3

I am able to successfully unlock a corrupted Android encrypted SD card on desktop Linux using instructions from the Internet.

# dmsetup create crypt5 --table "0 `blockdev --getsize /dev/mmcblk0p2` crypt aes-cbc-essiv:sha256 HEXIDECIMALPASSPHRASEHERE 0 /dev/mmcblk0p2 0"

Recovery directly from the SD card using photorec was taking an unacceptable amount of time. As a compromise, I decided to start by making a disk image file from the encrypted partition so I can verify the integrity of the SD card an reuse it then recover the data from the image file later.

# dd if=/dev/mmcblk0p2 of=/home/crash/Documents/128gb.img iflag=direct oflag=dsync

Now the question is, "how do I unlock the disk image file?" Knowing that the disk image file is supposed to be identical to the original partition, I tried tweaking the original command to plug in the size of the block device and the location of disk image file.

# blockdev --getsize /dev/mmcblk0p2

Result:

250048479

Plug that in:

# dmsetup create crypt6 --table "0 250048479 crypt aes-cbc-essiv:sha256 HEXIDECIMALPASSPHRASEHERE 0 /home/crash/Documents/128gb.img 0"

This fails with the following error:

device-mapper: reload ioctl on crypt6 failed: Invalid argument
Command failed

I don't see what went wrong. I would like to confirm that this disk image can be unlocked before I move on to wiping and testing the SD card.

1

I would imagine that you need to convert your image file to a block device before dmcrypt can handle it. Here we use the loop device, which allows us to present a block interface to the named file:

# Create a loop device and capture its name
lodev=$(losetup --show --find /home/crash/Documents/128gb.img)
echo "Using device $lodev for the image" >&2

# Map the crypto layer on to the loop block device
dmsetup create crypt6 --table "0 250048479 crypt aes-cbc-essiv:sha256 HEXIDECIMALPASSPHRASEHERE 0 $lodev 0"

...
# Delete the loop device when we have finished with it
losetup -d "$lodev"

Actually, using this configuration you could replace your constant 250048479 with a call back to blockdev (notice I'm also using the more modern $(...) rather than backticks `...`):

dmsetup create crypt6 --table "0 $(blockdev --getsize "$lodev") crypt aes-cbc-essiv:sha256 HEXIDECIMALPASSPHRASEHERE 0 $lodev 0"
  • dmsetup create gives me device-mapper: reload ioctl on crypt6 failed: Das Argument ist ungültig Command failed - any idea how to solve that? – Qohelet Sep 7 '18 at 10:33
  • @Qohelet you'd first need to check that the value of $lodev is correct, and that blockdev --getsize "$lodev" returns something sensble. – roaima Sep 7 '18 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.