[UFO Chicago] Multiple mounts of the same device.

Sean Neakums sneakums@ufo.chicago.il.us
Fri, 13 Sep 2002 08:41:57 +0100


commence  Jesse Becker quotation:

> 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".

It's perfectly safe.  It's the same FS instance, appearing at two
different locations (the bind happens inside the VFS, at the dentry
level).  What you will *not* end up with two instances of the same FS
trying to write to the same device and making a mess.

> 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?

It's the same file, so both of them "get to write".  It'll be exactly
as if both programs wrote to /usr/lib/foo or /var/lib/foo.  I assume
for this example that you have the same FS mounted at both /usr and
/var.

> Furthermore, if you read data, it may be 'correct' for one process,
> but compeltely wrong for another.

It's the same file.  So if the programs in question were not designed
to be able to write to the same file then yes, you will have a mess.

> 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,

Unless you want getcwd(2) to return correct results, which will not
happen for all cases when symlinks enter the picture.

> 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

Or instead of this last step you could just do

# mkdir /var
# mount -o bind /usr/slash/var /var

(You will of course want to add an fstab entry for this.)

> 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.

-- 
Sean Neakums - <sneakums@ufo.chicago.il.us> --- --- -- -
Director of International Operations, UFO Chicago - -- -
http://ufo.chicago.il.us/ --- ------ ----- ---- --- -- -