Description of problem: A cryptsetup device can't be removed once the underlying device disappeared. My external hard drive does not work well with suspend/resume. It happens quite often that the device does need to be reconnected if it was not detected properly after a resume. It contains an encrypted partition. Once the resume of the hdd failed, the encrypted partition on hdd is still available and can not be removed. My current "solution" is to reboot the system once this happens. The reconnected hdd, containing the encrypted partition has the same UUID again and can not be mounted before the old device is removed completely. Version-Release number of selected component (if applicable): Kernel 3.9.9-301.fc19.x86_64, cryptsetup 1.6.1-1.fc19, device-mapper 1.02.77-9.fc19 Steps to Reproduce: 1. Suspend/Resume failure (To be reported) 2. Device still visible in Nautilus but can not be unmounted 3. cryptsetup close does not work Actual results: $ cryptsetup --debug close luks-UUID # cryptsetup 1.6.1 processing "cryptsetup --debug close luks-UUID" # Running command close. # Locking memory. # Installing SIGINT/SIGTERM handler. # Unblocking interruption on signal. # Allocating crypt device context by device luks-UUID. # Initialising device-mapper backend library. # dm version OF [16384] (*1) # dm versions OF [16384] (*1) # Detected dm-crypt version 1.12.1, dm-ioctl version 4.24.0. # Device-mapper backend running with UDEV support enabled. # dm status luks-UUID OF [16384] (*1) # Releasing device-mapper backend. # Allocating crypt device (null) context. # Initialising device-mapper backend library. Underlying device for crypt device luks-UUID disappeared. # dm table luks-UUID OFW [16384] (*1) # LUKS device header not available. # Deactivating volume luks-UUID. # dm status luks-UUID OF [16384] (*1) # Udev cookie 0xd4da9e5 (semid 884736) created # Udev cookie 0xd4da9e5 (semid 884736) incremented to 1 # Udev cookie 0xd4da9e5 (semid 884736) incremented to 2 # Udev cookie 0xd4da9e5 (semid 884736) assigned to REMOVE task(2) with flags (0x0) # dm remove luks-UUID OFT [16384] (*1) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*2) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*3) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*4) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*5) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*6) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*7) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*8) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*9) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*10) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*11) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*12) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*13) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*14) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*15) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*16) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*17) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*18) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*19) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*20) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*21) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*22) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*23) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*24) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # dm remove luks-UUID OFT [16384] (*25) device-mapper: remove ioctl on luks-UUID failed: Device or resource busy # Udev cookie 0xd4da9e5 (semid 884736) decremented to 1 # Udev cookie 0xd4da9e5 (semid 884736) decremented to 0 # Udev cookie 0xd4da9e5 (semid 884736) waiting for zero # Udev cookie 0xd4da9e5 (semid 884736) destroyed # dm status luks-UUID OF [16384] (*1) Device luks-UUID is still in use. # Releasing crypt device (null) context. # Releasing device-mapper backend. # Unlocking memory. Command failed with code 16: Device luks-UUID is still in use. $ dmsetup remove --force luks-UUID device-mapper: resume ioctl on luks-UUID failed: Invalid argument device-mapper: remove ioctl on luks-UUID failed: Device or resource busy Command failed Expected results: Removal of the cryptsetup device if the underlying device disappeared.
cryptsetup can remove device if underlying device disappeared. But it cannot remove device which is still in use (here perhaps mounted). As you already found, dmsetup remove -f can detach underlying device by replacing it with "error" device but it cannot remove device itslef from system. Can you please paste output of lsblk and mount? If you see luks device still mounted, just umount -f and releat luks removal. It should work. (and udisks should do this automatically btw...)
I found a simpler way of getting my system in the problematic state: Keeping a terminal open on the luks partition, and then pulling the cable of the hdd. $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 119,2G 0 disk ├─sda1 8:1 0 600M 0 part /boot ├─sda3 8:3 0 1G 0 part [SWAP] └─sda4 8:4 0 117,7G 0 part /home $ mount |grep -i luks <empty> $ lsof luks-UUID lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete. $ fuser -m luks-UUID <empty> Now, if I close the shell in question, of which I need to be aware, I can unmount the device using cryptsetup but only from the console. Nautilus show while accessing the still visible mount point: Error mounting /dev/dm-0 at /run/media/user/NAME: Command-line `mount -t "ext4" -o "uhelper=udisks2,nodev,nosuid" "/dev/dm-0" "/run/media/user/NAME"' exited with non-zero exit status 32: mount: wrong fs type, bad option, bad superblock on /dev/mapper/luks-UUID, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. Besides, I could mount or format the device using nautilus. (dmesg shows many errors, but that's about it.) How can I find out which process needs to be killed and, maybe, have that process killed automatically?
Hm. This seems to be problem with lazy umount (see man umount -l). lsof should help (any file open on the mounted fs over luks etc). You can see open count using "dmsetup info -c". If device has open count > 0, then removal will fail as you described.
$ dmsetup info -c Name Maj Min Stat Open Targ Event UUID luks-UUID 253 0 L--w 1 1 0 CRYPT-LUKS1-UUID-luks-UUID ..works as expected, before and after unplugging. lsof yields interesting results: While the hdd is connected: $ lsof |grep $PID_OF_BASH |grep cwd bash $PID_OF_BASH user cwd DIR 253,0 4096 2 /run/media/user/mountpoint After unplugging: $ lsof |grep $PID_OF_BASH |grep cwd bash $PID_OF_BASH user cwd DIR 253,0 4096 2 / Grepping for luks or dm-0 does not yield any useful information either...
This message is a notice that Fedora 19 is now at end of life. Fedora has stopped maintaining and issuing updates for Fedora 19. It is Fedora's policy to close all bug reports from releases that are no longer maintained. Approximately 4 (four) weeks from now this bug will be closed as EOL if it remains open with a Fedora 'version' of '19'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Fedora version. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora 19 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora, you are encouraged change the 'version' to a later Fedora version prior this bug is closed as described in the policy above. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Fedora release includes newer upstream software that fixes bugs or makes them obsolete.
Fedora 19 changed to end-of-life (EOL) status on 2015-01-06. Fedora 19 is no longer maintained, which means that it will not receive any further security or bug fix updates. As a result we are closing this bug. If you can reproduce this bug against a currently maintained version of Fedora please feel free to reopen this bug against that version. If you are unable to reopen this bug, please file a new report against the current release. If you experience problems, please add a comment to this bug. Thank you for reporting this bug and we are sorry it could not be fixed.