使用cryptsetup创建LUKS加密文件容器后,umount与cryptsetup close报“target is busy”错误的问题咨询
I’ve seen this exact issue pop up for many users working with LUKS encrypted containers, and the root cause is almost always straightforward once you spot it. Let’s break down what’s happening and how to fix it:
Why This Happens
Looking at your command sequence, after mounting the encrypted device, you run:
cd mount_point sudo dd if=/dev/zero of=random_data.bin bs=1G count=1 status=progress
At this point, your terminal’s active working directory is inside the mounted filesystem (/data/test/mount_point). Linux prevents unmounting a filesystem that’s currently in use by a process—and your shell (the terminal session) counts as an active process holding that directory open. Closing the terminal kills that shell process, which releases the lock, allowing the unmount to succeed.
Fixes to Try (No Terminal Closing Needed)
Here are the simplest ways to resolve this without having to close your terminal:
Exit the mounted directory first
Before runningumount, change your working directory to somewhere outside the mount point, like the root directory or your home folder:cd / # Or go back up a few levels cd ../../Then run your unmount commands as normal:
sudo umount /data/test/mount_point cryptsetup -v close device_nameIdentify and terminate lingering processes
If exiting the directory doesn’t work (unlikely here, but useful for other cases), use tools to find which processes are using the mount point:- Use
lsofto list open files/processes tied to the mount:sudo lsof /data/test/mount_point - Or use
fuserto get process IDs (PIDs) directly:sudo fuser -m /data/test/mount_point
Once you have the PID(s), terminate the process safely (avoid
kill -9unless necessary):sudo kill <PID>Then retry the unmount.
- Use
Use lazy unmount as a last resort
If you can’t immediately free up the mount point, the-lflag forumountwill perform a "lazy unmount"—it detaches the filesystem immediately, and cleans up once no processes are using it:sudo umount -l /data/test/mount_point cryptsetup -v close device_nameThis is handy if you need to unmount quickly without hunting down processes.
Quick Note for Your Workflow
To avoid this issue in the future, remember to always navigate out of the mounted filesystem before trying to unmount it. It’s an easy oversight, but one that trips up even experienced users!
内容的提问来源于stack exchange,提问作者Damien LEFEVRE

