Skip to main content

Command Palette

Search for a command to run...

How to Unmount a Drive in Linux

Updated
6 min read

Unmounting a drive in Linux is a common task that you might need to do when managing your system’s storage. Whether you want to safely remove a USB stick, disconnect a network drive, or prepare a partition for maintenance, knowing how to unmount drives correctly is essential. In this article, I’ll guide you through the process step-by-step, making it easy for you to handle drives without risking data loss.

You don’t need to be a Linux expert to follow along. I’ll explain everything in simple terms and show you both command-line and graphical ways to unmount drives. By the end, you’ll feel confident managing your drives safely and efficiently on any Linux system.

What Does It Mean to Unmount a Drive in Linux?

Unmounting a drive means telling your Linux system to stop using it. When a drive is mounted, the system reads and writes data to it. Unmounting safely disconnects the drive so you can remove it or perform other tasks without corrupting files.

Here’s why unmounting is important:

  • Prevents data loss: If you remove a drive without unmounting, ongoing data transfers might be interrupted.
  • Frees system resources: The system releases the drive, making it available for other uses.
  • Allows maintenance: You can run disk checks or format drives only when they are unmounted.

In Linux, drives are usually mounted to directories like /mnt or /media. When you unmount, you detach the drive from these directories.

How to Check Which Drives Are Mounted

Before unmounting, you need to know which drives are currently mounted on your system. Here are some ways to check:

  • Using the mount command:
    Open a terminal and type mount. This lists all mounted filesystems with their mount points.

  • Using df -h:
    This command shows disk space usage and mounted drives in a human-readable format.

  • Using lsblk:
    Lists all block devices and their mount points, showing drives and partitions clearly.

Example output from lsblk:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0  100G  0 part /
├─sda2   8:2    0  365G  0 part /home
sdb      8:16   1  14.9G  0 disk 
└─sdb1   8:17   1  14.9G  0 part /media/usb

This shows a USB drive mounted at /media/usb.

How to Unmount a Drive Using the Command Line

The command line is the most reliable way to unmount drives in Linux. Here’s how you can do it:

Step 1: Identify the Mount Point or Device Name

You can unmount by specifying either the mount point (like /media/usb) or the device name (like /dev/sdb1).

Step 2: Use the umount Command

The basic command to unmount is:

sudo umount /mount/point

or

sudo umount /dev/sdXY

Replace /mount/point with the actual directory and /dev/sdXY with the device name.

Example

If your USB drive is mounted at /media/usb, run:

sudo umount /media/usb

Or if you prefer using the device name:

sudo umount /dev/sdb1

Step 3: Verify the Drive Is Unmounted

Run lsblk or mount again to confirm the drive is no longer listed as mounted.

Handling Busy Drives

Sometimes, you might get an error like:

umount: /media/usb: target is busy.

This means some process is using the drive. To fix this:

  • Close any files or terminals using the drive.
  • Use lsof to find open files:
sudo lsof /media/usb
  • Kill the processes if needed:
sudo kill -9 <PID>
  • Then try unmounting again.

Alternatively, use the lazy unmount option:

sudo umount -l /media/usb

This detaches the filesystem immediately and cleans up later.

Unmounting Drives Using GUI Tools

If you prefer not to use the terminal, most Linux desktop environments offer graphical ways to unmount drives.

GNOME (Ubuntu, Fedora)

  • Open the Files app.
  • Find your drive in the sidebar.
  • Click the eject icon next to the drive name.
  • The drive will unmount safely.

KDE Plasma

  • Open Dolphin file manager.
  • Right-click the drive in the sidebar.
  • Select Unmount or Eject.

XFCE

  • Use the Thunar file manager.
  • Right-click the drive.
  • Choose Unmount.

These GUI methods are user-friendly and perfect for casual users.

Unmounting Network Drives in Linux

Network drives like NFS or Samba shares are also mounted and can be unmounted similarly.

  • Use the umount command with the mount point:
sudo umount /mnt/network_share
  • If the network share is busy, use the lazy unmount option -l.

  • For CIFS mounts, you might need to unmount with:

sudo umount -t cifs /mnt/network_share

Unmounting network drives frees up network resources and ensures no data is lost.

Automating Unmounting with Scripts

If you often need to unmount drives, you can automate the process with a simple script.

Example script to unmount a USB drive:

#!/bin/bash
MOUNT_POINT="/media/usb"

if mountpoint -q "$MOUNT_POINT"; then
  sudo umount "$MOUNT_POINT"
  echo "Drive unmounted successfully."
else
  echo "Drive is not mounted."
fi

Save this as unmount_usb.sh, make it executable with chmod +x unmount_usb.sh, and run it whenever needed.

Best Practices When Unmounting Drives

To avoid problems, keep these tips in mind:

  • Always close files and applications using the drive before unmounting.
  • Avoid force unmounting unless necessary.
  • Use the sync command before unmounting to flush disk buffers.
  • For removable drives, wait for the system to confirm unmounting before unplugging.
  • Regularly check mounted drives with lsblk or mount.

Troubleshooting Common Unmount Issues

Here are solutions to common problems you might face:

ProblemSolution
Target is busy errorClose apps, use lsof to find processes, kill them, or use umount -l.
Permission deniedUse sudo to run unmount commands.
Drive not foundCheck correct mount point or device name with lsblk.
Drive still appears mountedRefresh file manager or reboot if necessary.

Conclusion

Unmounting drives in Linux is a straightforward but important task to keep your data safe and your system running smoothly. Whether you use the command line or a graphical interface, the key is to unmount drives properly before removing or modifying them. I’ve shown you how to identify mounted drives, unmount them safely, and handle common issues.

By practicing these steps, you’ll avoid data loss and system errors. Remember, unmounting is a simple habit that protects your files and hardware. Next time you need to remove a USB stick or disconnect a network share, you’ll know exactly what to do.

FAQs

How do I unmount a drive if it says "target is busy"?

Close any files or programs using the drive. Use sudo lsof /mount/point to find open files and kill those processes. If needed, use sudo umount -l /mount/point for a lazy unmount.

Can I unmount a drive without sudo?

Usually, unmounting requires root permissions, so you need to use sudo. Some desktop environments allow unmounting without sudo if you own the mount point.

What is the difference between unmount and eject?

Unmount detaches the filesystem from the system. Eject also powers down or physically ejects removable media like CDs or USB drives, depending on hardware support.

How do I unmount a network drive in Linux?

Use the umount command with the network share’s mount point, like sudo umount /mnt/network_share. For CIFS shares, specify the type with -t cifs if needed.

Is it safe to unplug a USB drive without unmounting?

No, unplugging without unmounting can cause data loss or corruption. Always unmount first to ensure all data is written and the drive is safely disconnected.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts