10

I have a home partition which is shared by mulitple distros on the same box. I'm using bind mounts from fstab. Each Linux install has something like this:

UUID=[...]       /mnt/data  ext4  nodev,nosuid   0 2
/mnt/data/arch   /home      none  defaults,bind  0 0
/mnt/data/files  /files     none  defaults,bind  0 0

The disadvantage is, of course, that /mnt/data/arch and /mnt/data/files are now mounted twice. On a hunch, I tried umount /mnt/data, which seems to work as I had hoped: according to mount, the device is now only mounted to /home and /files.

My questions are:

  1. Is this safe, or am I overlooking something?
  2. Is it possible to get the same effect as umount /mnt/data using only fstab? Or could I do it in rc.local?
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175

1 Answers1

9

It's safe to unmount one of the bind-mounted copies. After you run mount --bind /foo /bar, the kernel doesn't keep track of which of /foo or /bar came first, they're two mount points for the same filesystem (or part of a filesystem).

Note that if /foo is a mount point but /foo/wibble isn't, mount --bind /foo/wibble /bar makes /bar point to a part of the filesystem that's mounted on /foo. It's still ok to unmount /foo.

So if you mount /mnt/data, then bind parts of it to /home and /files, and unmount /mnt/data, you end up with no access to the parts of /mnt/data outside arch and files. If that doesn't bother you, go for it.

You can't achieve that through fstab: it only supports mounting filesystems. Bind mounts get in through a hack (the bind mount option is turned into a --bind option to the mount command internally). mount --move and unmounting can't be specified in fstab. You can use /etc/rc.local to call umount.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175