unmount
Detach a mounted filesystem
TLDR
View documentation for the correct command
SYNOPSIS
umount [options] directory|device
umount -a [options]
PARAMETERS
-a, --all
Unmounts all file systems listed in /etc/mtab, except for the root file system.
-f, --force
Forces the unmount. This is a dangerous option and should only be used as a last resort, for example, on unreachable NFS systems, as it can lead to data corruption.
-l, --lazy
Performs a 'lazy' unmount. The file system is detached from the file hierarchy immediately, and all references to the file system are cleaned up when it is no longer busy.
-n, --no-mtab
Prevents writing to the /etc/mtab file (which tracks currently mounted file systems).
-O, --options
Used with -a, unmounts only file systems that have the specified mount options in /etc/fstab.
-t, --types
Used with -a, restricts the unmount operation to file systems of the specified types (e.g., ext4, nfs).
-v, --verbose
Provides more detailed output about the unmount operation.
DESCRIPTION
The umount command is used to detach a mounted file system from the directory tree. This is a critical operation that ensures data integrity by flushing any pending data writes from memory to the disk and releasing the file system resources. Failing to unmount a file system, especially for removable media like USB drives, before physical removal can lead to data corruption or loss. The command can operate on a specified mount point (e.g., a directory where the file system is mounted) or by the device name (e.g., /dev/sdb1). It is essential to ensure no processes are actively using the file system before unmounting; otherwise, the operation will fail with a "device is busy" error. umount plays a vital role in system maintenance, allowing administrators to manage storage devices safely.
CAVEATS
Device is busy: The most common issue is attempting to unmount a file system that is currently in use. This could be due to open files, active processes, or a user's current working directory being within the mounted file system. The umount command will typically fail with an error like "target is busy" or "device is busy".
Data Loss with --force: Using the -f (force) option can lead to data corruption or loss if the file system is still being actively used. It should only be employed when absolutely necessary and when data integrity is not a primary concern (e.g., unmounting an unresponsive NFS share).
Root Filesystem: The root file system (/) cannot be unmounted while the system is running, as it is essential for the operating system's core functions.
PERMISSIONS
Typically, only the root user or a user with sudo privileges can execute the umount command. However, on some systems, non-root users might be allowed to unmount devices they have mounted themselves (if the user or users option is set in /etc/fstab for that mount point), or removable media like USB drives through desktop environment tools which handle permissions implicitly.
TROUBLESHOOTING BUSY FILESYSTEMS
If umount reports 'target is busy', you can use commands like fuser mount_point or lsof mount_point to identify processes or users accessing the file system. You can then terminate these processes (e.g., using kill) or ask users to exit the directory before attempting to unmount again. The -l (lazy) option provides a graceful way to handle busy filesystems without immediate termination, as it detaches the filesystem and cleans up when no longer in use.
HISTORY
The umount command has been a fundamental part of Unix-like operating systems since their early development. It originated as a counterpart to the mount command, providing the necessary functionality to safely detach file systems. Its core purpose and syntax have remained largely consistent over decades, reflecting the enduring need for proper file system management. While the underlying file system types and options have evolved, umount's role in ensuring data integrity during storage device removal or system maintenance has been steadfast. The -l (lazy) option is a notable modern addition, providing a more robust way to handle stubbornly busy file systems.