Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,806,018 Members 45,004 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Mounting userdata partition on PC

Tip us?
 
thirtythreeforty
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 8
Join Date: Apr 2014
Default [Q] Mounting userdata partition on PC

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.
 
jd1639
Old
#2  
jd1639's Avatar
Recognized Contributor
Thanks Meter 3,333
Posts: 9,780
Join Date: Sep 2012
Location: Minnetonka, MN
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
 
rootSU
Old
#3  
rootSU's Avatar
Senior Member
Thanks Meter 11,335
Posts: 22,380
Join Date: Aug 2010
Location: Oxenhope, West Yorkshire, UK
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
Want to root/unroot? All important guides and info threads are contained within the "Sticky Roll-up" thread in General. Click the link below to get there!

**Sticky Roll-up: All Guides snd Info Threads linked here**



Philz Touch Recovery with passkey secure lock

I do NOT reply to support queries over PM.
 
thirtythreeforty
Old
#4  
Junior Member - OP
Thanks Meter 0
Posts: 8
Join Date: Apr 2014
Quote:
Originally Posted by rootSU View Post
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.
 
rootSU
Old
#5  
rootSU's Avatar
Senior Member
Thanks Meter 11,335
Posts: 22,380
Join Date: Aug 2010
Location: Oxenhope, West Yorkshire, UK
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
Want to root/unroot? All important guides and info threads are contained within the "Sticky Roll-up" thread in General. Click the link below to get there!

**Sticky Roll-up: All Guides snd Info Threads linked here**



Philz Touch Recovery with passkey secure lock

I do NOT reply to support queries over PM.
 
thirtythreeforty
Old
#6  
Junior Member - OP
Thanks Meter 0
Posts: 8
Join Date: Apr 2014
Quote:
Originally Posted by rootSU View Post
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.
 
rootSU
Old
#7  
rootSU's Avatar
Senior Member
Thanks Meter 11,335
Posts: 22,380
Join Date: Aug 2010
Location: Oxenhope, West Yorkshire, UK
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
Want to root/unroot? All important guides and info threads are contained within the "Sticky Roll-up" thread in General. Click the link below to get there!

**Sticky Roll-up: All Guides snd Info Threads linked here**



Philz Touch Recovery with passkey secure lock

I do NOT reply to support queries over PM.
 
thirtythreeforty
Old
#8  
Junior Member - OP
Thanks Meter 0
Posts: 8
Join Date: Apr 2014
Quote:
Originally Posted by rootSU View Post
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.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes