Bug 511409 - Cannot remount encrypted USB disk after unclean ejection.
Summary: Cannot remount encrypted USB disk after unclean ejection.
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: DeviceKit-disks
Version: rawhide
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: David Zeuthen
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-07-15 01:09 UTC by Saikat Guha
Modified: 2009-10-02 17:56 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2009-10-02 17:17:00 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Saikat Guha 2009-07-15 01:09:55 UTC
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:

Comment 1 Saikat Guha 2009-09-04 20:54:05 UTC
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

Comment 2 David Zeuthen 2009-10-02 17:17:00 UTC
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.

Comment 3 Milan Broz 2009-10-02 17:56:18 UTC
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)


Note You need to log in before you can comment on or make changes to this bug.