This page attempts to document running NetBSD/riscv under the QEMU open source processor emulator. This can be extremely useful for development and testing.


Installing QEMU on NetBSD

You can install latest qemu with the following commands. It is assumed that your pkgsrc tree is in /usr/pkgsrc directory.

# cd /usr/pkgsrc/emulators/qemu
# make install

Preparing the disk image and kernel

The disk image (riscv64.img.gz) must first be uncompressed. The qemu-img tool can then resize the image to the desired size. On first boot, NetBSD will grow the root file-system to match the size of the disk.

$ gunzip netbsd-GENERIC64.gz 
$ gunzip riscv64.img.gz
$ qemu-img resize riscv64.img 20g

Booting the system (riscv64)

$ qemu-system-riscv64 \
      -M virt \
      -m 4g \
      -kernel netbsd-GENERIC64 \
      -drive if=none,file=riscv64.img,id=hd0,format=raw \
      -device virtio-blk-device,drive=hd0 \
      -device virtio-rng-device \
      -netdev type=user,id=net0 \
      -device virtio-net-device,netdev=net0,mac=00:11:22:33:44:55 \
      -append "root=dk1" \