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

Requirements

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

The disk image (armv7.img.gz or arm64.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 arm64.img.gz
$ qemu-img resize arm64.img 20g

Booting the system (arm64)

$ qemu-system-aarch64 -M virt -cpu cortex-a53 -smp 4 -m 4g \
      -drive if=none,file=arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 \
      -netdev type=user,id=net0 -device virtio-net-device,netdev=net0,mac=00:11:22:33:44:55 \
      -bios QEMU_EFI.fd -nographic

Booting the system (arm64) directly into the kernel with hardware accelerated virtualization on a Linux host

$ qemu-system-aarch64 -M virt,accel=kvm -cpu host -m 256 \
      -drive if=none,file=arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 \
      -device virtio-rng-pci -kernel netbsd-GENERIC64.img -append "root=NAME=netbsd-root" \
      -netdev type=user,id=net0 -device virtio-net-device,netdev=net0,mac=00:11:22:33:44:55 \
      -display none -serial stdio

Booting the system (armv7)

$ qemu-system-arm -M virt -cpu cortex-a15 -smp 4 -m 2g \
      -drive if=none,file=armv7.img,id=hd0 -device virtio-blk-device,drive=hd0 \
      -netdev type=user,id=net0 -device virtio-net-device,netdev=net0,mac=00:11:22:33:44:55 \
      -bios QEMU_EFI.fd -nographic

Enabling graphics support

To enable graphics support, remove the following command-line argument:

-nographic

and replace it with:

-display sdl,gl=on -device ramfb -device usb-ehci,id=ehci \
-device usb-mouse,bus=ehci.0 -device usb-kbd,bus=ehci.0

Bridged networking

To bridge a QEMU guest to your network, you need to create a tap(4) interface for your VM, then connect it to a physical interface with a bridge(4) interface.

The following example assumes NetBSD as a host OS, and a physical interface named bge0.

/etc/ifconfig.bridge0

descr "LAN VM bridge" up
!brconfig bridge0 add bge0

/etc/ifconfig.tap0

link f2:0b:a4:d1:f2:69 descr "NetBSD Arm64 VM" up
!brconfig bridge0 add tap0

Then replace the -netdev part of the qemu command with:

-net nic -net tap,ifname=tap0,script=no