Build Android Kernel and Run on QEMU with Minimal Environment: Step by Step
Get the Android Linux kernel named "Goldfish". Build. Get initrd or ext4 device image. Run QEMU.
Short Recipe
git clone https://android.googlesource.com/kernel/goldfish kernel/goldfish
cd ./kernel/goldfish
git checkout -b android-4.4-dev origin/android-4.4
make defconfig
make -j4
wget https://storage.googleapis.com/syzkaller/wheezy.img
qemu-system-x86_64 -m 1GB -kernel arch/x86/boot/bzImage -hda wheezy.img -append "root=/dev/sda"
Step by Step
- Get the Android Linux kernel named "Goldfish" adapted to run under emulator (see Building Kernels | Android Open Source Project):
git clone https://android.googlesource.com/kernel/goldfish kernel/goldfish
- Enter the directory. It is empty.
cd ./kernel/goldfish
- List the branches and select any of them.
git branch -a * master remotes/origin/android-4.14 remotes/origin/android-4.4 # <- Linux kernel 4.4.
- Checkout.
git checkout -b android-4.4-dev origin/android-4.4
- Build.
Result is here: arch/x86/boot/bzImage.make defconfig make -j4
- Install QEMU.
or justsudo apt install qemu
sudo apt install qemu-system-x86
- Run Android Linux kernel with initrd.
Create initrd RAM disk.
Run QEMU.mkinitramfs -o initrd
Give to QEMU some additional RAM memoryqemu-system-x86_64 -m 1GB -kernel arch/x86/boot/bzImage -initrd initrd
-m 1GB
to not get an error message like "Kernel panic - Not syncing: No working init found." - Run Android Linux kernel with ext4 image.
Download 1GB wheezy.img.
Wheezy image is a R/W image of Debian 7 with 656 MB of a free space. It is suitable for QEMU and also if you're going to runsyzkaller
further.
Run QEMU.wget https://storage.googleapis.com/syzkaller/wheezy.img
Login: root. Password: empty.qemu-system-x86_64 -m 1GB -kernel arch/x86/boot/bzImage -hda wheezy.img -append "root=/dev/sda"