8

In Eric Hammond's article Running MySQL on Amazon EC2 with EBS he shows how to add a second drive (/vol/) and then progresses to move mysql's config and data there.

/sdh gets mounted as /vol by editing fstab and adding:

/dev/sdh /vol xfs noatime 0 0

And next some paths are added like this:

/vol/etc/mysql /etc/mysql     none bind

I don't have a problem with doing this way but I don't quite understand what is going on.

I can most closely compare this to using a symlink, something like:

ln -s /etc/mysql /vol/etc/mysql

I've taken a look at man fstab without seeing much information about the bind syntax and can't find it in the fstab section in the Linux Administrator's Handbook either. Can someone shed some light on fstab's bind syntax, how it works, what it does, and where I should be able to find more information on it?

1 Answer 1

8

bind mirrors a filesystem (among other situatons, it's useful when setting a chroot inside which you need to have a "complete" system (like when unpacking/installing Gentoo).

Just simply like that, it mirrors a tree from A into B. I don't know for sure if it has any option, but I doubt it, it does not do more than, well, mirroring.

Unlike a symlink, which is a file in a filesystem pointing to another filesystem, requiring you to set it up, and is still a "special file", bind really mirrors the whole subtree. Depending on the tool, both strategies may work, but it is possible to detect the symlink and some tools may resolve it to the original path. The bind approach is more transparent, acting like two different filesystems.

4
  • 1
    Just had to do this last night, excellent answer. this is the description from LFS build docs: ....since this is a new system and does not have Udev and has not yet been booted, it is necessary to mount and populate /dev manually. This is accomplished by bindmounting the host system's /dev directory. A bind mount is a special type of mount that allows you to create a mirror of a directory or mount point to some other location..
    – 2bc
    Mar 26, 2012 at 21:04
  • 2
    Exactly. Symlinks that reference inodes outside of a chroot environment won't work. You can link /mychroot/home to /home before you chroot(2), but after you chroot, the symlink is broken (/mychroot no longer exists from the point of view of the chrooted environment). Binding to the rescue.
    – Alexios
    Mar 26, 2012 at 22:03
  • 1
    You can have a read only bind mount, but symlinks can't change the permissions of the target.
    – psusi
    Mar 26, 2012 at 22:50
  • 1
    When you say "mirror" I panicked thinking it was going to copy all the files, it acts more like a directory hard-link, the two directories are simply the same directory, something that happens in one happens in the other, because they are the same event. Apr 20, 2017 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .