How To Unmount A Drive In Linux – Storage Device Ejection Methods

Unmounting a drive in Linux requires using the umount command followed by the device’s mount point. If you are new to Linux, understanding how to unmount a drive in linux is essential for safely removing storage devices and avoiding data corruption.

This guide will walk you through every method, from basic commands to advanced scenarios. You will learn the exact steps, common errors, and best practices to keep your data safe.

How To Unmount A Drive In Linux

Before you unmount a drive, you need to know its mount point or device name. The umount command is the primary tool for this task. It detaches the filesystem from the directory tree.

Check Current Mounted Drives

First, list all mounted drives to find the one you want to unmount. Use the lsblk or mount command.

  • lsblk shows block devices and their mount points.
  • mount displays all active mounts.
  • df -h shows disk usage and mount points.

For example, if you see /dev/sdb1 mounted at /mnt/usb, that is your target.

Basic Unmount Command

The simplest way to unmount is by specifying the mount point:

sudo umount /mnt/usb

You can also use the device path:

sudo umount /dev/sdb1

Both commands achieve the same result. The system will release the drive safely.

Force Unmount A Busy Drive

Sometimes a drive is “busy” because a process is using it. The unmount will fail with a “target is busy” error. You can force the unmount with the -f flag.

sudo umount -f /mnt/usb

Be careful: force unmounting can cause data loss if files are being written. Always try to close programs first.

Lazy Unmount (Detach Later)

If you want to unmount immediately but allow ongoing operations to finish, use the lazy option -l. This detaches the filesystem now and cleans up later.

sudo umount -l /mnt/usb

This is usefull when you cannot close a process but need to remove the device quickly.

Unmount All Mounted Drives

To unmount all filesystems except the root, use the -a flag. This is rarely needed but can be handy for scripts.

sudo umount -a

This will skip the root filesystem automatically. Use with caution.

Common Errors And Solutions

You will encounter errors when unmounting. Here are the most frequent ones and how to fix them.

Target Is Busy

This error means a program is accessing the drive. Use lsof or fuser to find the culprit.

lsof | grep /mnt/usb

Or:

fuser -v /mnt/usb

Once you identify the process, close it or kill it with kill.

Device Is In Use By System

Some system processes like systemd or udisks might hold the mount. Try unmounting with sudo umount -l first.

Not Mounted Error

If you get “not mounted” but you see it in lsblk, the mount point might be stale. Check the exact path again.

Unmounting Specific Drive Types

Different drives require slightly different approaches. Here are common scenarios.

Unmount USB Drive

USB drives are usually mounted under /media/username/ or /mnt. Use the same umount command.

  1. Run lsblk to identify the USB drive (e.g., /dev/sdc1).
  2. Unmount with sudo umount /dev/sdc1.
  3. Safely remove the drive after the command completes.

Unmount Network Drive (NFS)

Network File System (NFS) mounts can be unmounted normally, but ensure no network issues exist.

sudo umount /mnt/nfs_share

If the NFS server is unreachable, use the -f or -l option.

Unmount ISO Image

ISO files mounted via loop device can be unmounted like any other drive.

sudo umount /mnt/iso

Then detach the loop device if needed: sudo losetup -d /dev/loop0.

Using GUI Tools To Unmount

If you prefer a graphical interface, most desktop environments offer a simple unmount option. Right-click the drive icon in the file manager and select “Unmount” or “Eject”.

This is the easiest way for beginners. The system handles the command automatically.

Unmount Drive With Systemd

Modern Linux systems use systemd for mount management. You can unmount using systemctl if the mount is defined as a unit.

sudo systemctl stop mnt-usb.mount

This is more common for permanent mounts defined in /etc/fstab.

Automating Unmount With Scripts

You can write a bash script to unmount multiple drives or schedule unmounts. Here is a simple example.

#!/bin/bash
for mount in /mnt/drive1 /mnt/drive2; do
    sudo umount "$mount"
    if [ $? -eq 0 ]; then
        echo "Unmounted $mount successfully"
    else
        echo "Failed to unmount $mount"
    fi
done

Save this as a script and run it with sudo.

Best Practices For Safe Unmounting

Always follow these guidelines to avoid data loss.

  • Close all files and programs using the drive.
  • Check for open file handles with lsof.
  • Use sync before unmounting to flush buffers.
  • Never unplug a drive without unmounting first.
  • If unmount fails, try lazy unmount before forcing.

Unmount Drive As Non-Root User

Regular users can unmount drives they own, such as USB drives mounted automatically. Use udisksctl for a user-friendly approach.

udisksctl unmount -b /dev/sdb1

This works without sudo for most desktop setups.

Recovering From A Failed Unmount

If unmount fails repeatedly, try these steps.

  1. Run sudo fuser -km /mnt/usb to kill all processes using the mount.
  2. Then try sudo umount /mnt/usb again.
  3. If still stuck, reboot the system to release the mount.

Unmount Drive In Recovery Mode

If your system is unbootable, you can unmount drives from a live USB. Boot into a live environment, then mount and unmount as needed.

sudo umount /dev/sda2

This is usefull for repairing filesystems.

Understanding Mount Points

A mount point is a directory where the filesystem is attached. Common mount points include /mnt, /media, and /run/media. Always unmount by the mount point, not the device name, for clarity.

Difference Between Umount And Unmount

The command is umount, not unmount. This is a common typo. The correct spelling is umount (missing ‘n’).

If you type unmount, you will get a “command not found” error.

Unmount Drive With Specific Filesystem

Different filesystems (ext4, NTFS, FAT32) all unmount the same way. The umount command works regardless of the filesystem type.

Unmount Drive In Docker Containers

If you mount a drive inside a Docker container, unmount it from the host using the same commands. The container’s mount namespace is separate.

sudo umount /var/lib/docker/volumes/...

Unmount Drive With Encryption

For encrypted drives (LUKS), you must unmount the filesystem first, then close the encrypted device.

sudo umount /mnt/encrypted
sudo cryptsetup luksClose encrypted_device

Unmount Drive On Remote Server

If you are connected via SSH, unmounting works the same way. Ensure you have sudo privileges.

ssh user@server "sudo umount /mnt/data"

Unmount Drive With System Monitor

Some desktop environments provide a system monitor app that lets you unmount drives with a click. Look for “Disks” or “Disk Utility”.

Unmount Drive From Command Line Without Sudo

If you own the mount point (e.g., /media/username), you may not need sudo. Try umount /media/username/Drive first.

Unmount Drive When Directory Is Not Empty

Unmounting works even if the mount point directory contains other files. Those files are hidden until the drive is remounted.

Unmount Drive And Remove Mount Point

After unmounting, you can delete the mount point directory if it is no longer needed.

sudo rmdir /mnt/usb

This is optional and safe.

Unmount Drive With UUID

You can unmount using the filesystem’s UUID instead of the device name. Find the UUID with blkid.

sudo umount UUID="your-uuid-here"

This is usefull for scripts.

Unmount Drive In Virtual Machine

If you pass through a USB drive to a VM, unmount it from the host first. Then detach it from the VM.

Unmount Drive With NFS Version 4

NFSv4 mounts may require the -t nfs4 option, but usually umount works without it.

Unmount Drive With Fuse Filesystem

FUSE filesystems (like sshfs) can be unmounted with fusermount -u or umount.

fusermount -u /mnt/sshfs

Unmount Drive When System Is Hibernated

Do not unmount drives on a hibernated system. Boot fully first.

Unmount Drive With Read-Only Error

If the drive is read-only, unmount it normally. The error may indicate filesystem damage.

Unmount Drive And Check Filesystem

After unmounting, you can run fsck to check for errors.

sudo fsck /dev/sdb1

Unmount Drive With Multiple Partitions

Unmount each partition individually. You cannot unmount the whole disk at once.

Unmount Drive In Linux Mint

Linux Mint users can right-click the drive in the file manager and select “Unmount”.

Unmount Drive In Ubuntu

Ubuntu uses the same commands. The GUI option is also available.

Unmount Drive In Fedora

Fedora works identically. Use sudo umount.

Unmount Drive In Arch Linux

Arch Linux users have the same tools. The umount command is part of the core utilities.

Unmount Drive In Raspberry Pi

On Raspberry Pi OS, use the same commands. The drive is often mounted under /media/pi.

Unmount Drive In WSL

Windows Subsystem for Linux does not support unmounting drives directly. Use Windows tools instead.

Unmount Drive In Termux

Termux on Android does not have umount by default. Use su if rooted.

Unmount Drive With Samba Share

Samba mounts can be unmounted with umount or smbumount.

Unmount Drive With CIFS

CIFS mounts are unmounted normally.

sudo umount /mnt/cifs

Unmount Drive With Bind Mount

Bind mounts are unmounted the same way.

sudo umount /mnt/bind

Unmount Drive With Overlay Filesystem

Overlay mounts require unmounting each layer separately.

Unmount Drive With Tmpfs

Tmpfs mounts are unmounted normally. They are often used for temporary storage.

Unmount Drive With Ramfs

Ramfs mounts work the same as tmpfs.

Unmount Drive With Debugfs

Debugfs is a special filesystem; unmount it with umount.

Unmount Drive With Sysfs

Sysfs is a virtual filesystem; do not unmount it.

Unmount Drive With Procfs

Procfs is also virtual; never unmount it.

Unmount Drive With Devtmpfs

Devtmpfs is critical; do not unmount.

Unmount Drive With Cgroup

Cgroup mounts are system-managed; avoid unmounting.

Unmount Drive With Pstore

Pstore is for kernel logs; unmounting is not recommended.

Unmount Drive With Hugetlbfs

Hugetlbfs is for huge pages; unmount if needed.

Unmount Drive With Configfs

Configfs is for kernel configuration; unmount with caution.

Unmount Drive With Securityfs

Securityfs is for security modules; do not unmount.

Unmount Drive With Efivarfs

Efivarfs is for EFI variables; unmount only if necessary.

Unmount Drive With Bpf Filesystem

BPF filesystem is for eBPF programs; unmount carefully.

Unmount Drive With Fuse Filesystem (Again)

FUSE filesystems are common for cloud storage like Google Drive.

sudo umount /mnt/gdrive

Unmount Drive With Sshfs

Sshfs mounts can be unmounted with fusermount -u.

Unmount Drive With Rclone Mount

Rclone mounts are FUSE-based; unmount with fuserm