5

I am trying to emulate Ubuntu Core for Raspberry Pi 3 using QEMU but it does not work.

I found tutorials about emulating Raspbian using QEMU and tried to apply them to Ubuntu Core:

I could not find the right kernel so I used Raspbian Kernel. It did not work. Then I Mounted Ubuntu Core Image and extracted the kernel.img it also did not work.

I start qemu with this command

qemu-system-arm -kernel ./kernel.img \
-cpu arm1176 \
-m 256 \
-M versatilepb \
-no-reboot \
-serial stdio \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" \
-drive "file=pi3.img,index=0,media=disk,format=raw" \
-redir tcp:2222::22 

QEMU starts but does not load Ubuntu Core.

Does somebody emulated Ubuntu Core(for Raspberry Pi 3) with QEMU?

Rustam Isaev
  • 51
  • 1
  • 5
  • Hallo, I pretty sure now it is impossible to emulate Ubuntu Core for Raspberry Pi 3 on QEMU. But alternative you can emulate, Ubuntu Core for Raspberry Pi 2. I was able to Emulate Ubuntu Core for Raspi 2 on QEMU Using this command: `qemu-system-arm -M raspi2 -serial stdio -kernel kernel.img -initrd initrd.img -append "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty0 elevator=deadline snap_core=core_3750.snap snap_kernel=pi2-kernel_22.snap" -dtb bcm2709-rpi-2-b.dtb -sd ubuntu-core.qcow` – Rustam Isaev Mar 13 '18 at 12:59
  • Related: https://stackoverflow.com/questions/38837606/emulate-raspberry-pi-raspbian-with-qemu – Ciro Santilli OurBigBook.com Mar 18 '18 at 13:42
  • The related Topic is about running Raspbian OS on QEMU. Ubuntu Core seems to be more complicated – Rustam Isaev Mar 19 '18 at 07:20
  • Yes, not saying it is a dupe or anything. I'd just recommend that you try to get that working first (I didn't manage to get the display working on vanilla kernel so far). – Ciro Santilli OurBigBook.com Mar 19 '18 at 08:41

2 Answers2

1

