Operation system: Ubuntu 16.04.6 LTS
QEMU emulator version: 2.5.0
apt install qemu-system-arm
We need netinst initrd
and vmlinuz
, can download from here
wget http://ftp.debian.org/debian/dists/Debian10.2/main/installer-armhf/current/images/netboot/initrd.gz
wget http://ftp.debian.org/debian/dists/Debian10.2/main/installer-armhf/current/images/netboot/vmlinuz
Also, we can download netinst iso file
wget https://cdimage.debian.org/debian-cd/current/armhf/iso-cd/debian-10.2.0-armhf-netinst.iso
qemu-image create debian.img 4G
apt-get install bridge-utils install uml-utilities
Replace ens32 as your network card name
IF_NAME=ens32
ifconfig $IF_NAME down
brctl addbr br0
brctl addif br0 $IF_NAME
brctl stp br0 off
brctl setfd br0 1
brctl sethello br0 1
ifconfig br0 0.0.0.0 promisc up
ifconfig $IF_NAME 0.0.0.0 promisc up
dhclient br0
brctl show br0
brctl showstp br0
tunctl -t tap0 -u root
brctl addif br0 tap0
ifconfig tap0 0.0.0.0 promisc up
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-10.2.0-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.