Wednesday, April 12, 2017

backup - Mount Android encrypted data partition on PC


My Nexus 4 screen met a tragic end due to violent contact with flooring tiles. Everything works except the touchscreen (which displays fine but does not react to touch any more).


I would like to get a full copy of my data partition, but my device uses Full Disk Encryption, with a lock pattern. I can easily get image files of my partitions from CWM recovery through adb:


adb pull /dev/block/mmcblk0p23 ./userdata.img

which gives me a nice 6GB file, but mounting this image is another story since it is encrypted. My PC uses XUbuntu (I also have Windows at hand if necessary, but I guess a linux system is more useful here). My phone is rooted.


I know my unlock pattern of course, so there should be some way to mount/read my userdata.img file. Any pointers ?



Thanks !



Answer



Apparently there is no tool on PC to decrypt Android's encryption at the moment, but the TWRP recovery can be used on the device to decrypt everything... Even with a broken touchscreen, as long as your device is supported by TWRP recovery:



  • Download the TWRP image (2.8.7 worked for me)

  • Boot into fastboot (power + vol. down on Nexus 4)


  • Start the recovery, from your PC:


    fastboot boot twrp-2.8.7.0-mako.img





  • Once you are in the recovery, you can decrypt your data from the command line:


    adb shell twrp decrypt yourpassword




where yourpassword is your encryption password. In case of schema, translate it to numbers:


1 2 3
4 5 6
7 8 9


if you go through the same point twice, it is ignored after the first time.


Then it will tell you that your decrypted data is available in a block device, I think this was /dev/block/dm-0 for me (not sure). You can back it up to your PC with:


adb pull /dev/block/dm-0 ./decrypted-data.img

And finally, mount the image as ext4 on your Linux PC ! (or use some program that can read ext4 partitions on Windows).


HUGE thanks to the TWRP folks on IRC who told me about the twrp decrypt command !


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...