Documenting Problems That Were Difficult To Find The Answer To

Backing Up Encrypted Data Partition On Android Phone

I have CyanogenMod 12.1 (Android 5.1.1) on my phone. And the data partition is encrypted. Unfortunately TWRP (recovery) cannot access this encrypted data partition – so I cannot back up my data in recovery.

Making Backup From Phone

So, when booted normally into Android, one can use adb to make a backup of the data partition.

This Stack Exchange forum post suggests executing:

$ adb root # connect as root user when running adb shell in future
$ adb pull /dev/block/dm-0 /tmp/dm0backup.img

An alternative technique might be to use the following command (though it appears to create an invalid gzip file for me):

$ adb shell "cat /dev/block/dm-0 |gzip -c" >/tmp/dm0backup.gz
$ adb shell "gzip -c /dev/block/dm-0" >/tmp/dm0backup.gz

Pushing Backup Back To Phone

$ adb root # connect as root user when running adb shell in future
$ adb push /tmp/dm0backup.img /dev/block/dm-0

Pull the battery out (don’t shut down normally and give the system a chance to write all over your newly restored backup), put it back in, and restart the phone.

Mounting Android Data Partition Image In Linux

You can mount your backed up partition in Linux using the command (thanks to this article):

# make a mount point
sudo mkdir /mnt/android

# mount dirty partition
#   noload - don't load journal on mounting
#   noexec - do not allow direct execution of binaries on mount
#   ro     - read only
sudo mount -o ro,noexec,noload -t ext4 /tmp/dm0backup.img /mnt/android

# look into mounted partition
ls -al /mnt/android

# unmount when you're finished
sudo umount /mnt/android

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: