Linux distributions like Ubuntu, Debian, CentOS, RHEL, and others use disks by mounting them to the file system. We have already examined
mount command in the following tutorial. In this tutorial we will learn how to umount the disk in a Linux system.
Before unmount we should be sure that all changes are written to the file system and disk. So we need to close open files that reside in the file system we want to unmount.
umount command help information can be listed with
--help like below. We can see some different help options in a brief way like unmount all filesystems, verbose etc.
List Mounted File Systems
Before unmounting filesystems and partitions we may need to list currently mounted filesystems and partitions.We can use the command mount in order to list currently mounted file systems and partitions with some information.
lsblk command can be used already mounted file systems which provides more hierarchical list and eliminate unnecassary information.
Umount Specified Partition
We will start by unmounting specified partition. We can unmount just providing the partition path. In this example, we will unmount
/dev/hda1. We need root privileges in order to complete this job which is gained with the
$ sudo umount /dev/hda1
When the unmount is completed succesfully there will be no message about the process which simply sign the succesfull unmount. If there are some messages which are generally related with the error this means some error which prevents the unmount operation.
Unmount All Partitions
If we need to unmount all partitions of file systems currently mounted to the Linux system. We will use
-a option which means all.
$ sudo umount -a
Force To Unmount
In some cases write operations can be resume for a long time and we need to unmount the file system. So we can force
umount command with
-f option like below. The following command will unmount the file system located in /dev/hda1 in a forceful way which may create some minor file system related errors in the next mount. Alternatively, the
--force option can be used to force unmount. We can see the error like ” umount:/mnt devices is busy” error like below.
$ sudo umount -f /dev/hda1
Alternatively we can list already opened file descriptor with the lsof command like below. We will just provide the mount path where the opened files will be list.
$ lsof /home/ismail
umount failed we can find detailed information about the reason. We can use
-v option which will list detailed information while trying to unmount.
$ sudo umount -v /dev/hda1