UNIX / Linux umount Command Examples

by SathiyaMoorthy

What is umount?
3 umount examples
Syntax and Options
Related Commands

What is umount?

umount stands for unmount, which unmounts the file system. Use umount to unmount a device / partition by specifying the directory where it has been mounted.

Following is the partial output of the mount command.

# mount
/dev/sdb1 on /mnt type vfat (rw)

Device /dev/sdb1 is mounted on /mnt, from where all your process will be accessing the data available on that device.

For some reason, if you like to physically detach the /dev/sdb1 device, you should first unmount it (to logically detach the device).

3 umount Examples

Unmount a file system

umount the file system by specifying the directory path where it has been mounted. For example, /mnt.

# umount /mnt

When the device is not used anywhere else, then the above umount will unmount the device without any issue.

Note: When umount command completes successfully, it will not display any message indicating that it is successfully unmounted the device.

Proper Umount of a busy device

If the file located on that device is accessed by some other program, the device will be busy and you cannot umount it. If you do so, you will get the “umount: /mnt: device is busy.” error as shown below.

# umount /mnt
umount: /mnt: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

Use fuser command to find out which process is accessing the device along with the user name.

# fuser -mu /mnt/
/mnt/:                2677c(sathiya)
  • fuser – command used to identify processes using the files / directories
  • -m – specify the directory or block device along with this, which will list all the processes using it.
  • -u – shows the owner of the process

You got two choice here. 1) Ask the owner of the process to properly terminate it or 2) You can kill the process with super user privileges and unmount the device.

Forcefully umount a busy device

When you cannot wait to properly umount a busy device, use umount -f as shown below.

# umount -f /mnt

If it still doesn’t work, lazy unmount should do the trick. Use umount -l as shown below.

# umount -l /mnt

Syntax and Options

umount [-hV]

umount -a [-dflnrv] [-t vfstype] [-O options]
umount [-dflnrv] dir | device [...]

Short Option Option Description
-n Unmount without writing in /etc/mtab
-r In case unmounting fails, try to remount read-only
-d In case the unmounted device was a loop device, also free this loop device
-i Don’t call the /sbin/umount. helper even if it exists. By default /sbin/umount. helper is called if one exists.
-a All of the file systems described in /etc/mtab are unmounted. (With umount version
2.7 and later: the proc filesystem is not unmounted.)


Related Commands

mount
eject
fuser

1 kk October 22, 2013 at 3:56 am

it works……….

tx

2 peyman January 5, 2014 at 5:43 am

Hi…very good….thanks

Comments on this entry are closed.

{ 2 trackbacks }

Previous post:

Next post: