[Android Software/Hacking General [Developers Only]] rkull:
Hi newbit!

Thanks for some great tutorials, unfortunately for me I can't get it to work properly. Hopefully, you're able to help me :)

I'm trying to build and install a custom kernel in an AOSP built emulator. I've been trying out the "official" guide at https://source.android.com/setup/build/building-kernels#customize-build, your rootAVD guide for Android 11 and the "classic" guide for Android 11. All of the guides give me the same result:

[ 0.610588] Run /init as init process
[ 0.611985] init: init first stage started!
[ 0.612930] init: Loading module /lib/modules/dummy-cpufreq.ko with args ""
[ 0.613579] dummy_cpufreq: disagrees about version of symbol module_layout
[ 0.614170] init: Failed to insmod '/lib/modules/dummy-cpufreq.ko' with args ''
[ 0.614793] init: LoadWithAliases was unable to load dummy_cpufreq
[ 0.615366] init: [libfs_mgr]ReadFstabFromDt(): failed to read fstab from dt
[ 0.616164] init: Using Android DT directory /proc/device-tree/firmware/android/
[ 0.629196] init: bool android::init::BlockDevInitializer::InitDevices(std::set<std::string>): partition(s) not found in /sys, waiting for their uevent(s): metadata, super, vbmeta

After that, the emulator hangs for a short while and the it reboots to try again..

In your "classic" guide, you're warning about this:

When I checked the version of my running emulator i got this:

Linux version 5.4.50-01145-g056684c0d252-ab6656030 (android-build@abfarm-01106) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Mon Jul 6 18:09:10 UTC 2020

So I used xconfig to add the "-g056684c0d252" string and also made sure to use the r383902 clang toolchain to compile, but no luck.. After compilation and running with the new kernel, I get this version print:

[ 0.000000] Linux version 5.4.162-g056684c0d252-android11-2-00102-gfe0ed45e42fe-dirty (build-user@build-host) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Fri Nov 26 10:38:38 UTC 2021

Can you see anything obvious from that?

When I tried with rootAVD, I'm getting this output when running the script:

./rootAVD.sh /aosp/out/target/product/myproduct/ramdisk.img InstallKernelModules
[!] and we are NOT in an emulator shell
[*] Set Directorys
[-] Test if ADB SHELL is working
[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
[-] Magisk installer Zip exists already
[*] Cleaning up the ADB working space
[*] Creating the ADB working space
[*] Push Magisk.zip into /data/data/com.android.shell/Magisk
[-] ./Magisk.zip: 1 file pushed, 0 skipped. 254.4 MB/s (6874374 bytes in 0.026s)
[*] create Backup File of ramdisk.img
[*] Push ramdisk.img into /data/data/com.android.shell/Magisk
[-] /ramdisk.img: 1 file pushed, 0 skipped. 1006.6 MB/s (903723 bytes in 0.001s)
[*] Push initramfs.img into /data/data/com.android.shell/Magisk
[-] ./initramfs.img: 1 file pushed, 0 skipped. 299.9 MB/s (2256062 bytes in 0.007s)
[*] Push rootAVD.sh into /data/data/com.android.shell/Magisk
[-] rootAVD.sh: 1 file pushed, 0 skipped. 243.4 MB/s (7826127 bytes in 0.031s)
[-] run the actually Boot/Ramdisk/Kernel Image Patch Script
[*] from Magisk by topjohnwu and modded by NewBit XDA
[!] We are in an emulator shell
[-] Api Level Arch Detect
[-] Device Platform: x64
[-] ARCH32 x86
[-] Device SDK API: 30
[-] First API Level: 28
[-] Switch to the location of the script file
[*] Extracting busybox and Magisk.zip ...
[-] Checking AVDs Internet connection...
[!] AVD is offline
[*] Re-Run rootAVD in Magisk Busybox STANDALONE (D)ASH
[!] We are in an emulator shell
[-] We are now in Magisk Busybox STANDALONE (D)ASH
[*] rootAVD with Magisk '23.0' Installer
[-] Get Flags
[*] System-as-root, keep dm/avb-verity
[-] Encrypted data, keep forceencrypt
[*] RECOVERYMODE=false
[-] KEEPVERITY=true
[*] KEEPFORCEENCRYPT=true
[*] No 64-Bit Binarys found, please consider Magisk Alpha
[-] copy all x86 files from /data/data/com.android.shell/Magisk/lib/x86 to /data/data/com.android.shell/Magisk
[*] Detecting ramdisk.img compression
[!] Ramdisk.img uses gzip compression
[-] taken from shakalaca's MagiskOnEmulator/process.sh
[*] executing ramdisk splitting / extraction / repacking
[-] API level greater then 30
[*] Check if we need to repack ramdisk before patching ..
[*] After decompressing ramdisk.img, magiskboot will work
Detected format: [gzip]
[-] Test patch status and do restore
[-] Checking ramdisk status
[-] STATUS=0
[-] Stock boot image detected
[-] Patching ramdisk
[*] adding overlay.d/sbin folders to ramdisk
Loading cpio: [ramdisk.cpio]
Create directory [overlay.d] (0750)
Create directory [overlay.d/sbin] (0750)
Dump cpio: [ramdisk.cpio]
[!] PATCHFSTAB=false
[!] Skipping fstab.ranchu patch with /dev/block/sda
[?] If you want fstab.ranchu patched, Call rootAVD with PATCHFSTAB
[!] AddRCscripts=false
[!] Skip adding *.rc scripts into ramdisk.img/sbin/*.rc
[?] If you want *.rc scripts added into ramdisk.img/sbin/*.rc, Call rootAVD with AddRCscripts
[!] patching the ramdisk with Magisk Init
Loading cpio: [ramdisk.cpio]
Add entry [init] (0750)
Add entry [overlay.d/sbin/magisk32.xz] (0644)
Add entry [overlay.d/sbin/magisk64.xz] (0644)
Patch with flag KEEPVERITY=[true] KEEPFORCEENCRYPT=[true]
Loading cpio: [ramdisk.cpio.orig]
Backup mismatch entry: [init] -> [.backup/init]
Record new entry: [overlay.d] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/magisk32.xz] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/magisk64.xz] -> [.backup/.rmlist]
Create directory [.backup] (0000)
Add entry [.backup/.magisk] (0000)
Dump cpio: [ramdisk.cpio]
[*] repacking back to ramdisk.img format
[!] Rename Magisk.zip to Magisk.apk
[*] Pull ramdiskpatched4AVD.img into ramdisk.img
[-] /data/data/com.android.shell/Magisk/ramdiskpatched4AVD.img: 1 file pulled, 0 skipped. 294.3 MB/s (1270228 bytes in 0.004s)
[*] Pull Magisk.apk into
[-] /data/data/com.android.shell/Magisk/Magisk.apk: 1 file pulled, 0 skipped. 358.8 MB/s (6342346 bytes in 0.017s)
[*] create Backup File of kernel-ranchu
[*] Copy ./bzImage (Kernel) into kernel-ranchu
[-] Clean up the ADB working space
[-] Install all APKs placed in the Apps folder
[*] Trying to install Apps/Magisk.apk
[*] Performing Streamed Install
[*] Success
[-] Shut-Down & Reboot (Cold Boot Now) the AVD and see if it worked
[-] Root and Su with Magisk for Android Studio AVDs
[-] Modded by NewBit XDA - Jan. 2021
[!] Huge Credits and big Thanks to topjohnwu, shakalaca and vvb2060
[-] Trying to shut down the AVD
[!] If the AVD doesn't shut down, try it manually!

Which is not the same as the one you're showing in the rootAVD guide. Is it anything I'm doing incorrect here or has the prints just changed?

Would be really awesome if you're able to help in any way :) let me know if you need more info!