Any device plugged from the external port can be accessed in Linux so far the file system is supported by Linux, but any file system residing on the SATA/PATA or SCSI device needs to be mounted before it can be accessed. For example, if I’m dual-booting Windows and Linux, for it to be possible to access my Windows drive from my Linux, you must mount the device on the system. You should also know that in most Linux systems, the NTFS-3g package is not installed by default, so in a situation when you have to access a Windows drive from your Linux machine, you have to install the NTFS-3G package to be able to have access to the files after mounting the drive.

It is pretty easy to mount your file system in Linux, a simple command with a source and destination path we do just that for you. To mount your file system, you need the mount command. The first argument after the mount command specifies the file system to mount, and the second argument specifies the target directory where the file system is to be mounted known as the mount point. You can as well choose to unmount a mounted file system.

In this article, we will be looking at so much more on the mount command. We will be looking at how to mount and unmount file systems manually and as well as how to mount file systems persistently in the Linux system.

HOW TO MANUALLY MOUNT FILE SYSTEMS IN LINUX

Like said earlier, before any file system that resides in the PATA/SATA or SCSI can be used on the Linux system, you have to be able to mount the file system. One of this method of mounting is to mount the file system manually, but this method of mounting is not persistent across boot.

To be able to mount a file system manually, two arguments are specified alongside with the mount command. The first argument is the source of the file system and the second is the mount point which is the destination path of the drive to mount

The command below is a general procedure on how to mount your filesystem. Though I don’t have a drive that resides in my PATA/SATA, I will be making use of
the DVD ROM

Now let's give a try in mounting our DVD drive but first let's view the correct block device by running the blkid command on the terminal

We will be mounting the ISO file with LABEL= “DYNASTY_SEASON_2” using the Block ID

Note that it is necessary to mount your file system using the UUID of the device rather than the name. The name of a device can change, but the UUID of the device will remain the same, even after removing the device.

So for knowledge sake, I will be demonstrating how to mount using the device name and the UUID. Also, note that you must specify the mount point which could be an existing directory or you can create a new directory to mount the device.

We have mounted the DVD drive using the device name. Let's try using the UUID of the device. Again, display the block ID of the device using the blkid command then copy the UUID and paste on your command as seen below.

That’s an example of mounting a drive using UUID of the device. At the same time, you can see that I specified the file type using the –t option as UDF, which is the new file system equivalent to the ISO9660 file system type

HOW TO MOUNT FILE SYSTEM PERSISTENTLY

What we discussed above is how to mount manually, mounting a file system manually is not persistent, which means when the system reboots, you will have to remount the file system. Now we will have to mount our drive which resides in SATA/PATA persistently.

To achieve this, we have to make entry into the /etc/fstab file and add some necessary parameters in the file.

I have discovered that most new users who try to mount a file system persistently in /etc/fstab file tend to make a mistake on which parameter comes first, either the device file of the partition that holds the drive or the mount point. I believe all confusion will be cleared after reading this article.

Please also remember to run the mount –a command on the terminal to check if there is an error in the /etc/fstab file. If everything goes well in the /etc/fstab file, the command will return no result, but if there is an error, the command will return an error message.

Remember i said you could choose to use the UUID or the name of the drive to mount the file system but it is best you use the UUID

Let’s see a practical example of how to mount persistently using the UUID

This is how it looks like mounting persistently, and also this is how the pattern should follow. If you are using the UUID to mount your file system, the UUID should come first followed by the mount point and the file system. If you are using the device name, then the device name should come first.

HOW TO UNMOUNT A FILE SYSTEM

The command umount is used to unmount a file system. The mount point follows as an argument

You should also know that an issue may arise when you try unmounting a file system. For example, if you change directory to the current directory of the mounted device and try to unmount the device right in its directory, the command will fail that’s because a process is accessing the mount point and for the umount command to be successful, the process needs to stop accessing the mount point.

To go about this, you need the lsof command. The lsof command will list all the processes accessing a file in the specified directory.

Let's give this a practical try for better understanding

So now lets run the lsof command to view all processes accessing the files in the provided directory

You can see the feedback from the terminal. To be able to unmount this device, we will have to kill the process by sending the SIGKILL or SIGTERM command. You can also change to another directory outside the mount point directory before unmounting the file system

Try to switch to a new directory and see the result

The unmounting is successful because the process accessing the mount point is the bash. So switching to another directory was able to unmount the file successfully.

CONCLUSION

I decided to write on file systems today because it got me confused when I newly started working on a Linux machine. I believe all doubt will be cleared on how file systems are mounted and unmounted after reading this article

Anyway, there are things you still need to know about file systems and mount point. If the directory of the mount point is not empty, the files that reside in that directory are not accessible. Therefore, it is essential to mount your file system on an empty directory or subdirectory.

Also, note that all removable devices such as flash drives and external devices are mounted automatically by the system when plugged into the machine. They resides in the /run/media/<user>/<name>. In this path, the user is the currently logged in user, and the name is the name given to the device when plugged into the machine.

Author

Comments