[Linux] Filesystem mounts
Robert Citek
linux@flux.org
Mon, 25 Feb 2008 13:10:32 -0600
On Mon, Feb 25, 2008 at 12:17 PM, Robert Citek <robert.citek@gmail.com> wrote:
> On Mon, Feb 25, 2008 at 12:00 PM, Danny Rathjens <dannyr@wirespring.com> wrote:
> > Robert Citek wrote:
> > > On Mon, Feb 25, 2008 at 9:47 AM, <kwan@digitalhermit.com> wrote:
> > >> Question is, without unmount /foo/bar, how can I view the directory
> > >> contents of the mount point /foo/bar.
> > >
> > > This might help. man mount:
> > >
> > > Since Linux 2.5.1 it is possible to atomically move a mounted
> > > tree to another place. The call is
> > > mount --move olddir newdir
> > >
> > I'm confused as to why you can't just unmount and recover any data coincidentally
> > not overwritten and mount it again.
>
> You can't unmount a filesystem if a processes is using it, but you can move it.
This script demonstrates moving a filesystem under Ubuntu using a
loopback device:
#!/bin/bash
sudo true && (
set -x
#### setup
tmp=$(mktemp -d tmp.XXXXXX) || exit
cd $tmp
mkdir ext3-{A,B}
touch ext3-A/file-A
touch ext3-B/file-B
ls -l ext3-{A,B}
# create loopback filesystem
dd if=/dev/zero bs=1M count=100 of=ext3.img >& /dev/null
mkfs.ext3 -F ext3.img >& /dev/null
# show the files when mounted
sudo mount -o loop ext3.img ext3-A
# notice file-A is no longer seen
ls -l ext3-{A,B}
# by unmounting, file-A is viewable again
sudo umount ext3-A
ls -l ext3-{A,B}
# however, if ext3-A is busy, it cannot be unmounted
sudo mount -o loop ext3.img ext3-A
( cd ext3-A ; sleep 3 ) &
sudo umount ext3-A
# if instead, ext3-A is moved to ext3-B, then file-A is visible but
file-B become invisible, even though ext3-A is busy
sudo mount --move ext3-A ext3-B
ls -l ext3-{A,B}
# and if ext3-B is moved to ext3-A, then file-B is visible again and
file-A is once again invisible, even though ext3-A is busy
sudo umount ext3-B
sudo mount --move ext3-B ext3-A
ls -l ext3-{A,B}
# unmount and clean up
sleep 3
sudo umount ext3-A &&
rm -rf ../$tmp
) 2>&1 | tee output.txt
Browse through output.txt to view the results.
Regards,
- Robert