Operation system: Raspbery Pi OS (Debian 10)
QEMU emulator version: 2+
sudo apt install qemu-system-arm
We need netinst initrd
and vmlinuz
, can download from here
wget http://ftp.debian.org/debian/dists/stable/main/installer-armhf/current/images/netboot/initrd.gz
wget http://ftp.debian.org/debian/dists/stable/main/installer-armhf/current/images/netboot/vmlinuz
Also, we can download netinst iso file, please look which is current
wget https://cdimage.debian.org/debian-cd/current/armhf/iso-cd/debian-armhf-netinst.iso debian-netinst.iso
qemu-img create debian.img 4G
sudo apt install bridge-utils uml-utilitie
Replace eth0 as your network card name
sudo ifconfig eth0 down
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl stp br0 off
sudo brctl setfd br0 1
sudo brctl sethello br0 1
sudo ifconfig br0 0.0.0.0 promisc up
sudo ifconfig eth0 0.0.0.0 promisc up
sudo dhclient br0
sudo brctl show br0
sudo brctl showstp br0
sudo tunctl -t tap0 -u root
sudo brctl addif br0 tap0
sudo ifconfig tap0 0.0.0.0 promisc up
sudo brctl showstp br0
Edit /etc/sysctl.conf
net.ipv4.ip_forward = 1
Then apply change
sudo sysctl -p
qemu-system-arm -M virt -kernel ./vmlinuz -initrd ./initrd.gz -cdrom debian-armhf-netinst.iso -hda debian.img -nographic -m 1024M -append "console=ttyAMA0" -netdev tap,id=tap0 -device e1000,netdev=tap0
- Set memory to 1024M to prevert unzip initrd.gz fail
- Set console to ttyAMA0 to prevert show install interface
- Specify network device to prevert network device not found
- If mirror is error, please check your network connection
- This install will take long time to finish
Grub install will fail, but never mind, we can continue without boot loader
We should copied vmlinuz
and initrd
from disk image.
First, check disk image
sudo fdisk -l -u debian.img
This image rootfs has 2048 unit offset, so we should fix this offset then mount it.
sudo mount -o loop,offset=$((2048 * 512)) debian.img /mnt
Then, copy file from /mnt
mkdir boot
cp /mnt/* boot/ -rv
Remember append root dev to kernel parameter
qemu-system-arm -M virt -kernel ./boot/vmlinuz -initrd ./boot/initrd.img -hda debian.img -nographic -m 1024M -append "root=/dev/vda2 console=ttyAMA0" -netdev tap,id=tap0 -device e1000,netdev=tap0 -redir tcp:2222::22
I found this qemu while stuck at sync clock if cpu count is more then 1, so I decide use another way to compile armhf program.