Ubuntu installation on a RISC-V virtual machine using a server install image and QEMU

Overview

Starting with Ubuntu 22.04 a server install image is made available. This topic describes how to use the image for an installation on a virtual machine.

A general overview of the installation process is available at https://ubuntu.com/tutorials/install-ubuntu-server.

Prerequistites

To run the installation you will need the following packages:

  • qemu-system-misc - QEMU is used to emulate a virtual RISC-V machine.
  • opensbi - OpenSBI provides the Supervisor Execution Environment running in machine mode.
  • u-boot-qemu - U-Boot is the firmware implementing the UEFI API and loads GRUB.
sudo apt-get install qemu-system-misc opensbi u-boot-qemu

Download the image either using your web browser or with

wget https://cdimage.ubuntu.com/ubuntu-server/daily-live/current/jammy-live-server-riscv64.img.gz 

Installation

Extract the image.

gzip -d jammy-live-server-riscv64.img.gz

Create the disk image on which you will install Ubuntu. 16 GiB should be enough.

dd if=/dev/zero bs=1M of=disk count=1 seek=16383

Start the installer with:

/usr/bin/qemu-system-riscv64 -machine virt -m 4G -smp cpus=2 -nographic \
    -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin \
    -kernel /usr/lib/u-boot/qemu-riscv64_smode/u-boot.bin \
    -netdev user,id=net0 \
    -device virtio-net-device,netdev=net0 \
    -drive file=jammy-live-server-riscv64.img,format=raw,if=virtio \
    -drive file=disk,format=raw,if=virtio \
    -device virtio-rng-pci

Follow the installation steps in https://ubuntu.com/tutorials/install-ubuntu-server.

When rebooting we have to remove the installer image. Otherwise the installer will restart.

U-Boot gives you a 2 second time window to press the Enter key to reach the U-Boot console. In U-Boot’s console you can use the poweroffcommand to stop QEMU. Another option to exit QEMU is pressing keys CTRL-a followed by key x.

Run Ubuntu

To run you installed Ubuntu image use

/usr/bin/qemu-system-riscv64 -machine virt -m 4G -smp cpus=2 -nographic \
    -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin \
    -kernel /usr/lib/u-boot/qemu-riscv64_smode/u-boot.bin \
    -netdev user,id=net0 \
    -device virtio-net-device,netdev=net0 \
    -drive file=disk,format=raw,if=virtio \
    -device virtio-rng-pci

In Ubuntu 22.04 the number of virtual CPUs is limited to 8 in QEMU and in the Linux kernel.

3 Likes

Nice guide @xypron, thanks.
In my testing on Focal I was not able to use these instructions, as the boot stops with a traceback 5 seconds in.
Running this on Jammy is working just fine.

Are there some fixes that might be SRUed, or is there a minimum series that people should be running if they want to test this?

Please, use the opensbi and u-boot-qemu from the same release as the one that you are installing.

U-Boot gives you a 2 second time window to press the Enter key to reach the U-Boot console

Have you considered the -no-reboot argument for qemu-system ? It results in the installation VM shutting down instead of booting again, which would then make it easier to run your second command line that does not contain the installer image.