device-mapper: remove ioctl on luks-xxxx failed: Device or resource busy

Solution 1:

After two years of fighting with this, I think I've finally cracked it completely!

dmsetup ls gives you the data you need:

$ sudo dmsetup ls
luks-xxxxx (252:1)

then

sudo lsof |grep 252,1

It seems that sudo may be critical here -- at least in some cases.


This should give you the information necessary to close all open files on the device -- including names of open files and process IDs for the offending applications. You may be able to simply go to those apps and close them, but a brute force approach might be something like:

kill -9 (process ID)

Once you've closed all the files, some of the command-line tools shown in the question may be necessary in order to close down the existing mount before it can be reopened normally.

Solution 2:

Try to stop LVM group prior to stop cypher:

lvchange -a n [LVM_Group_name]

then

cryptsetup -v luksClose [LUKS_name]

Sample:

lvchange -a n My_vg_crypt
cryptsetup -v luksClose My_Crypt

Solution 3:

next time try a lazy umount

umount -l /<folder>

This works for me most of the times, especially useful with hung-up NFS-drives.