Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

The target is busy error often occurs when trying to unmount a file system that’s still in use. Linux uses this safeguard to prevent data corruption when processes actively access files or directories on the busy device. That’s why proper unmounting is crucial—it ensures data is safely written before disconnecting the device.

From unplugging USB drives to handling shared network storage, it’s always useful to know how to properly unmount devices.

In this tutorial, we’ll cover practical methods to safely unmount busy devices, from checking and killing active processes to forcefully unmounting when necessary.

2. Why Does Unmounting Fail?

Linux protects file system integrity by blocking unmounting when a device is still in use. Simply put, this prevents potential data loss or corruption.

The system usually blocks us from unmounting a device when:

  • a terminal session or file manager is working within a directory on the device
  • background processes are accessing files stored on the device
  • network storage (like NFS) is actively sharing files

In the next sections, we’ll cover the most common methods to unmount busy devices.

3. Identify What’s Keeping the Device Busy

Let’s use the umount command to detach a busy device:

$ sudo umount /media/mydisk
umount: /media/mydisk: target is busy.

This error message indicates the system is actively using the mount point.

Before we can unmount this busy device, it’s always smart to find out what’s using it. For this, we can rely on a couple of handy tools: lsof and fuser.

3.1. List Open Files With lsof

The lsof command shows every process accessing files on a mounted device. Let’s check what’s locking the device:

$ sudo lsof /media/mydisk/
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
file-roll 5126 ubuzz   13r   REG   0,40  1029608    2 /media/test/network-manager-gnome_1.8.20-1.1_amd64.deb

This lists all processes that are still using /media/mydisk/. From the results, we can see which specific process is preventing the unmount. In this case, network-manager-gnome_1.8.20-1.1_amd64.deb is the one keeping the device busy.

3.2. File User Check With fuser

Another quick way is fuser, which shows which processes are using files in a device:

$ sudo fuser -vm /media/mydisk/
                     USER        PID ACCESS COMMAND
/media/mydisk:         root     kernel mount /media/test
                     ubuzz      5126 f.... file-roller

Here, the -v flag gives a verbose output, while -m checks all processes on the mount point (/media/mydisk/).

From the output, we can see the user, the PID (Process ID), and the command responsible for keeping the device busy. Once we get the PID, we can terminate the process and then unmount the device safely.

4. Force Unmount Options

After identifying what’s holding the device, the next step is to stop active processes and detach the device.

4.1. Killing Processes

One way is to force-terminate specific processes with kill:

$ sudo kill -9 5126  

Here, 5126 is the PID of the process holding the device. The -9 flag sends the SIGKILL signal, which forcefully terminates the process. Unlike other signals, SIGKILL stops the process immediately. Therefore, it’s important to use this option carefully, as it doesn’t allow the process to clean up or save data properly.

After that, we should be able to unmount the device successfully.

4.2. Lazy Unmount

There’s a gentler alternative to unmount a busy device without abruptly stopping processes.

We can perform a lazy unmount to immediately detach the filesystem while allowing background processes to complete. This is perfect when we need to unmount, but can’t stop active processes like file transfers.

Let’s try the -l flag (short for lazy) to unmount the busy device:

$ sudo umount -l /media/mydisk/

Here, the filesystem immediately disappears from the directory tree while letting background operations like file transfers complete safely. Noteably, this delays actual unmounting until all processes finish.

4.3. Force Unmount

In other cases where nothing else works—and we’re certain it’s safe to proceed—we can force the unmount using the -f (force) flag:

$ sudo umount -f /media/mydisk/

This option allows unmounting the device forcefully. However, we should use it carefully to avoid data corruption.

5. Verify Successful Unmounting

After trying to unmount a device (whether normally, lazily, or forcefully), it’s smart to double-check that it worked. We have several quick ways to verify this.

The simplest method is to list mounted filesystems using the mount and grep commands, and look for the target device:

$ mount | grep mydisk

Nothing shows up here because the unmount was successful. If the command outputs /media/mydisk, it means the device is still mounted. This command gives a quick yes/no answer on whether the unmount worked.

6. Conclusion

In this article, we explored the target is busy error, the reasons behind unmounting failures, and practical methods to resolve the issue. Specifically, we looked at lsof and fuser to pinpoint active processes and explored umount options like -l and -f  to forcefully unmount devices.