7

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

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.

  • Inaccessibility of anything other than arch and files was exactly what I was going for. Thanks for the confirmation. :-) – PPvG Aug 30 '12 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.