umount
Unmount a mounted filesystem
TLDR
Unmount a filesystem, by passing the path to the source it is mounted from
Unmount a filesystem, by passing the path to the target where it is mounted
Unmount all mounted filesystems (except the proc filesystem)
SYNOPSIS
umount [OPTIONS] <DEVICE|DIRECTORY>
PARAMETERS
-a, --all
Unmounts all filesystems listed in /etc/mtab (or /proc/mounts) except the root, proc, sysfs, devfs, devpts, and tmpfs types. Typically used with -t to specify types.
-f, --force
Forces the unmount. Use with extreme caution, especially on local filesystems, as it can lead to data loss or corruption if data is still buffered. Primarily for unreachable NFS mounts.
-l, --lazy
Performs a 'lazy' unmount. The filesystem is detached from the file hierarchy immediately, and all references to it are cleaned up later when it is no longer busy.
-R, --recursive
Recursively unmounts submounts. If the target directory has other filesystems mounted beneath it, they will also be unmounted.
-t, --types <TYPE>
Specifies a comma-separated list of filesystem types to be unmounted. This option is often used with -a to unmount all filesystems of a certain type.
-v, --verbose
Enables verbose output, showing more details about what umount is doing.
-h, --help
Displays a help message and exits.
-V, --version
Displays version information and exits.
DESCRIPTION
The umount command is used to detach a mounted filesystem from the current directory hierarchy. When a filesystem is mounted, its contents become accessible through a specific mount point directory on the system. umount reverses this process, making the device or partition available for other operations or removal.
Before a filesystem can be successfully unmounted, it must not be in use. This means no files should be open on that filesystem, and no processes should have their current working directory within it. If the filesystem is busy, umount will typically fail with an error message. The command ensures that all pending data writes to the device are completed before detachment, preventing data corruption and maintaining filesystem integrity.
While umount is generally used with a device name (e.g., /dev/sdb1) or a mount point (e.g., /mnt/mydrive), it's more robust to specify the mount point as it avoids issues if the device name changes. By default, umount requires superuser privileges (root or via sudo) to execute, as it modifies the system's filesystem hierarchy.
CAVEATS
Filesystem Busy: The most common reason for umount failure is that the filesystem is currently in use. This means a process has an open file, or its current working directory, on the filesystem. Use commands like fuser or lsof to identify and terminate such processes before attempting to unmount.
Root Filesystem: The root filesystem (/) cannot be directly unmounted while the system is running, as it is essential for the operating system's operation.
Data Integrity: Using the --force option on a local filesystem is highly discouraged, as it bypasses checks and can lead to data corruption or loss if there are pending writes. It's primarily intended for network filesystems (like NFS) that are unreachable.
FINDING BUSY PROCESSES
If umount reports 'device is busy,' you need to identify which processes are using the filesystem. Common tools for this include:
fuser <mount_point>: Shows PIDs of processes accessing the specified mount point. You can then use kill to terminate them (e.g., kill -9 $(fuser -m <mount_point>), use with caution).
lsof <mount_point>: Lists all open files associated with the mount point, along with the processes that opened them. This provides more detailed information, including specific file paths.
Alternatively, navigating out of the mount point and closing any applications using files on it can often resolve the 'busy' issue.
LAZY UNMOUNT (<I>--LAZY</I>)
The --lazy (or -l) option is particularly useful when you cannot immediately unmount a filesystem because it's busy, but you need to detach it from the directory hierarchy. When used, the filesystem is immediately 'unlinked' from the mount tree, so it becomes inaccessible to new operations. However, actual cleanup (flushing data, releasing resources) happens in the background only when the filesystem is no longer busy. This can be helpful for situations like unmounting network shares that are temporarily unresponsive or for preparing a device for removal even if a process still has an open handle that will eventually close.
HISTORY
The umount command has been a fundamental part of Unix-like operating systems since their early days. It's a core utility within the util-linux package on Linux systems, essential for managing storage devices and ensuring data integrity when detaching them from the system hierarchy. Its functionality has remained largely consistent over decades, reflecting its crucial and unchanging role in system administration.