What is the difference between a symlink and binding with fstab?

6,819

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.

Share:
6,819

Related videos on Youtube

cwd
Author by

cwd

Updated on September 18, 2022

Comments

  • cwd
    cwd over 1 year

    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?

  • 2bc
    2bc about 12 years
    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..
  • Simon Gates
    Simon Gates about 12 years
    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.
  • psusi
    psusi about 12 years
    You can have a read only bind mount, but symlinks can't change the permissions of the target.
  • ThorSummoner
    ThorSummoner about 7 years
    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.