TrumanWong

umount

Used to unmount a mounted file system

Supplementary instructions

umount command is used to unmount a loaded file system. You can umount the file system using the device name or mount point, but it is best to unmount it through the mount point to avoid confusion when using bind mounts (one device, multiple mount points).

grammar

umount(option)(parameter)

Options

-a: Remove all file systems recorded in /etc/mtab;
-h: display help;
-n: Do not store information in the /etc/mtab file when uninstalling;
-r: If the removal cannot be successful, try to remount the file system in read-only mode;
-t<file system type>: Only dismount the file system specified in the option;
-v: Display detailed information during execution;
-V: Display version information.

Parameters

File system: Specify the file system to be uninstalled or its corresponding device file name.

Example

The following two commands unmount the file system by device name and mount point respectively, and output detailed information at the same time:

Uninstall by device name

umount -v /dev/sda1
/dev/sda1 umounted

Uninstall via mount point

umount -v /mnt/mymount/
/tmp/diskboot.img umounted

If the device is busy, the uninstallation will fail. A common reason for uninstallation failure is that the current directory of an open shell is a directory in the mount point:

umount -v /mnt/mymount/
umount: /mnt/mymount: device is busy
umount: /mnt/mymount: device is busy

Sometimes the reason why a device is busy is not easy to find. When encountering this situation, you can use lsof to list open files, and then search the list to find the mount point to be uninstalled:

lsof | grep mymount finds open files in the mymount partition
bash 9341 francois cwd DIR 8,1 1024 2 /mnt/mymount

From the above output, we can see that the reason why the mymount partition cannot be unmounted is that the bash process with PID 9341 is running by francois.

Another way to deal with busy system files is to perform a delayed uninstall:

umount -vl /mnt/mymount/ performs delayed unmounting

Lazy unmount will immediately unmount the file system in the directory tree and wait until the device is no longer busy to clean up all related resources. You can also use the eject command to uninstall removable storage media. The following command will unmount the CD and eject the CD:

eject /dev/cdrom Uninstall and eject the CD