Skip to content

Instantly share code, notes, and snippets.

@tai271828
Forked from KunoiSayami/install-armhf-qemu.md
Created April 3, 2024 21:24
Show Gist options
  • Save tai271828/95a8aa0a3727d6ca18d357b572c365eb to your computer and use it in GitHub Desktop.
Save tai271828/95a8aa0a3727d6ca18d357b572c365eb to your computer and use it in GitHub Desktop.

Install armhf debian system on qemu

Environment

Operation system: Ubuntu 16.04.6 LTS

QEMU emulator version: 2.5.0

Installation

QEMU

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/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

qemu-image create debian.img 4G

Configure network

Install software

apt-get install bridge-utils install uml-utilities

Create bridge

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

Create tap device

tunctl -t tap0 -u root
brctl addif br0 tap0
ifconfig tap0 0.0.0.0 promisc up
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-10.2.0-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