Dr. Brian Robert Callahan

academic, developer, with an eye towards a brighter techno-social life


Let's install OpenBSD/riscv64 on QEMU

I wanted to get in on the OpenBSD/riscv64 bandwagon, but I don't have the money to spend on fancy new hardware. Fortunately, QEMU has RISC-V support. Unfortunately, I could not find any instructions to install OpenBSD on it. We'll just have to figure it out ourselves.

Additionally, my laptop for $DAYJOB is running Windows 11. It's also the fastest machine I have at the moment, so I'd prefer to use it for running my OpenBSD/riscv64 VM. It will also let me do some development work in my office.

Let's figure out how to set this all up.

Step 1: Getting QEMU

I got QEMU binaries for Windows x64 here. They seem to work just fine.

Step 2: Preparing for OpenBSD

I set up a new folder on my Desktop named riscv64. Inside that directory, I placed the following files:

The riscv64.img file I generated using qemu-img create -f qcow2 riscv64.img 80G. The miniroot71.img file I downloaded from here. The fw_jump.bin file I got from the sysutils/opensbi package and the u-boot.bin file I got from the sysutils/u-boot package.

While I installed these two packages on one of my OpenBSD machines and copied the two needed files over to my Windows machine, that is not necessary. OpenBSD packages are simply gzip'd tar files, so you can download the opensbi and u-boot-riscv64 packages from here and extract them yourself on your Windows machine.

It took me a while to figure out the right QEMU incantation. Here it is:

C:\Users\Brian\Desktop\riscv64>"C:\Program Files\qemu\qemu-system-riscv64w.exe" \
	-M virt -m 1G -bios fw_jump.bin -kernel u-boot.bin \
	-device virtio-net-device,netdev=net -netdev user,id=net \
	-device virtio-blk-device,drive=sd -drive file=miniroot71.img,if=none,id=sd \
	-device virtio-blk-device,drive=hd -drive file=riscv64.img,if=none,id=hd

The order of the two hard drives is important, as QEMU will try to boot from the first one you list on the command line.

When the QEMU window appears, it will start in the compatmonitor0 view. There is no glass console (yet?) for RISC-V on QEMU. You can switch to the serial0 view by clicking on the View menu and selecting serial0 from the drop-down menu. You will then see the machine booting up and the OpenBSD installer running.

Step 3: Install OpenBSD

Now you can install OpenBSD normally. You will have to select sd1 as your root disk when asked. Everything works as expected, including networking. I was able to install over https.

Step 4: Running OpenBSD

To run OpenBSD, we only need to remove the references to the installer. I also decided to redirect the serial over telnet so I could use PuTTY for a nicer user experience:

C:\Users\Brian\Desktop\riscv64>"C:\Program Files\qemu\qemu-system-riscv64w.exe" \
	-M virt -m 1G -bios fw_jump.bin -kernel u-boot.bin \
	-device virtio-net-device,netdev=net -netdev user,id=net \
	-device virtio-blk-device,drive=hd -drive file=riscv64.img,if=none,id=hd \
	-nographic -serial telnet::4444,server

Step 5: Enjoy OpenBSD

Now I can enjoy my favorite operating system on a new architecture. I'll use it to do some ports work.

Have fun!