This is an old revision of the document!
Table of Contents
Debian Buster for RaspberryPi 3 with Qemu in 64bits (aarch64)
This guide explains how to get Debian Buster using a RaspberryPi 3 image running with Qemu. These images are 64bits (aarch64), therefore, taking advantage of RPi 3 and 4 newest hardware.
This configuration is useful in order to use a big PC to precompile and afterwards export the binaries to the slower/real Raspberry Pi.
This will be used to get ROS2 installed.
Preparing your host system
- Install aarch64 qemu and other dependencies
sudo apt-get install qemu-system-arm xz-utils
- Create a directory for your emulated system
mkdir ~/db_rpi3_qemu cd ~/db_rpi3_qemu
- Download the raspberry pi image (Browse for newer images if possible, if you select the raspberry pi 3 image, you'll get a 64bit system):
wget https://people.debian.org/~gwolf/raspberrypi/20190628/20190628_raspberry-pi-3_buster_PREVIEW.img.xz
- Qemu requires the kernel and initrd image as separate files. First we decompress the image:
xz --decompress 20190628_raspberry-pi-3_buster_PREVIEW.img.xz
- Now we have to mount the first (/boot) partition of this image to extract the kernel and initrd files. But we need to determine the file byte offset for the first partition in order to mount it. We use fdisk for this:
sudo fdisk -l 20190628_raspberry-pi-3_buster_PREVIEW.img
- It should print something like this:
Disk 20190628_raspberry-pi-3_buster_PREVIEW.img: 1.5 GiB, 1572864000 bytes, 3072000 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x36969c21 Device Boot Start End Sectors Size Id Type 20190628_raspberry-pi-3_buster_PREVIEW.img1 2048 614399 612352 299M c W95 FAT32 (LBA) 20190628_raspberry-pi-3_buster_PREVIEW.img2 614400 3071999 2457600 1.2G 83 Linux
- Use the start sector (2048) of the first partition and multiply it with the sector size (512). 2048*512=1048576
- Use this number to mount with offset the first partition:
mkdir -p ~/mnt/test sudo mount -o offset=1048576 20190628_raspberry-pi-3_buster_PREVIEW.img ~/mnt/test
- Now copy the kernel and initrd files:
cp ~/mnt/test/vmlinuz-4.19.0-5-arm64 ~/db_rpi3_qemu cp ~/mnt/test/initrd.img-4.19.0-5-arm64 ~/db_rpi3_qemu
- Now we are ready to run the emulated system:
qemu-system-aarch64 -M virt -m 1024 -smp 4 -cpu cortex-a53 -kernel vmlinuz-4.19.0-5-arm64 -initrd initrd.img-4.19.0-5-arm64 -drive if=none,file=20190628_raspberry-pi-3_buster_PREVIEW.img,format=raw,id=hd -append 'root=/dev/vda2 noresume' -device virtio-blk-pci,drive=hd -device virtio-net-pci,netdev=mynet -netdev user,id=mynet,hostfwd=tcp::2222-:22 -device virtio-rng-pci -no-reboot -nographic
- Username: root, password: raspberry
- The network interface included in the “virt” virtual machine has a different name than the one from the real raspberrypi. This new interfaces must be configure first:
nano /etc/network/interfaces.d/enp0s2
- Inside of this file put the following content:
auto enp0s2 # TODO: switch back to iptables-persistent once it re-enters testing iface enp0s2 inet dhcp pre-up iptables-restore < /etc/iptables/rules.v4 pre-up ip6tables-restore < /etc/iptables/rules.v6
- Restart the VM:
poweroff
- The hostfwd in the qemu command was necessary to be able to access this computer from your host computer. You can do this with:
ssh root@localhost -p 2222
- ssh in the guest system was hanging during startup. It was hanging in a getrandom() system call. To avoid this hanging the qemu option “-device virtio-rng-pci” was necessary. Apparently, software random number generation in the virt qemu machine was too slow or not working properly.
References
https://wiki.debian.org/RaspberryPiImages
https://people.debian.org/~gwolf/raspberrypi/
https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/
https://translatedcode.wordpress.com/2018/04/25/debian-on-qemus-raspberry-pi-3-model/
https://wiki.debian.org/RaspberryPi
https://wiki.debian.org/RaspberryPi3
https://salsa.debian.org/raspi-team/image-specs
https://wiki.debian.org/RaspberryPi/qemu-user-static
https://people.debian.org/~stapelberg/raspberrypi3/2018-01-08/