I'm trying to emulate a Raspberry Pi with the Raspian OS using QEMU. I've tried several approaches described on the internet but without any success.
I figured out that I need to patch a Linux Kernel fitting the desired OS. In my case I chose Rasbian Lite with Kernel 4.4:
wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2016-05-31/2016-05-27-raspbian-jessie-lite.zip
unzip 2016-05-27-raspbian-jessie-lite.zip
rm 2016-05-27-raspbian-jessie-lite.zip
Next I load a Kernel from https://www.kernel.org/:
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.16.tar.gz
tar -xzf linux-4.4.16.tar.gz
rm linux-4.4.16.tar.gz
Now cross compiling the Kernel:
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
cd linux-4.4.16
make vexpress_defconfig
make all
cd ..
Now I can copy the boot image, that is a compressed kernel image that auto-extracts in RAM, to my workspace:
cp linux-4.4.16/arch/arm/boot/zImage zImage
and run QEMU
qemu-system-arm -kernel zImage -M vexpress-a9 -m 1024 -cpu cortex-a9 -no-reboot -serial stdio -hda 016-05-27-raspbian-jessie-lite.img -append "root=/dev/sda2 rootfstype=ext4"
But all I see is a black filled QEMU-window. :(
I think that the problem is to get the right Kernel. Copying some of the Kernels from the Internet never led to success because they are not fit for the OS.
How can I build/patch a Kernel fitting the OS (without downloading an existing one) and how to run QEMU properly?
Thanks in advance
Alex
2nd approach
I load a kernel-qemu
from here https://www.dropbox.com/s/g8u93xblz1v1ly0/kernel-qemu?dl=0 and run QEMU with it:
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2" -hda 2016-05-27-raspbian-jessie-lite.img
This brings me the following output:
And it makes sense to me because the Kernel is 3.10.25 and older than Raspbian Jessie with Kernel 4.4.16.
With the qemu-kernel from https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/master/kernel-qemu-4.4.12-jessie
qemu-system-arm -kernel kernel-qemu-4.4.12-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2016-05-27-raspbian-jessie-lite.img
I got this similar result:
A new try with a new kernel-qemu 4.4.16:
Copy build-kernel-qemu from https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/master/tools and add the following line to checkout the version for Kernel 4.4.16:
git checkout b05965f284db3e086022f4e318e46cb5bffb1376
Run build-kernel-qemu
to build the kernel
sh build-kernel-qemu
Run QEMU
qemu-system-arm -kernel kernel-qemu -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2016-05-27-raspbian-jessie-lite.img
The result:
See Question&Answers more detail:
os