F.X. F.X. - 8 days ago 4
Android Question

Forcing the Android emulator to store changes to /system

I know this is a recurrent question when working with the Android emulator, but is there a way to force the emulator to accept persistent changes to

/system
?

The emulator is based on QEMU, so it should be possible, in theory, to force the
system
image to behave the same way
userdata
(for instance) does, but I'm not familiar with how QEMU handles things. Any pointers?

Answer

Yury's answer is the common one, but if you want to be able to script things (which is what I want in the end), you need to be able to find the emulator image in the /tmp directory.

I discovered that you can override QEMU's behavior. This is a bit hackish, but it works, so I ended up doing this :

  1. Copy system.img from the platform directory to your AVD directory.
  2. Convert the amount of space you need to hex. For instance, if you need 500M, this is 0x1f400000.
  3. Run the emulator in read-write mode :

    emulator -avd Galaxy_Nexus -qemu -nand system,size=0x1f400000,file=/home/fx/.android/avd/Galaxy_Nexus/system.img
    

    (If you put the emulator in verbose mode, you'll notice that it will, by default, use initfile= instead of just file=)

  4. Make your changes, they are immediately saved to the local system.img

  5. Now you can just start the emulator with emulator -avd Galaxy_Nexus, and it'll use your changes

Update: If scripting, QEMU does not sync changes immediately to the image, so if you're rebooting immediately after changing something, chances are you will lose data. I'm looking for a way around this...

Next update: Use adb -e emu kill to stop the emulator. reboot will just do bad things.