Cyngn, OnePlus, Micromax – The Legal Battle

Recently, a battle has been waging in India over the rights to distribute the commercial … more

Lean Mean Battery Power Saving App Review

We talk a lot about battery topics here at XDA TV. We talk about everything from Power Banks to USB … more

Android 5.1 Possibly Coming February 2015

Google released Android 5.0 just over a month ago, and since then Lollipop has been trying to … more

Double Tap to Wake on the Nexus 6 Without Root

A few weeks ago, we featured an app which allowed the Nexus 6 to regain the double tap to wake … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Mounting userdata partition on PC

OP thirtythreeforty

25th June 2014, 12:57 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Apr 2014
Hello all,
Last night I ran the following command (with the phone in recovery and everything unmounted) to back up my Nexus 5's userdata partition to my computer:

Code:
adb pull /dev/block/platform/msm_sdcc.1/by-name/userdata
My phone is encrypted, so I use "cryptsetup --type=plain open" to obtain a plaintext version on /dev/mapper/my-nexus-backup. But I cannot mount the mapped device using "mount"! It complains that iit can't find the filesystem.

So, how would I mount such an image? Or, even better, what's the best way to dd it back to the userdata partition on the device?

And yes, next time I will just use a Nandroid, even if it means having to erase things to make room.
25th June 2014, 01:10 AM   |  #2  
jd1639's Avatar
Recognized Contributor
Minnetonka, MN
Thanks Meter: 3,905
 
11,196 posts
Join Date:Joined: Sep 2012
See if @rootSU or @bitdomo can help. They're gurus at this type of stuff

Sent from my Nexus 5 using XDA Free mobile app
25th June 2014, 07:47 AM   |  #3  
rootSU's Avatar
Senior Member
Flag Oxenhope, West Yorkshire, UK
Thanks Meter: 13,797
 
24,973 posts
Join Date:Joined: Aug 2010
More
Sorry, where are you mounting exactly? Are you trying to mount an image on a Linux box after the pull?

If not can you please share the full step of commands and what you expect to happen please?

Sent from my Nexus 5 using Tapatalk
25th June 2014, 08:09 AM   |  #4  
OP Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Apr 2014
Thumbs up
Quote:
Originally Posted by rootSU

Sorry, where are you mounting exactly? Are you trying to mount an image on a Linux box after the pull?

If not can you please share the full step of commands and what you expect to happen please?

Sent from my Nexus 5 using Tapatalk

Hey rootSU. I pulled the image from my phone, decrypted it, and tried to mount it:

Code:
$ adb pull /dev/block/platform/msm_sdcc.1/by-name/userdata
$ su
# losetup /dev/loop1 userdata
# cryptsetup open --type plain /dev/loop1 nexus
Enter passphrase: 
# mount /dev/mapper/nexus /mnt/tmp
mount: wrong fs type, bad option, bad superblock on /dev/mapper/nexus,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
I'm not sure why that doesn't work. It's just ext4, right? I'd still find it instructive to figure out how to mount it; hopefully you can shed some light?

As far as getting the image back on the device's partition, I was a bit stuck, because there's obviously no room on the device to copy it to. I finally figured out a method involving netcat. Essentially I forwarded a local TCP port to my device (in recovery) using adb, then used netcat to feed dd the image.

Code:
$ adb forward tcp:4444 tcp:4444
$ adb shell
# nc -l -p 4444 -e dd of=/dev/block/platform/msm_sdcc.1/by-name/userdata
This will hang as it waits for an inbound connection. From a second shell:

Code:
$ dd if=userdata | nc localhost 4444
My 28GiB image took around 6 hours (!) to complete. Nandroid is probably the way to go.
25th June 2014, 08:15 AM   |  #5  
rootSU's Avatar
Senior Member
Flag Oxenhope, West Yorkshire, UK
Thanks Meter: 13,797
 
24,973 posts
Join Date:Joined: Aug 2010
More
Nandroid won't backup sdcard but you can use foldersync to back that up.

Yes it is just ext4

I've never done anything like this before with an encrypted device but my assumption was if you adb pull a file, it would decrypt it on the fly.. Does it not?? If it does, I'd just dd it to an img.

Sent from my Nexus 5 using Tapatalk
25th June 2014, 08:27 AM   |  #6  
OP Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Apr 2014
Quote:
Originally Posted by rootSU

Nandroid won't backup sdcard but you can use foldersync to back that up.

Yes it is just ext4

I've never done anything like this before with an encrypted device but my assumption was if you adb pull a file, it would decrypt it on the fly.. Does it not?? If it does, I'd just dd it to an img.

Sent from my Nexus 5 using Tapatalk

Nope, in this case, userdata is the encrypted *device*; in any case TWRP knows nothing about the encryption. The pull was identical to using dd to copy the file. Of course, if you wanted to decrypt your device without wiping data, you could probably have TWRP decrypt the data partition, then dd or pull the resulting /dev/block/dm-0 file (which is equivalent to my /dev/mapper/nexus file I created). Haven't tried it though; ain't nobody got time for that.

I wonder why it wouldn't mount. Oh well. I'm just happy that my device is the way it was yesterday.
25th June 2014, 08:31 AM   |  #7  
rootSU's Avatar
Senior Member
Flag Oxenhope, West Yorkshire, UK
Thanks Meter: 13,797
 
24,973 posts
Join Date:Joined: Aug 2010
More
I'd love to have a play with this but I just don't have the time to start encrypting and decrypting stuff

Out of interest what about adb whilst in android?

Sent from my Nexus 5 using Tapatalk
25th June 2014, 08:57 AM   |  #8  
OP Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Apr 2014
Quote:
Originally Posted by rootSU

I'd love to have a play with this but I just don't have the time to start encrypting and decrypting stuff

Out of interest what about adb whilst in android?

Sent from my Nexus 5 using Tapatalk

You would have the exact same results, as the /dev/* files are the physical disks represented as a file. The crypto drivers read/write this block device file to present a decrypted /dev/block/dm-0 device. Then the kernel mounts dm-0 as an ext4 filesystem on /data. All the files I mentioned are pullable with adb, assuming you have sufficient privileges. You don't need fancy tools to read/write them, which is why the netcat hack worked. Thus is the power of Unix!

You can screw around with it if you want in regular desktop Linux with a "device" you make from a bunch of 0s. Do:

Code:
# dd if=/dev/zero of=disk.image count=100000
# losetup /dev/loop0 disk.image
Now you can do "mkfs.ext4 /dev/loop0" and "mount ..." or whatever, and the data will be written to the "device" disk.image.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes