User Tools

Site Tools


Writing /var/lib/dokuwiki/data/meta/tutorials/debian_buster_for_rpi3_with_qemu.meta failed
tutorials:debian_buster_for_rpi3_with_qemu

This is an old revision of the document!


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
  • The hostfwd is 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

tutorials/debian_buster_for_rpi3_with_qemu.1572914213.txt.gz · Last modified: 2022/09/20 00:08 (external edit)