Master the Linux ‘umount’ Command: A Comprehensive Guide

Peter Hou
2 min readJun 8, 2023

--

This article provides an in-depth guide to the Linux ‘umount’ command, explaining its history, usage, parameters, and common use cases. It also highlights the nuances and precautions that users need to be aware of. After reading this, beginners should be able to effectively use the ‘umount’ command.

Instructions

This guide aims to provide a thorough understanding of the Linux ‘umount’ command. It covers the history, usage, parameters, and common use cases of the command. The guide also includes nuanced details and precautions to be taken while using the ‘umount’ command.

History

The ‘umount’ command has been a part of UNIX and UNIX-like operating systems since their inception. Its purpose is to unmount file systems that have previously been mounted using the ‘mount’ command.

When and why to use it

The ‘umount’ command is used when a file system that was previously mounted to a specific point in the directory structure needs to be disconnected. This could be because the device (like an external hard drive or CD-ROM) is to be removed, or the network location is no longer in use.

How to use it

Using ‘umount’ is quite straightforward. You only need to specify the directory path of the mounted file system. For instance, to unmount a file system mounted at ‘/mnt/mydisk’, use the following command:

$ umount /mnt/mydisk

The commonly used parameters

  • -f This forces the unmount in cases where the 'umount' operation is not responding.
$ umount -f /mnt/mydisk
  • -l This performs a lazy unmount, where the unmount operation is performed as soon as it is possible to do so.
$ umount -l /mnt/mydisk

Other supported parameters

  • -a Unmount all file systems in /etc/mtab.
  • -r Remounts read-only if unmounting fails.
  • -d Free the loop device if it has been used.

Most common use cases

The most common use case for the ‘umount’ command is when an external device, like a USB or an external hard drive, needs to be safely removed from the system.

$ umount /mnt/usb

The tricky skills

There may be instances where the ‘umount’ command fails because the target is busy. In such cases, the fuser command can be used to identify the processes using the mounted file system. Here's an example of how you can use it:

$ fuser -muv /mnt/mydisk

What needs to be noted

  1. Always make sure that no processes are using the file system before attempting to unmount it.
  2. Do not force unmount (-f) unless absolutely necessary as it can lead to data loss.

Conclusion

Understanding the ‘umount’ command is crucial in managing the file systems and devices in a Linux system. This guide should provide a beginner with enough knowledge to handle the most common use cases and troubleshoot potential issues.

--

--

Peter Hou
Peter Hou

Written by Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.

No responses yet