Quick Learning — Explained Linux mount Command
As a DevOps Engineer, you need to manage disk devices and filesystem mounts quite a few times. Whenever you add a disk volume to your server, you need to create a partition table, format it with a file system and mount it.
Here is the man page snippet for mount command.
The Mount command helps you with simple mounting a device on to a Linux filesystem directory. You can also mount a filesystem with Read Only / Read Write permission, and many more, lets get started.
mount
When you just execute mount command, it displays all the existing mounts. The following list shows all the mount points including system mounts like /proc, /sys, /run etc., and each one with different filesystem types like proc, sysfs, tmpfs etc., respectively.
Get Sampath Inturi’s stories in your inbox
Join Medium for free to get updates from this writer.
I will explain more on filesystems in my future blog.
List Only Specific Type Of Mounts
If you need to list only a specific type of mounts, you use option -t type
Mount a device
Whenever you need to a mount a device, you should run the mount command with the device, mount point and optionally its filesystem type. Most of the cases, the mount command can auto-detect the mounted device filesystem type, but in some cases if it’s failed to detect, you should provide its type using `-t type` option.
You need superuser permissions to run the mount command. And, if you try to mount the same device and mount point, you get a message like this.
You can verify all the mount partitions using mount or df -h commands.
If you see the mount command here, I tried to mount it without its filesystem type, which is worked. Most of the time
Unmount a device
In some cases, you need to unmount the already mounted partitions, to achieve that you need to use the command umount. Please remember, the command is u mount not un mount
Remount a device
Occasionally, you have to remount the existing mount with a different set of options without un mounting it. Cases likes, there is a device already mounted as ReadOnly, but now you have to mount the same as ReadWrite, or vice versa.
Mount with bind option
What if you have to mount the same partition to two mount points, like one with Read Write and another with Read Only. To accomplish that, we can use mount command with --bind option. When you use the bind option, you need to provide the source mount point and target mount point as command line options, instead of device partition.
With this, both the mount points contain the same contents, like when you write a file to the Read Write mount point, and that can be accessible from the Read-Only mount point.
If you see the above screenshot, the file file2.txt I created in /opt/data automatically available inside directory /opt/data-ro/
Bonus Tip — Fake Mount
What if you would rather not mount a device, but just want to verify if the mount or remount works without errors? To achieve that, use option -f along with the mount command. Furthermore, use -v to see the output in verbose mode.
Here if you see the above screenshot, even though the command worked, the mount point still in Read Write mode only.
Here I have covered a few day-to-day use options, but still, there are two more options that needs your attention are, mount -a and fstab. These are useful when you want to mount the partitions across system reboots.
I will cover those in my upcoming blog, stay tuned…