This bit: "-M versatilepb" says "please emulate a VersatilePB development board". (That's a several decades old ARM evaluation board.) "-cpu arm1176" asks for an "arm1176" CPU, which is the ARMv6 CPU that's in the raspberry pi 1. Most userspace code intended for the raspi2 or raspi3 will not run on that (they use a newer ARMv7 CPU). Basically you're trying to use a command line from a tutorial for running a versatilepb kernel on a versatilepb model in order to run raspi 1 userspace images and filesystems. It won't work for raspi2 or raspi3 userspace code.

(Current upstream QEMU does now have a model of a raspi3; I suspect it is not yet complete enough to be able to boot the Ubuntu image, though.)

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25
  • Yes this is correct. But The kernel used in Tutorials is patched and can be run on verstailePB dev board. What do you think about using **"-M virt"** option do I need to patch the kernel then? – Rustam Isaev Mar 07 '18 at 14:58
  • You would need to use a kernel built to work with the 'virt' board. – Peter Maydell Mar 08 '18 at 11:08
  • Do you mean I can not use the standard armhf Kernel for virt board? In [this guidance] (https://gist.github.com/takeshixx/686a4b5e057deff7892913bf69bcb85a) the autor just used the Kernel from Image he wanted to emulate. – Rustam Isaev Mar 08 '18 at 12:03
  • The Ubuntu generic-lpae kernels are built to work with a variety of boards including virt (hence the 'generic' part of the name), so they're ok. The general principle is that you can't use any random kernel and expect it to work, especially if that kernel was built for a specific different board. – Peter Maydell Mar 09 '18 at 13:41
  • This sounds plausible to me. I do not use the *versatilepb* board anymore. I downloaded Ubuntu Core for Raspberry Pi 2 and trying to emulate it, on the "-M raspi2" Board. I extracted Kernel, initrd and Device Tree Binary. And Start QEMU with this command: `qemu-system-arm -M raspi2 -kernel boot-ubuntu-core/kernel.img -initrd boot-ubuntu-core/initrd.img -append "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty0 elevator=deadline" -dtb boot-ubuntu-core/dtbs/bcm2709-rpi-2-b.dtb -nographic -sd ubuntu-core-16-pi2.img` – Rustam Isaev Mar 12 '18 at 08:03
  • the output is: the requiered kernel commandline snap_core is not set – Rustam Isaev Mar 12 '18 at 08:09
  • That output must be from the guest kernel; you should do what it suggests and add a suitable snap_core entry to the guest kernel command line (which is the -append "..." string on the QEMU command line). Hopefully the docs on how to boot the Ubuntu Core images will tell you what the command line option should be. – Peter Maydell Mar 12 '18 at 10:26
  • PS: there is no USB or networking support currently in the raspi2 model. – Peter Maydell Mar 12 '18 at 10:27
  • Thank you for your quick response. Ich checked a boot log from a running Ubuntu Core on Raspi3 and modified my kernel command line to `qemu-system-arm -M raspi2 -kernel boot-ubuntu-core/kernel.img -initrd boot-ubuntu-core/initrd.img \ -append "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty0 elevator=deadline root=/dev/disk/by-label/writable net.ifnames=0 init=/lib/systemd/systemd ro panic=-1 fixrtc snap_core=core_3750.snap snap_kernel=pi2-kernel_22.snap" \ -dtb boot-ubuntu-core/dtbs/bcm2709-rpi-2-b.dtb \ -sd ubuntu-core-16-pi2.img` – Rustam Isaev Mar 12 '18 at 11:02
  • after I run this command, I get `[ 49.594734] initrd: mounting /run` and blinking curser. It seems to me that I have to append a right kernel command. Any Idea where I could find some Information about it? – Rustam Isaev Mar 12 '18 at 11:09
  • Look for the Ubuntu Core documentation. At this point you're successfully booting the guest in QEMU, so this is more of a "how do I configure my guest?" question than a QEMU one. – Peter Maydell Mar 12 '18 at 11:15
  • are you sure that there is no network support on raspi2 Machine? Ubuntu Core is useless without network, because you can only access it over ssh. – Rustam Isaev Mar 13 '18 at 13:06
  • Yes, I'm certain. We don't implement the USB controller model, and the rpi's networking hangs off USB. – Peter Maydell Mar 13 '18 at 17:58
  • Can a virtual network can be added to raspi2 Machine? – Rustam Isaev Mar 14 '18 at 07:11
0

These are the steps I did to run ubuntu for raspberry Pi in Qemu

Step 1, copy files from the image

Mount the image:

sudo losetup -f --show -P "ubuntu-20.04.3-preinstalled-server-arm64+raspi.img"
sudo mount /dev/loopXp1 /mnt/raspberry-pi-boot

Copy all the raspberry pi boot files to a local folder

Unmount the image:

sudo umount /mnt/raspberry-pi-boot
sudo losetup -d /dev/loopX

Step 2, resize the SD card image

qemu-img resize ubuntu-20.04.3-preinstalled-server-arm64+raspi.img 8G

Step 3, run qemu

qemu-system-aarch64.exe \
-M raspi3b \
-append "rw earlyprintk root=/dev/mmcblk0p2 rootdelay=1 dwc_otg.lpm_enable=0 rootfstype=ext4 loglevel=8 console=ttyAMA0,115200" \
-dtb ubuntu_arm64/bcm2710-rpi-3-b.dtb \
-kernel ubuntu_arm64/vmlinuz \
-sd "ubuntu-20.04.3-preinstalled-server-arm64+raspi.img" \
-smp 4 \
-m 1G \
-no-reboot \
-serial stdio \
-device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22

Notable tricks in the command above:

  • We pick a fairly random device tree file, there are many, lets hope for the best
  • We pick vmlinuz as kernel, lets hope it's the file we require
  • Use USB network device
  • Forward port 5555 on the host to port 22 of the emulated ubuntu
Windel
  • 499
  • 4
  • 11