Description of problem: Error message after entering password when plugging in a USB disk after it fell off: Unable to mount 363 GB Encrypted Error unlocking device: cryptsetup exited with exit code 239: Command failed: Device devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 already exists. Version-Release number of selected component (if applicable): cryptsetup-luks-1.0.7-0.1.fc12.x86_64 How reproducible: Always Steps to Reproduce: 1.Uncleanly unplug USB device with mounted encrypted partition. 2.Plug in same device. Wait for gnome password prompt. Enter password. Actual results: Error Expected results: Device is mounted. Additional info:
Remounting encrypted disk after unclean dismount requires reboot. Error unlocking device: cryptsetup exited with exit code 239: Command failed: Device devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 already exists. [root@dent ~]# ls -l /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 brw-rw---- 1 root disk 253, 3 2009-09-04 02:43 /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 [root@dent root]# lsof /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 [root@dent ~]# [root@dent ~]# cryptsetup luksClose /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 Command failed: Device busy
Handling devices in use suddenly disappearing is very difficult and it should probably be done in the kernel instead of trying to piece things together in user space. I've opened a bug at https://bugs.freedesktop.org/show_bug.cgi?id=24279 to discuss this. Ideally we'd fix the kernel to do this. So I'm closing this as UPSTREAM. For now, the answer to this bug report is "Don't do it", e.g. you need to properly unmount the device before removing it. It is not a very satisfying answer but that's how things work right now.
Command failed: Device busy error means, that device is open (mounted fs). Someone must umount the fs first. If the underlying device disappears, cryptsetup luksClose should remove it without problems - just it must have open_count == 0 (see dmsetup info). If the device is reinserted, new disk is probably allocated (like sdb->sdc) so it cannot work with the original mapping pointing to sdb. Maybe there should be some handler reacting to usb remove event, which force umount and remove encrypted fs and disc. The same problem exist without crypto - just disconect disk with mounted fs. So what fails/missing here is probably force umount fs on disk which dissappeared. Hardly to imagine that this can be done in kernel space. See: (removed usb disk) # cryptsetup luksClose bad Command failed: Device busy # umount -f /mnt/tst # cryptsetup luksClose bad ok (if you reinsert disk between these steps, new device appears. but because of name and uuid conflict for existing crypt it cannot be created)