How to Fix Bash Device or Resource Busy Error in Linux

Working in the Linux terminal with file systems, storage volumes, network shares, or hardware interfaces is part of regular system administration. However, running commands like umount /mnt/data, rmdir /path/to/dir, or systemctl restart docker only to receive the standard POSIX error device or resource busy (error code EBUSY) prevents immediate execution. This error indicates that an active kernel thread, user process, or open file descriptor is locking the target resource.

Why Linux Returns “Device or Resource Busy”

The Linux kernel enforces strict access controls to prevent filesystem corruption:

  • Active Working Directory: A shell session or background daemon currently has its Current Working Directory (CWD) set inside the target mount point.
  • Open File Descriptors: A process is actively reading, writing, or holding a file handle on the volume.
  • Shared Network NFS/Samba Locks: Remote clients maintaining stateful file locks across the network.
  • Kernel Device Mappers or Loop Devices: A loopback device, LVM snapshot, or software RAID array still utilizing the underlying block storage.
  • Active Swap or Submounts: A swapfile or nested bind-mount active inside the directory hierarchy.

1. Identify Locking Processes with lsof

The lsof (List Open Files) utility pinpoints the exact Process ID (PID) and executable keeping the filesystem busy.

  1. Run lsof on the target directory or mount point with root privileges:
    sudo lsof +D /mnt/data
  2. Review the output columns:
    • COMMAND: The name of the process (e.g. python3, smbd, tail).
    • PID: The process identification number.
    • USER: The user account executing the command.
    • FD: File descriptor type (cwd means current working directory; txt means binary executable; numbers indicate open file handles).
  3. Gracefully terminate the locking process:
    sudo kill -15 <PID>

2. Find and Kill Busy Processes with fuser

The fuser tool directly queries the kernel for filesystem users and can automate terminating blocking tasks.

  1. List the PIDs holding access to the mount point:
    sudo fuser -v -m /mnt/data
  2. If an interactive shell is holding the directory open, check if any of your own terminal sessions are cd-ed into the folder. Change directory back to home:
    cd ~
  3. To send a SIGTERM signal to all processes locking the device:
    sudo fuser -k -TERM -m /mnt/data
  4. If processes refuse to release the resource, terminate them with SIGKILL:
    sudo fuser -k -9 -m /mnt/data

3. Perform a Lazy Unmount (umount -l)

When unmounting a busy volume where stopping all services immediately is impractical, perform a lazy unmount.

  1. Execute umount with the lazy flag:
    sudo umount -l /mnt/data
  2. A lazy unmount immediately detaches the filesystem from the directory hierarchy, so new processes cannot access it.
  3. The kernel cleans up all remaining references and flushes buffers asynchronously as soon as the active processes close their handles.

4. Check for Hidden Bind Mounts, Loop Devices, or Swap

Subordinate system structures often prevent parent device detachment.

  1. Check if the partition contains active Linux swap space:
    cat /proc/swaps
  2. If an active swapfile or partition is listed on that drive, disable it:
    sudo swapoff /mnt/data/swapfile
  3. Inspect active loopback devices associated with the filesystem:
    losetup -a
  4. Detach any lingering loop device:
    sudo losetup -d /dev/loopX
  5. Check for nested mounts via findmnt:
    findmnt | grep /mnt/data

5. Verify Hardware Interface or Serial Port Locks

If the error occurs on devices like /dev/ttyUSB0, modem managers or serial consoles may hold exclusive locks.

  1. Check which daemon owns the hardware node:
    sudo lsof /dev/ttyUSB0
  2. If ModemManager or brltty is claiming the port, temporarily stop the service:
    sudo systemctl stop ModemManager
  3. Re-run your serial or hardware communication command.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.