Here are some instructions based on what I did which worked for me.
- Have Ubuntu 20.04 host and download the Ubuntu 20.04 “riscv64” image or have an Ubuntu 21.04 host and download the Ubuntu 21.04 “riscv64” image (this software is really picky about the versions matching).
- Install the dependencies:
sudo apt install qemu-system-misc opensbi u-boot-qemu qemu-utils
- Optionally rename the image to something simpler.
- Extract the image from step 0:
xz -dk ubuntu.img.xz
- Increase the size of the image
qemu-img resize -f raw ubuntu.img +20G
- Be aware, this can technically be changed later but it’s really annoying to do, I recommend setting the size now to whatever size you think you’ll need, I ended up running out of space and spent over an hour fiddling with fdisk and such.
- Make a Bash script with this command (or just run it) to boot the VM:
qemu-system-riscv64 \
-machine virt \
-nographic \
-m 8192 -smp 4 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-device virtio-net-pci,netdev=eth0 \
-netdev user,id=eth0,hostfwd=tcp::2222-:22 \
-drive file=ubuntu.img,format=raw,if=virtio \
- Let it boot, this may take several minutes. Then log in.
- Do not run
sudo apt upgrade
as changing the kernel or bootloader can brick the VM (in my experience). - By default it uses the serial port, but this is quite bad. Run
sudo apt install openssh-server
, open a terminal on your host, and runssh -p 2222 ubuntu@localhost
to SSH into your VM for a much better experience. - Install whatever you want as long as you don’t run upgrade. Like
sudo apt install cmake gcc clang build-essential