What is the difference between a symlink and binding with fstab?
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.
Related videos on Youtube
cwd
Updated on September 18, 2022Comments
-
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 movemysql
's config and data there./sdh
gets mounted as/vol
by editingfstab
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 thebind
syntax and can't find it in thefstab
section in the Linux Administrator's Handbook either. Can someone shed some light onfstab
'sbind
syntax, how it works, what it does, and where I should be able to find more information on it? -
2bc about 12 yearsJust 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 bybind
mounting 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 about 12 yearsExactly. Symlinks that reference inodes outside of a chroot environment won't work. You can link
/mychroot/home
to/home
before youchroot(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 about 12 yearsYou can have a read only bind mount, but symlinks can't change the permissions of the target.
-
ThorSummoner about 7 yearsWhen 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.