1

I am trying to emulate a Raspberry Pi 3B using QEMU 7 with the following options:

qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a53 \
    -append "ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" \
    -dtb bcm2710-rpi-3-b.dtb \
    -drive if=sd,format=raw,file=2022-04-04-raspios-bullseye-arm64-lite.img \
    -kernel kernel8.img \
    -m 1G -smp 4 \
    -serial mon:stdio \
    -usb -device usb-mouse -device usb-kbd \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \

But without much success as I am facing some problems.

First, I can't login with the default pi/raspberry combo. I have used the lite image, the full image and the ubuntu server one (with ubuntu/ubuntu combo) and I wasn't able to login in any of them although I have tried numerous times, I have made sure that I typed the password correctly and even copy-pasted it but to no avail.

Furthermore while booting I get an error that the kernel modules weren't loaded. I also believe that I should provide QEMU with an initrd file which I can't find on the Raspberry/firmware repository (where I got the kernel and the device tree).

PS

There is also a minor annoyance because the emulation runs in the console while the QEMU window remains pitch black.

Edit #1:

I was able to login using the Ubuntu Server image with the following options, but it doesn't connect to the internet (the PS described above persists too):

qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a53 \
    -m 1G -smp 4 \
    -drive if=sd,format=raw,file=ubuntu-22.04-server-raspi.img \
    -kernel vmlinuz \
    -append "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" \
    -initrd initrd.img \
    -dtb bcm2710-rpi-3-b_ubuntu.dtb \
    -serial mon:stdio \
    -usb -device usb-mouse -device usb-kbd \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \

Important for QEMU beginners that may read this in the future: Kernel image, initrd and dtb must be retrieved from the same image that is used to boot in order to avoid version mismatches. This is why the kernel modules didn't load.

Also notice that it takes a few minutes to boot, more so in the first boot/initial setup, so be patient before logging in.

4
  • i do not see a question in your post
    – jsotola
    Aug 4, 2022 at 6:46
  • @jsotola how to make it work. I fixed the modules & login issue as described in edit #1 but I can't connect to the internet, so it's still not properly emulated.
    – AQUATH
    Aug 4, 2022 at 8:41
  • I'm also trying to get this to work? Any luck? Sep 5, 2022 at 1:39
  • @JamesRisner Not a robust solution, but I managed to login using Manjaro instead of Raspberry Pi OS.
    – AQUATH
    Sep 6, 2022 at 15:22

1 Answer 1

3

I've created some steps needed to get this working with April 4th Raspios

# wget https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-04-07/2022-04-04-raspios-bullseye-arm64-lite.img.xz
# unxz 2022-04-04-raspios-bullseye-arm64-lite.img.xz
# mkdir boot
# mount -o loop,offset=4194304 2022-04-04-raspios-bullseye-arm64-lite.img boot
# cp boot/bcm2710-rpi-3-b-plus.dtb kernel8.img .
# echo 'pi:$6$6jHfJHU59JxxUfOS$k9natRNnu0AaeS/S9/IeVgSkwkYAjwJfGuYfnwsUoBxlNocOn.5yIdLRdSeHRiw8EWbbfwNSgx9/vUhu0NqF50' > boot/userconf
# umount boot
# qemu-img convert -f raw -O qcow2 2022-04-04-raspios-bullseye-arm64-lite.img  \
      2022-04-04-raspios-bullseye-arm64-lite.qcow2
# qemu-img resize 2022-04-04-raspios-bullseye-arm64-lite.qcow2 4g

Then run Qemu 7.1.0 this way:

# qemu-system-aarch64 -m 1024 -M raspi3b -kernel kernel8.img \
  -dtb bcm2710-rpi-3-b-plus.dtb -sd 2022-04-04-raspios-bullseye-arm64-lite.qcow2 \
  -append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4" \
  -nographic -device usb-net,netdev=net0 \
  -netdev user,id=net0,hostfwd=tcp::5555-:22

Edit your /boot/cmdline.txt file to add modules-load=dwc2,g_ether to /boot/cmdline.txt after rootwait.

They changed how passwords work. In short, there is no valid password. You must create a file in the boot directory called "userconf" with the hashed username:password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.