I can't unmount a disk because something's using it. How do I find what?

Quick Linux Tip #21:

Try: sudo lsof +D /mnt/backup

Info: Lists all active processes holding open files under a specific directory to identify unmount blockers.

Examples:

  • $ sudo lsof +D /mnt/usb
  • $ sudo fuser -m /var/log  # List processes using filesystem
  • $ sudo fuser -k -SIGTERM /mnt/backup  # Graceful kill first

Note: +D recurses subdirectories. fuser -k sends SIGKILL by default; always try passing -SIGTERM first to allow processes to close gracefully.




LinuxTeck.com
linuxteck@ubuntu:~$ sudo lsof +D /mnt/backup
COMMAND   PID    USER       FD   TYPE DEVICE SIZE/OFF NODE NAME
bash      3456   linuxteck  cwd  DIR  8,1    4096     524290 /mnt/backup
vim       4567   linuxteck  4u   REG  8,1    12345    524301 /mnt/backup/notes.txt
rsync     5678   root       3w   REG  8,1    45678901 524325 /mnt/backup/data.tar

linuxteck@ubuntu:~$ sudo fuser -km /mnt/backup
/mnt/backup:            3456c  4567c  5678c
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #20: How do I write a script that cleans up its temp files even on errors? NEXT ARTICLE Quick Linux Tip #22: How do I prevent a runaway script from consuming all resources?
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.