[UFO Chicago] Multiple mounts of the same device.

Jesse Becker jesse_becker@yahoo.com
Thu, 12 Sep 2002 23:24:12 -0700 (PDT)


Following up on the converstation about mount points from
this evening (/dev/hda6 is a scratch partition, with a new
ext2 filesystem):

<-------------------snip------------------->

[root@deadlands]# uname -s -r -m; mount --version
Linux 2.4.18-8.1mdksecure i686
mount: mount-2.11t

[root@deadlands]# cd /mnt

[root@deadlands]# ls -l
total 12
drwxrwxr-x    2 root     root     4096 Oct  9  1998 cdrom/
drwxrwxr-x    2 root     root     4096 May 28 23:36 disk/
drwxrwxr-x    2 root     root     4096 Feb  6  1996 floppy/

[root@deadlands]# mount |grep /dev/hda6

[root@deadlands mnt]# mount /dev/hda6 /mnt/disk

[root@deadlands mnt]# mount |grep /dev/hda6
/dev/hda6 on /mnt/disk type ext2 (rw)

[root@deadlands mnt]# mount /dev/hda6 /mnt/floppy

[root@deadlands mnt]# mount |grep hda6
/dev/hda6 on /mnt/disk type ext2 (rw)
/dev/hda6 on /mnt/floppy type ext2 (rw)

[root@deadlands mnt]# ls -l floppy/ disk/
disk/:
total 12
drwx------    2 root  root   12288 Sep 13 00:34 lost+found/

floppy/:
total 12
drwx------    2 root  root   12288 Sep 13 00:34 lost+found/

[root@deadlands mnt]# touch disk/foo

[root@deadlands mnt]# ls -l */foo
-rw-r--r--    1 root     root    0 Sep 13 00:57 disk/foo
-rw-r--r--    1 root     root    0 Sep 13 00:57 floppy/foo

[root@deadlands mnt]# touch floppy/bar

[root@deadlands mnt]# ls -l disk/ floppy/
disk/:
total 12
-rw-r--r--    1 root   root     0 Sep 13 00:59 bar
-rw-r--r--    1 root   root     0 Sep 13 00:57 foo
drwx------    2 root   root 12288 Sep 13 00:34 lost+found/

floppy/:
total 12
-rw-r--r--    1 root   root     0 Sep 13 00:59 bar
-rw-r--r--    1 root   root     0 Sep 13 00:57 foo
drwx------    2 root   root 12288 Sep 13 00:34 lost+found/

[root@deadlands mnt]# rm disk/bar
rm: remove `disk/bar'? y

[root@deadlands mnt]# ls -l disk/ floppy/
disk/:
total 12
-rw-r--r--    1 root   root      0 Sep 13 00:57 foo
drwx------    2 root   root  12288 Sep 13 00:34 lost+found/

floppy/:
total 12
-rw-r--r--    1 root   root      0 Sep 13 00:57 foo
drwx------    2 root   root  12288 Sep 13 00:34 lost+found/

<------------------------snip---------------->

So, under this version of the Linux Kernel, using this
version of mount(1), you can mount the same device multiple
times in different locations.

You should also read the man page for mount as it refers to
"binding" mount points, which appear to be the same thing. 
Since this 'feature' is in the stable kernel, I assume that
it's safe for general use.

However, I do NOT suggest that you do this.  At the moment,
I cannot prove that your data will be horribly corrupted if
you do this, but I would by no means consider it "safe". 
There is also a very real danger of conflicts in the
filesystem namespace as well.  If program A writes to
/usr/lib/foo, and program B writes to /var/lib/foo, then
who gets to write?  Furthermore, if you read data, it may
be 'correct' for one process, but compeltely wrong for
another.  

One further problem with this configuration is that even if
there are no problems with nameing issues, you will have
combined /usr and /var in such a way that you will never be
able to seperate them (not easily at least).  So, when you
fill that combined partition, you're stuck.

There are situations where I can see multiple mountings
being useful, mostly in the context of chroot'ed servers,
but not on a workstation machine.

Instead, use symlinks.  It takes five commands which are
not complicated, and give what is tryign to be done here,
if you don't want to run these, you shouldn't be trying
something like this in the first place:

(All as root, and in single user mode, which as few
processes running as possible.  The last three commands
should be run as close together as possible).

# cd /
# mkdir -p /usr/slash/var
# tar cpf - var | (cd /usr/slash; tar xpvf -)
# mv /var /var.old
# ln -s /usr/slash/var /var

Once you are certain that everything works (I'd suggest
returning to runlevel 5, or rebooting), you can delete
/var.old and reclaim the space.

If either of these processes break you computer, you get to
keep the pieces.  It's also late and I'm tired, so don't
blindly follow any of this unless you're looking for an
adventure.

--Jesse

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com