| by Arround The Web | No comments

Linux Umount Command

All files available in Unix or a Unix-like system like Linux are organized in a single large tree termed the file hierarchy which is rooted at “/”. These files could be distributed across multiple devices. It is necessary to unmount a device or filesystem when it is not in use anymore.

A file system can be identified by mentioning the directory in which it is mounted. Providing the specific device where the file system resides can also be possible, but it is no longer a viable option as it fails if the device is mounted on multiple directories. Keep in mind that a filesystem could be unmounted if it is “busy”. This could be because there are files that are open on that particular file system or some other reasons might affect the process. Despite this, the lazy umount can help to detach such filesystems.

In this article, we will discuss the various usages of the Linux umount command to unmount the mounted filesystems.

Syntax to Use the Umount Command

The syntax to use the mount command is as follows:

umount [option] path_to_mount_point

In this syntax, umount is the keyword to detach a filesystem or device. The option refers to a list of options that can be used with the umount command. It is not a mandatory field. The path_to_mount_point refers to the full path of the directory in which the specified filesystem is mounted.

When unmounting a file system, various options can be supplied. Some of these choices can be found in the following list:

  • -V
    Executing this with umount command displays the version information of umount.
  • -a
    All the file systems that are listed in the /etc/mtab are unmounted when this flag is used with the umount command.
  • -t
    It specifies that the action should be taken to the specified filesystem type.
  • -h
    All the options for the umount commands could be printed using this flag.
  • -n
    This flag is used to unmount without writing in the /etc/mtab.
  • -v
    It specifies the verbose mode.
  • -r
    It tries to remount the filesystem, when umount fails, in the read-only mode.
  • -l
    This flag refers to the lazy umount. When the filesystem is no longer in use, it instantly detaches and cleans away the references.

Though the list of choices is long, we will practice the umount command with some of these options in this tutorial.

Checking the Umount Version

The first illustration that we will look into is checking the version of the Linux umount command. From the options, umount operates. Use the -V parameter to determine the version of the umount command. The following command is executed to print the umount version:

omar@omar-VirtualBox:~$ umount -V
umount from util-linux 2.37.2 (libmount 2.37.2: selinux, smack, btrfs, verity, namespaces, assert, debug)

As you can see from the previous output, the currently running umount version is 2.37.2.

Utilizing the Linux Umount Command to Unmount a Filesystem

A filesystem or partition can be detached using the umount command in Linux. We need to provide the path of the directory in which the particular filesystem is mounted, so we can unmount it with the umount command. Here, we unmount the /dev/sda3 partition. We run the umount command with the sudo privileges. Then, we mention the path of the directory as /dev/sda3. The command that we execute is as follows:

 omar@omar-VirtualBox:~$ sudo umount /dev/sda2

Since the unmounting is successful, we didn’t meet any warning. You can also check it by simply running the mount command:

omar@omar-VirtualBox:~$ mount

If you don’t find the partition in the output, this means that the unmount is successful.

Using the Linux Umount Command to Unmount All the Files

We can detach all the mounted filesystems from the /etc/mtab with the umount command. Use this command with care because it eventually detaches all the filesystems from your system. The umount command is used with the –a flag which unmounts all the mounted filesystems. Write the following command to unmount all the filesystems in the /etc/mtab directory:

omar@omar-VirtualBox:~$ sudo umount -a

All the file systems shoould be unmounted if they aren’t currently used.

Executing the Linux Umount Command to Forcefully Unmount a Partition

You might try to unmount a filesystem or a partition but then you find out that the device is busy or there can be other reasons for not being able to unmount the partition or filesystem. The specified file might not be accessible at that moment. For that, you can try to unmount it forcefully using the umount command with the –f flag. This forces the unmount and removes the references of the unmounted partition from the system. The command that we execute is given in the following:

omar@omar-VirtualBox:~$sudo umount -f /dev/sda3
umount: /: target is busy

If you still couldn’t unmount the desired partition, use the lazy umount method.

Lazy Unmount Using the Umount Command

If the partition or filesystem that you are attempting to unmount is currently busy, you can employ the lazy unmount command which unmounts the partition when the system has finished the operations on that particular filesystem. To execute the lazy mount, the flag –l is used with the umount command. This command waits for the system to complete the operation on the particular partition and clears the references of the partition when it is free. The command is given in the following:

omar@omar-VirtualBox:~$sudo umount -l /dev/sda3

A lazy unmount is carried out on the particular /dev/sda3 partition. The specified partition disappears once the filesystem is free of activity.

Remounting a Filesystem or Partition

Write the umount command with the –r flag. Then, specify the mounting point. The command is as follows:

omar@omar-VirtualBox:~$sudo umount -r /dev/sda3

Conclusion

The umount command is utilized when unmounting a mounting filesystem. In this article, we discussed the different aspects of exercising the umount command in Linux. The article started with a brief introduction to the Linux mount command. Then, we defined the options that can be used with the umount command. Lastly, we demonstrated the various uses of the umount command to detach a partition or a filesystem with a respective command line implementation.

Share Button

Source: linuxhint.com

Leave a Reply