Rescue LUKS encrypted partition: Error unlocking device

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Rescue LUKS encrypted partition: Error unlocking device

Post by ^rooker »

[PROBLEM]
Playing around with encrypted USB sticks, I just ran into a problem with a stick that was previously reported to have "unrecovered read error":
[258363.812786] end_request: critical target error, dev sde, sector 0
[258363.863612] sd 10:0:0:2: [sde] Unhandled sense code
[258363.863617] sd 10:0:0:2: [sde] Result: hostbyte=invalid driverbyte=DRIVER_SENSE
[258363.863621] sd 10:0:0:2: [sde] Sense Key : Medium Error [current]
[258363.863625] sd 10:0:0:2: [sde] Add. Sense: Unrecovered read error
After some unplugging/replugging the stick, it's encrypted partition finally showed up again. Unfortunately, when trying to unlock it, you get the following error:
Error unlocking device: cryptsetup exited with exit code 1: device-mapper: reload ioctl failed: Invalid argument.
dmesg | tail also has something to say:

Code: Select all

[260836.603738] device-mapper: table: 252:0: crypt: Device lookup failed
[260836.603743] device-mapper: ioctl: error adding target to table

[SOLUTION]
1) Draw a "dd" image:

Code: Select all

$ sudo dd if=/dev/sdg1 of=luks_image.bin bs=1024k conv=noerror,sync
Thanks to the article "Backup And Restore Files To/From A LUKS Encrypted Partition Image File", I also figured out how to access and mount this image file instead of the usb-stick device:

2) Create a loopback device:

Code: Select all

$ sudo losetup /dev/loop1 luks_image.bin
3) Mount the luks_image file:
Actually, the encrypted partition should already show up in your OS' file browser. On XFCE for example, you can mount the luks_image now by opening the encrypted partition in Thunar.

But of course, you can also do it the good old experts' way:

Code: Select all

$ sudo mount /dev/loop1 /mnt/luks_partition
Voila.

Links:
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply