What is a Bind Mount in Linux?

In Linux, the mounting process of the filesystem is done by using the mount command that enables the user to access the device’s file system. The bind mount is a special type of mount that gives the feature to mount a device’s file system in more than one place simultaneously. The purpose of a bind mount is to provide an alternative view of the file system that can be accessed from multiple locations within the system.

This post will demonstrate the question “what is a bind mount?” in Linux.

  • What is Bind Mount in Linux?
  • How to Create the Bind Mount Directory?

What is Bind Mount in Linux?

The “bind” parameter is used to bind the mount; it works like an alias. For example, when the directory is mounted with “bind” on the target directory, both will refer to the same content. If the user wants to apply bind mount on directories and sub-directories, consider the “rbind.” Here r stands for recursive mode. Furthermore, applying the bind mount won’t allow the user to approach the original content in the target directory.

How to Create the Bind Mount Directory?

To create the bind mount directory in Linux, follow the basic syntax that is given below: 

Syntax:

$ sudo mount --bind [Target Directory] [Bind_Mount Directory]
  • The “sudo” for the root privileges.
  • The “mount” to mount the directory.
  • The “bind” to apply the bind mount.
  • Specify the “Target Directory” to whom the user wants to apply bind mounted.
  • Specify “Bind_Mount Directory” to create the bind mount view.

Follow the below-mentioned steps to apply bind mount:

Step 1: Create the Test Directory

Let’s create the test directory and add some file content to it as shown below:

$ mkdir /tmp/mount_dir
$ touch /tmp/mount_dir/File
$ touch /tmp/mount_dir/itslinuxfoss

The directory “/tmp/mount_dir” is created with file content named “File” and “itslinuxfoss”.

Step 2: Apply Bind Mount 

Create another directory (/tmp/bind_mount) for bind mount and apply it on the target directory “/tmp/mount_dir”:

$ mkdir /tmp/bind_mount
$ sudo mount --bind /tmp/mount_dir /tmp/bind_mount

The directory “/tmp/bind_mount” is created and bind mount is applied on the target directory “/tmp/mount_dir.” 

Step 3: Check the Content of Both Directories

Now, let’s compare the content of both directories to verify their content. To accomplish this, run the below-given command in the terminal:

$ ls -l /tmp/mount_dir
$ ls -l /tmp/bind_mount

Both directories “/tmp/mount_dir” and “/tmp/bind_mount” has the same content “File” and “itslinuxfoss”.

Conclusion

The bind mount is a special type utilized for simultaneously mounting the device’s file system in two places. To create the bind mount directory, create the test directory and put some file content. Then create another directory and apply bind mount on the target directory. The user can access both mounting points with the same content.

This write-up has answered the question, “what is a bind mount?”.