The umount command in Linux safely detaches a filesystem before physical removal of the storage device. Learning how to unmount in Linux is essential for preventing data corruption and ensuring your system remains stable. This guide covers everything from basic commands to troubleshooting common issues.
When you plug in a USB drive or mount an external disk, Linux attaches it to the directory tree. Before you yank it out, you must unmount it properly. Otherwise, you risk losing data or damaging the filesystem.
What Does Unmounting Mean In Linux
Unmounting is the process of detaching a filesystem from the mount point. The mount point is a directory where the filesystem is accessible. Once unmounted, the device is no longer available for reading or writing.
Think of it like unplugging a lamp from the wall socket. You don’t just cut the cord—you switch it off first. Unmounting is that safety switch for your storage devices.
The system buffers writes in memory. If you remove the device without unmounting, those buffered writes may not complete. This leads to corrupt files or even a broken filesystem.
How To Unmount In Linux
Now let’s get into the actual steps. The primary command for unmounting is umount (note the missing ‘n’—it’s not “unmount”). You’ll use it in the terminal with either the device name or the mount point.
Basic Umount Command Syntax
The syntax is straightforward:
umount [options] <device_or_mount_point>
You can specify either the device file (like /dev/sdb1) or the directory where it’s mounted (like /mnt/usb). Both work the same way.
Unmount By Device Name
First, find the device name using lsblk or df -h. Then run:
sudo umount /dev/sdb1
Replace /dev/sdb1 with your actual device. The sudo is often needed because unmounting requires root privileges.
Unmount By Mount Point
If you know the mount point directory, use that instead:
sudo umount /mnt/usb
This is often easier because you don’t need to remember the device name. Just the path where it’s mounted.
Force Unmount When Device Is Busy
Sometimes the system says “target is busy.” This means a process is using the filesystem. You can force unmount with the -l (lazy) or -f (force) options:
sudo umount -l /mnt/usb
The lazy option detaches the filesystem immediately and cleans up later. The force option is more aggressive:
sudo umount -f /mnt/usb
Use these carefully. Forcing an unmount can cause data loss if processes are still writing.
Unmount All Filesystems
To unmount all filesystems except the root, use:
sudo umount -a
This is useful before shutting down or when you want to clean up all mounted devices. Be cautious—it won’t unmount filesystems that are in use.
Common Unmount Errors And Solutions
You’ll likely run into errors. Here are the most common ones and how to fix them.
Target Is Busy
This is the most frequent error. It means a process is accessing the filesystem. Use lsof or fuser to find the culprit:
lsof | grep /mnt/usb
Or:
fuser -v /mnt/usb
Once you see the process ID, you can kill it with kill or close the application that’s using it.
Device Is Mounted In Multiple Locations
If you mount the same device to multiple directories, you need to unmount each one individually. Check with mount | grep /dev/sdb1 to see all mount points.
Not Superuser
If you get a permission error, add sudo before the command. Most unmount operations require root access.
Filesystem Is Read-Only
This is usually not an error but a warning. If the filesystem is mounted read-only, unmounting should still work. If it fails, check for hardware issues.
How To Unmount A USB Drive In Linux
USB drives are the most common devices you’ll unmount. Here’s a step-by-step guide.
- Insert the USB drive. It usually mounts automatically under
/media/yourusername/. - Open a terminal.
- Run
df -hto find the mount point. Look for a device like/dev/sdb1. - Close any file managers or applications that are accessing the USB.
- Run
sudo umount /dev/sdb1orsudo umount /media/yourusername/USBNAME. - Wait for the command to complete. No output means success.
- Now you can safely remove the USB drive.
If you get a “target is busy” error, close all open files and terminals that might be using the USB. You can also use lsof to find the offending process.
How To Unmount An NFS Share
Network File System (NFS) shares require the same umount command. But there are some extra considerations.
Unmount NFS With Force
If the NFS server is unreachable, the unmount may hang. Use the -f option to force it:
sudo umount -f /mnt/nfs_share
This works even if the server is down. But it may leave stale file handles.
Unmount All NFS Shares
To unmount all NFS filesystems, use:
sudo umount -a -t nfs
This targets only NFS type filesystems, leaving local ones intact.
How To Unmount A Loop Device
Loop devices are used for mounting ISO files or disk images. To unmount them, first unmount the filesystem, then detach the loop device.
sudo umount /mnt/iso
sudo losetup -d /dev/loop0
Replace /dev/loop0 with your actual loop device. You can find it with losetup -a.
How To Unmount A Bind Mount
Bind mounts make a directory accessible from another location. Unmounting them is the same as any other mount:
sudo umount /path/to/bind/mount
But note that the original directory remains mounted. You need to unmount the original separately if desired.
How To Unmount A CIFS/Samba Share
Windows shares mounted with CIFS can be unmounted normally:
sudo umount /mnt/windows_share
If it’s stuck, use the -f option. You may also need to specify the filesystem type:
sudo umount -t cifs /mnt/windows_share
How To Check If Unmount Was Successful
After running the command, verify with df -h or mount. The device should no longer appear in the list. You can also check the mount point directory—it should be empty.
If you see the device still listed, try unmounting again. Sometimes a lazy unmount takes a moment to complete.
How To Unmount Multiple Devices At Once
You can unmount multiple devices in one command by listing them:
sudo umount /dev/sdb1 /dev/sdc1 /mnt/backup
Or use a wildcard if your shell supports it. But be careful—wildcards can match unintended devices.
How To Unmount Using File Manager
Most desktop environments offer a graphical way to unmount. In Nautilus (GNOME), right-click the device icon and select “Unmount” or “Safely Remove Drive.” In Dolphin (KDE), look for the eject icon next to the device name.
This method is safer for beginners because it automatically closes open files. But it still uses the umount command behind the scenes.
How To Unmount In Linux Without Sudo
Normal users can unmount devices they mounted themselves, provided the mount point is in their home directory or /media. But most system mounts require root. If you want to allow a user to unmount without sudo, add an entry in /etc/fstab with the user option.
/dev/sdb1 /mnt/usb vfat user,noauto 0 0
Then the user can run umount /mnt/usb without sudo.
How To Unmount A Filesystem That Is In Use
When a filesystem is busy, you have several options:
- Find and close the process using
lsoforfuser. - Use lazy unmount
umount -l. - Use force unmount
umount -f. - Remount read-only first, then unmount:
mount -o remount,ro /mnt/usb.
The remount option is safest because it stops all writes before unmounting.
How To Unmount In Linux When Device Is Not Responding
If the device is unresponsive, try these steps:
- Use
umount -lfor a lazy unmount. - If that fails, use
umount -f. - As a last resort, reboot the system. The device will be unmounted during shutdown.
Never physically remove a device while it’s still mounted, even if it’s unresponsive. Wait for the system to finish.
How To Unmount In Linux Using Systemd
Systemd provides a systemd-umount tool, but it’s rarely used directly. Instead, use systemctl to unmount mount units:
sudo systemctl stop mnt-usb.mount
Replace mnt-usb.mount with the actual unit name. This is useful for managing mounts as services.
How To Unmount In Linux Automatically
You can configure automatic unmounting using udev rules or systemd. For example, when a USB drive is removed, a rule can trigger unmount. But this is advanced and not recommended for beginners.
For most users, manual unmounting is sufficient. Just remember to do it before removing the device.
How To Unmount In Linux With A Script
You can write a simple bash script to unmount all external drives:
#!/bin/bash
for dev in /dev/sd*; do
if mount | grep -q "$dev"; then
sudo umount "$dev"
fi
done
Save it as unmount_all.sh, make it executable with chmod +x, and run it with sudo.
How To Unmount In Linux On Raspberry Pi
Raspberry Pi uses the same commands. But because it’s often headless, you’ll rely on SSH. The process is identical:
sudo umount /dev/sda1
If you’re using a USB SSD, make sure no processes are writing to it. Check with iotop or htop.
How To Unmount In Linux For Docker Containers
Docker containers may have mounted volumes. To unmount them, stop the container first:
docker stop container_name
docker rm container_name
Then unmount the volume if it’s still attached. Docker usually cleans up automatically.
How To Unmount In Linux For Virtual Machines
If you’re using a VM with mounted ISOs, unmount from within the VM first. Then detach the ISO from the hypervisor. For VirtualBox, use the Storage settings.
How To Unmount In Linux For Encrypted Drives
Encrypted drives (LUKS) require two steps. First unmount the filesystem, then close the encrypted device:
sudo umount /mnt/crypt
sudo cryptsetup luksClose /dev/mapper/cryptname
Replace cryptname with your mapper name. You can find it with ls /dev/mapper/.
How To Unmount In Linux For ZFS Filesystems
ZFS uses its own commands. To unmount a ZFS dataset:
sudo zfs unmount tank/dataset
Or use the traditional umount command, but ZFS prefers its own tool.
How To Unmount In Linux For Btrfs Filesystems
Btrfs works with standard umount. But if you have subvolumes, you may need to unmount each one:
sudo umount /mnt/btrfs_subvol
Check with btrfs subvolume list to see all subvolumes.
How To Unmount In Linux For FUSE Filesystems
FUSE filesystems (like sshfs, rclone mount) can be unmounted with fusermount:
fusermount -u /mnt/fuse_mount
Or use umount if it’s integrated. FUSE mounts often run as user, so you may not need sudo.
Frequently Asked Questions
What Is The Difference Between Umount And Unmount?
The correct command is umount (without the ‘n’). “Unmount” is a common misspelling. Some systems have an alias, but always use umount for reliability.
Can I Unmount A Filesystem While It’s In Use?
Yes, with the lazy option -l or force option -f. But this can cause data loss. Always try to close processes first.
Why Does Umount Say “Target Is Busy”?
A process is using the filesystem. Use lsof or fuser to find it, then close the application or kill the process.
How Do I Unmount A Device Without Knowing The Mount Point?
Use lsblk or df -h to list all mounted devices and their mount points. Then unmount by device name.
Is It Safe To Force Unmount A USB Drive?
Only as a last resort. Force unmounting can corrupt data. Always try normal unmount first, then lazy unmount, then force.
Mastering how to unmount in Linux is a fundamental skill. It protects your data and keeps your system healthy. Practice with a spare USB drive to build confidence. Remember: always unmount before you unplug.