Jan 23

AOSP: emulator: don't copy the system image

The Android emulator seems to insist on copying the system.img file somewhere else (into /tmp/emulator-$USER on my system) before starting up. This is pretty annoying because the system.img file is 550 megabytes and it takes a while to copy.

The code doesn't quite know what it wants: there is the concept of an “initial system image” and a “rw system image”. If you create a file called system-qemu.img in the same directory as your system.img (i.e. in out/target/product/generic-whatever/) (or do what I did, and ln -s system.img system-qemu.img) then one part of the emulator will be happy to proceed without an initial image, using system-qemu.img only… but the Android initialisation portion will complain that there is no initial system image!

I guess all of this makes sense if you're supporting AVDs and don't want the system image corrupted, but if you're actually working on the system image it's a bit of a time sink.

You don’t need an initial system image. If you screw up the rw image you can fix it using make snod. To stop the complaints:

aosp/external/qemu$ git diff
diff --git a/vl-android.c b/vl-android.c
index 4b0c991..3b35a63 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -3601,7 +3601,7 @@ int main(int argc, char **argv, char **envp)
         } else {
-            PANIC("Missing initial system image path!");
+            VERBOSE_PRINT(init, "No initial system image specified. Ho hum");
         if (android_hw->hw_useext4) {
             /* Using a nand device to approximate a block device until full

I haven't tested this for very long, so maybe it will break everything. As a precaution, you might want to remount as ro before quitting the emulator if you make any changes to /system (i.e. if you have previously done an adb remount): adb shell mount -o remount,ro /system.