How to launch android emulator with my own .img partitions?

Viewed 2407

I compiled my own AOSP image and got this:

lz@vm:/mnt/android-dev-3/aosp/grapheneos-lz_experiments/out/target/product/generic_x86_64$ ls *.img 
cache.img          ramdisk.img       system.img       vendor_boot-debug.img
dtb.img            ramdisk-qemu.img  system-qemu.img  vendor_boot.img
encryptionkey.img  super_empty.img   userdata.img     vendor.img
ramdisk-debug.img  super.img         vbmeta.img       vendor-qemu.img

I then compiled my own Android emulator.

I know I dont need to specify the .img myself, the AOSP prebuilt emulator just works, but I want to for other purposes.

So I did DIR_OUT = /mnt/android-dev-3/aosp/grapheneos-lz_experiments/out/target/product/generic_x86_64

./emulator -sysdir $DIR_OUT/system -datadir $DIR_OUT/data -kernel $DIR_OUT/kernel-ranchu -ramdisk $DIR_OUT/ramdisk.img -system $DIR_OUT/system.img -data $DIR_OUT/userdata.img -cache $DIR_OUT/cache.img -vendor $DIR_OUT/vendor.img
emulator: ERROR: No AVD specified. Use '@foo' or '-avd foo' to launch a virtual device named 'foo'
emulator: WARNING: userdata partition is resized from 550 M to 800 M

emulator: WARNING: encryption is off
Segmentation fault (core dumped)

You can see that I ignored the AVD error by commenting the return

if (!avdName && !avdArch && !androidOut && !forceEngineLaunch && !queryVersion) {
    derror("No AVD specified. Use '@foo' or '-avd foo' to launch a virtual"
           " device named 'foo'\n");
    //return 1;
}

because without it I couldn t get anything to work. It could be segfaulting because of my quirk, but without it I dont see how to run with the .img myself.

Here s what the android emulator says about specifying my own .img files:

 ./emulator -help-disk-images

  The emulator needs several key image files to run appropriately.
  Their exact location depends on whether you're using the emulator
  from the Android SDK, or not (more details below).

  The minimal required image files are the following:

    kernel-qemu      the emulator-specific Linux kernel image
    ramdisk.img      the ramdisk image used to boot the system
    system.img       the *initial* system image
    vendor.img       the *initial* vendor image
    userdata.img     the *initial* data partition image

  It will also use the following writable image files:

    userdata-qemu.img  the persistent data partition image
    system-qemu.img    an *optional* persistent system image
    vendor-qemu.img    an *optional* persistent vendor image
    cache.img          an *optional* cache partition image
    sdcard.img         an *optional* SD Card partition image

    snapshots.img      an *optional* state snapshots image

  If you use a virtual device, its content directory should store
  all writable images, and read-only ones will be found from the
  corresponding platform/add-on directories. See -help-sdk-images
  for more details.

  If you are building from the Android build system, you should
  have ANDROID_PRODUCT_OUT defined in your environment, and the
  emulator shall be able to pick-up the right image files automatically.
  See -help-build-images for more details.

  If you're neither using the SDK or the Android build system, you
  can still run the emulator by explicitely providing the paths to
  *all* required disk images through a combination of the following
  options: -sysdir, -datadir, -kernel, -ramdisk, -system, -data, -cache
  -sdcard and -snapstorage.

  The actual logic being that the emulator should be able to find all
  images from the options you give it.

There s nothing saying how to overcome that error

UPDATE:

Segmentation fault is in this exact line:

https://android.googlesource.com/platform/external/qemu.git/+/refs/heads/aosp-emu-30-release/android-qemu2-glue/main.cpp#476

            sysImagePath = std::string(
                    avdInfo_getSystemImagePath(m_avd)
                            ?: avdInfo_getSystemInitImagePath(m_avd));

UPDATE:

I tried with

./emulator -sysdir $DIR_OUT/system -datadir $DIR_OUT/data -kernel /home/project/disk/aosp/grapheneos-lz_experiments/prebuilts/qemu-kernel/x86_64/5.4/kernel-qemu2 -ramdisk $DIR_OUT/ramdisk-qemu.img -system $DIR_OUT/system.img -data $DIR_OUT/userdata-qemu.img -cache $DIR_OUT/cache.img -vendor $DIR_OUT/vendor.img

(I added -qemu to some .img that had the qemu in the name)

But the problem persists the same

1 Answers

try this. https://source.android.com/setup/create/avd To build and run an AVD system image:

Download the Android source:

mkdir aosp-master; cd aosp-master
repo init -u
repo sync -j24

If you want to build other Android versions, you can find their branch names in the public Android repository. They map to Android Codenames, Tags, and Build Numbers.

Build an AVD system image. This is the same process as building an Android device system image. For example, to build a x86 32-bit AVD:

mkdir aosp-master; cd aosp-master
source ./build/envsetup.sh
lunch sdk_phone_x86
make -j32

If you prefer to build an x86 64-bit AVD, run lunch for the 64-bit target:

lunch sdk_phone_x86_64 Run the AVD system image in the Android Emulator:

emulator See the Command-line startup options for more details about running the emulator. Figure 2 shows an example of the Android Emulator running an AVD.

Related