2022-04-18: Let's install OpenBSD/riscv64 on QEMU
source link: https://briancallahan.net/blog/20220418.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[prev]
[next]
2022-04-18
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:
fw_jump.bin
miniroot71.img
riscv64.img
u-boot.bin
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!
OpenBSD httpd
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK