Skip to content

Instantly share code, notes, and snippets.

@BenjaminWegener
Forked from KunoiSayami/install-armhf-qemu.md
Last active May 23, 2021 12:58
Show Gist options
  • Save BenjaminWegener/4d68251068e6e1ee956f7dd1e8ef756c to your computer and use it in GitHub Desktop.
Save BenjaminWegener/4d68251068e6e1ee956f7dd1e8ef756c to your computer and use it in GitHub Desktop.

Install armhf debian system on qemu

Environment

Operation system: Raspbery Pi OS (Debian 10)

QEMU emulator version: 2+

Installation

QEMU

sudo apt install qemu-system-arm

Prepare file

Debian files

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 image

qemu-img create debian.img 4G

Configure network

Install software

sudo apt install bridge-utils uml-utilitie

Create bridge

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

Create tap device

sudo tunctl -t tap0 -u root
sudo brctl addif br0 tap0
sudo ifconfig tap0 0.0.0.0 promisc up
sudo brctl showstp br0

Enable IPv4 Forward

Edit /etc/sysctl.conf

net.ipv4.ip_forward = 1

Then apply change

sudo sysctl -p

Install Operation System

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

Note

  • 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

Bootloader Install failure

Grub install will fail, but never mind, we can continue without boot loader

After Install

Copy linux kernel to outside

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

Start system

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

Postscript

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.

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment