2

I'm trying to mount the userdata-qemu.img.qcow2 file created by the Android emulator. The following procedure does not work:

sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2

First command runs well, but running

sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2

results in this output:

Fehler: /dev/nbd0: unbekannte Partitionstabelle
Modell: Unbekannt (unknown)                                               
Festplatte  /dev/nbd0:  3146MB
Sektorgröße (logisch/physisch): 512B/512B
Partitionstabelle: unknown
Disk-Flags: 

Basically it cannot recognize a partition table in the image file. You may wonder what's the output of

fdisk /dev/nbd0 -l

so here it is:

Medium /dev/nbd0: 3 GiB, 3145728000 Bytes, 6144000 Sektoren
Einheiten: sectors von 1 * 512 = 512 Bytes
Sektorengröße (logisch/physisch): 512 Bytes / 512 Bytes
I/O Größe (minimal/optimal): 512 Bytes / 512 Bytes

As you could expect already, mounting fails of course, since no partitions can be recognized if the partition table itself cannot be recognized either. Thanks for any help!

Edit: I've just found out that the problem must have to do with Android's userdata encryption. As I've never changed any password the encryption password of the emulator's userdata partition would have to be the default one "default_password". How can I decrypt the image to be able to mount it?

Nico Feulner
  • 185
  • 3
  • 14

1 Answers1

2

You can mount userdata-qemu.img.qcow2 using the following procedure

  1. convert the image to a raw image

    qemu-img convert -O raw userdata-qemu.img.qcow2 udata-raw.img

  2. use losetup to setup a loopback device for mounting

    sudo losetup -f -P userdata.img

  3. use losetup -l to see what device was setup

    losetup -l
    NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                                DIO
    /dev/loop0         0      0         0  0 /path/to/userdata.img   0
    
  4. mount the drive

    mkdir /tmp/mnt
    sudo mount /dev/loop0 /tmp/mnt
    

Then ls /tmp/mnt/ gives

app  benchmarktest  benchmarktest64  lost+found  misc  nativetest nativetest64
  • Awesome, I'll try it later when I'm at home. There has just come something to my mind: Android encrypts the data partition by default, I assume the emulator does the same, doesn't it? If that's the case, I'd somehow need to decrypt the data partition to be able to mount it. Does someone have an idea how to do that? As I didn't use screen security in the emulator, the password is still the default one, persumeably. – Nico Feulner Mar 05 '18 at 09:47
  • 2
    I've just tested the procedure. It seems like the same happens again. Error message: "mount: wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error". I'm pretty sure now that it's due to the encryption. I've never set a password in the emulator so the encryption password should still be "default_password". However, I don't know how the encryption works. I only know that Team Win Recovery Project can decrypt the data partition on phones. How can I apply this procedure to my userdata image? Thank you so much! – Nico Feulner Mar 05 '18 at 20:21