Skip to content

Instantly share code, notes, and snippets.

@KhalilOuali
Created January 26, 2023 04:36
Show Gist options
  • Save KhalilOuali/f74a5fec25457a383a8cd93147f868ca to your computer and use it in GitHub Desktop.
Save KhalilOuali/f74a5fec25457a383a8cd93147f868ca to your computer and use it in GitHub Desktop.

How to emulate Raspbian Buster Lite on QEMU on Ubuntu 22.04 LTS

After a lot of online research, this is a summary of the steps I had to take to finally emulate Raspbian (Buster version) on Ubuntu.

For more information, check the sources in the guide and at the bottom.

Last tried Jan 2023 on a Lubuntu 22.04 LTS VM on Virtualbox

I. Install QEMU/KVM and virtlib

$ sudo apt update

$ sudo apt install qemu-system-arm qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon virt-manager

II. Download Raspberry Pi OS Buster Lite

  1. Download 2022-09-22-raspios-buster-armhf-lite.img.xz from Download Page or Download Link.

  2. Extract using $ unxz 2022-09-22-raspios-buster-armhf-lite.img.xz

(Optional) Convert OS image from .img to .qcow2 format (to enable VM snapshots later)

  • $ qemu-img convert -f raw -O qcow2 2022-09-22-raspios-buster-armhf-lite.img 2022-09-22-raspios-buster-armhf-lite.qcow2

III. Download kernel-qemu-4.19.50-buster and versatile-pb-buster.dtb

IV. Set up a new VM in Virtual Machine Manager

Open Virtual Machine Manager with $ sudo virt-manager and Click Create new virtual machine.

Step 1:

  1. Choose Import existing disk image.
  2. Under Architecture Options:
    1. Select Architechture: armv6l.
    2. Select Machine Type: versatilepb.
  3. Click Forward.

Step 2:

  1. Under Provide the existing storage path:
    1. Click Browse.
    2. Click Browse Local.
    3. Go to the downloaded OS image location and select the OS Image (.img or .qcow2).
  2. Under Choose the operating system you are installing: select Generic or unknown OS. Usage is not recommended.
  3. Click Forward.

Step 3:

  1. Input Memory: 256.
  2. Input CPU: 1.
  3. Click Forward.

Step 4:

  1. Rename VM if you like.
  2. Toggle Customize configuration before install ON.
  3. Choose Network selection: Virtual network 'default' : NAT.
  4. Click Finish.

Configuration screen:

  1. Go to CPUs tab:

    1. Select Model: arm1176.
    2. Click Apply.
  2. Go to Boot Options tab:

    1. Expand Direct kernel boot.
    2. Toggle Enable direct kernel boot ON.
    3. Input or browse Kernel path: /.../kernel-qemu-4.19.50-buster.
    4. Input or browse DTB path: /.../versatile-pb-buster.dtb.
    5. Input Kernel args: root=/dev/vda2 panic=1.
    6. Click Apply.
  3. Go to IDE Disk 1 tab:

    1. Select Disk Bus: VirtIO.
    2. Click Apply.
  4. Go to NIC tab:

    1. Select Device Model: virtio.
    2. Select Apply.
  5. Click Add Hardware:

    1. Go to Channel tab.
    2. Input Name: org.qemu.guest_agent.0
    3. Select Device Type: UNIX socket (unix).
    4. Click Finish.
  6. (Optional) Click Add Hardware:

    1. Go to RNG tab.
    2. Click Finish.
  7. Click Begin Installation.

  8. The VM will start and begin installation. Wait for it to finish, you'll be prompted to log in.

V. In the VM:

  1. Log in with the default credentials Login: pi and Password: raspberry.
  2. Run $ sudo raspi-config to configure the OS (hostname, password, ssh, language, keyboard layout, etc.).
  3. Run $ sudo apt install qemu-guest-agent to install QEMU guest agent and enable host control.

All Done!

Whenever you want to use your Raspbian VM again, just start Virtual Machine Manager and launch it.

Tips:

  • Enable ssh server (in raspi_config → Interface Options) to access your VM through ssh on your host machine.
  • Shutting down and starting up your VM can be time consuming. Instead, you can save and restore a snpashot in Virtual Machine Manager.

Additional Sources:

Note:

  • It seems that you cannot use a bridged connection with a wireless interface: Archlinux.org forum.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment