Raspberry: qemu on Ubuntu

development rpi raspberry ubuntu journal qemu

For a faster developement process and testing, it's possible to run the raspbian images with qemu. It's slow, it needs some minor adjustments, but it can help. I do use a raspbian lite image (without X) as i don't want/need X window management system, you may replace the image with the non-lite one, the directions still apply.

  • Install qemu:
    sudo apt install qemu-system-arm
  • Download custom qemu kernel and dtb:
    wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.14.79-stretch
    wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb
  • Download latest raspbian image and unzip:
    wget http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/2019-04-08-raspbian-stretch-lite.zip
    unzip 2019-04-08-raspbian-stretch-lite.zip
  • Expand fs:
    qemu-img resize 2019-04-08-raspbian-stretch-lite.img +8G
    fdisk 2019-04-08-raspbian-stretch-lite.img
    d > 2 > n > p > 2 > 98304 > N > w
  • Run startup script:
    #!/bin/bash
    qemu-system-arm \
    -M versatilepb \
    -cpu arm1176 \
    -m 256 \
    -hda 2019-04-08-raspbian-stretch-lite.img \
    -net nic \
    -net user,hostfwd=tcp::5022-:22 \
    -dtb versatile-pb.dtb \
    -kernel kernel-qemu-4.14.79-stretch \
    -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' \
    -no-reboot
  • Login
    pi / raspberry
  • Enable ssh:
    sudo raspi-config
  • Login via ssh (with dynamic port forwarding for basic networking):
    ssh -p 5022 -D127.0.0.1:8080 pi@localhost
  • Map virtual sdcard:
    sudo nano /etc/udev/rules.d/90-qemu.rules
    KERNEL=="sda", SYMLINK+="mmcblk0"
    KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
    KERNEL=="sda2", SYMLINK+="root"
  • Basic/Easy networking:
    echo "Acquire::socks::proxy \"socks5://127.0.0.1:8080\";" | sudo tee /etc/apt/apt.conf.d/12proxy
  • Change languages:

    sudo dpkg-reconfigure locales
    sudo dpkg-reconfigure keyboard-configuration
  • Sources:

Next Post