Create ln symbolink or hard links with mount –bind for better filesystem read/write performance / Adding mount –bind to /etc/fstab

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 mountmount –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

Share this on

Download PDFDownload PDF

Tags:

One Response to “Create ln symbolink or hard links with mount –bind for better filesystem read/write performance / Adding mount –bind to /etc/fstab”

  1. Steve Zekria says:
    Internet Explorer 7.0 Internet Explorer 7.0 Windows XP Windows XP
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

    whoa!, this is a pretty good post. I remember about reading something similar to this once, this is pretty great material.

    View CommentView Comment

Leave a Reply

CommentLuv badge