Reading Time: 2minutes
If you’re building a website and you need to create a link from a certain destination to another place.
You’ve probably already thought about using the ln command to create a symbolic link to the questionable directory (folder).
Though this is one of the possible approaches to solve the task, it’s far not the best one.
A possible alternative to the good old fashioned ln -s way would be through a bind mount – mount –bind
The mount –bind is well documented in mount’s manual so it’s best if you take a look at it.
You might want to check the following ln vs mount bind discussion to know more about why mount –bind is probably a better more efficient solution to link a location to another one in terms of efficiency.
fstab proper record for linking directory to another one using the –bind mount feature :
Bind mount is used to export a certain mounted directory to another one. The end result when using bind –mount it is absolutely.identical to a normal link created with ln .
However using a normal symlink is also less prone to a security leaks like filesystem directory traversal attacks etc.
Wherein ln -s command is used actually a new inode is created pointing to a certain filesystem object (let’s say directory),for comparison mounting it instead of linking the directory won’t have it’s own inode on the filesystem created.
The above inode explanation directly means that in hard links and mount binds creation no special inode is reseverved for either thehard link or the mount –bind thus working with directories created with mount –bind is a bit faster and on a heavy loadedfilesystems will have a positive decrease if used.
To permanently create a mount –bind from the /etc/fstab file in Linux, it would be necessary to place an fstab record like the one shown below:
/home/username/www/random/images /home/username/www/unknown/images/ bind defaults,bind 0 0
To add the mount bind to fstab directly from terminal/console you can use a command like:
debian:~# echo "/home/username/www/random/images /home/username/www/unknown/images/ bind defaults,bind 0 0" >> /etc/fstab