Linux Command Reference ยท Disks and Filesystems
Linux umount command
Reference for the Linux umount command: detach filesystems safely, fix 'target is busy' errors with lsof and lazy unmount, and unmount whole trees recursively.
umount detaches a filesystem from the directory tree. Note the spelling: there is no "n" after the "u". Before the kernel lets go of a filesystem, it must write out all cached data and make sure nothing is using it; that is why you unmount a USB stick before pulling it out, and why umount sometimes refuses with "target is busy".
You can name either the mount point (umount /mnt/usb) or the device (umount /dev/sdb1). Using the mount point is clearer, and it is the only choice for filesystems that have no device, such as tmpfs.
umount [-lfR] DIRECTORY|DEVICE...
Try it
Unmounting needs root, so the commands below that really detach something are read-only comments. The live parts show what a normal user sees and how to check state beforehand.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
umount [options] DIRECTORY|DEVICE... umount -a [-t TYPE]
| Option | Description |
|---|---|
-l, --lazy |
Detach the mount point from the tree now and clean up when it stops being busy. |
-f, --force |
Force unmounting an unreachable network filesystem (NFS). |
-R, --recursive |
Unmount the directory and everything mounted below it, deepest first. |
-a, --all |
Unmount everything in /proc/self/mounts except the special system mounts. |
-t TYPE |
With -a, only this filesystem type. |
-r |
If unmounting fails, try to remount read-only. |
-d |
Also free the loop device behind the mount. |
-n |
Do not write /etc/mtab. |
-v |
Verbose. |
Returns: 0 on success; 1 for problems such as insufficient permission, an unmounted target or "target is busy"; 32 for failures reported by the mount helpers; 64 for partial success with -a.
Usage notes
- "target is busy". A process has a file open there, or its working directory is inside. Find it with
lsof+f -- /mnt/usborfuser -vm /mnt/usb. Your own shell counts:cd /first. - Lazy unmount (
-l) hides the filesystem right away but keeps it alive until the last user leaves. It is a clean-up tool, not a fix: the data is not flushed until then, so never pull a removable disk after a lazy unmount. - Force (
-f) only helps for network filesystems whose server has disappeared. On a local disk it does nothing useful. - Flush first.
umountsyncs before detaching; withsyncyou can also flush manually. Seesync. - Order matters. A filesystem that has other filesystems mounted inside cannot be unmounted until the inner ones are gone.
umount -Rhandles that. - Ordinary users can unmount only filesystems they were allowed to mount (the
userorusersoption in/etc/fstab, or desktop auto-mounts). - Never unmount
/proc,/sysor/devon a running system. Many programs break at once. - Shutdown unmounts everything for you; after a crash the filesystem is marked dirty and checked on next mount. See
fsck. - Different namespaces. A container may have its own mounts.
umountonly acts on the mount namespace of the process that runs it.
Related
mount,lsof,sync,findmnt,fsck- Lessons: Disks and Logs, Rescue and Recovery