Running NetBSD on OmniOS using bhyve

       729 words, 4 minutes

I want to run GoToSocial on some *BSD system. Because I am who I am, I went for using NetBSD 10.0 . And because my hypervisor is running bhyve on OmniOS , you get the title of this blog post.

Don’t get too anxious, it is quite straightforward. So let the journey begin.

Preparation

All my servers are headless. The NetBSD VM will be no exception. Hopefully, NetBSD devs are smart enough to provide a serial console ready installation image. So let’s first grab it:

# cd /zones/iso
# wget -O NetBSD-10.0-boot-com.iso \
  https://cdn.netbsd.org/pub/NetBSD/NetBSD-10.0/amd64/installation/cdrom/boot-com.iso

I’m using zadm templates as much as possible because I find them really nice to use. A NetBSD 10 template looks like this:

# cat /zones/netbsd10-install.zadm
{
   "acpi" : "on",
   "autoboot" : "false",
   "bootdisk" : {
      "blocksize" : "8K",
      "path" : "rpool/zones/__ZONENAME__/root",
      "size" : "16G",
      "sparse" : "false"
   },
   "brand" : "bhyve",
   "cdrom" : [
      "/zones/iso/NetBSD-10.0-boot-com.iso"
   ],
   "diskif" : "virtio",
   "net" : [
      {
         "global-nic" : "private0",
         "physical" : "__ZONENAME__0"
      }
   ],
   "netif" : "virtio-net",
   "ram" : "2G",
   "rng" : "on",
   "vcpus" : "2",
   "vnc" : {
      "enabled" : "off"
   },
   "xhci" : "on",
   "zonename" : "__ZONENAME__",
   "zonepath" : "/zones/__ZONENAME__"
}

Update 2024-05-17: there seem to be network issues when using "netif" : "virtio". According to bhyve(7), this provides the virtio-net-viona, accelerated virtio interface as a default. This configuration makes network transferts freeze quite quickly. I found that using either e1000 or virtio-net provide expected network behaviour.

Installation

Before running the VM, it needs to be created. I’m using the zadm template. Some sizing values can be modified before the VM is populated.

# zadm create -b bhyve -t /zones/netbsd10-install.zadm gts
/zones/gts must not be group readable.
/zones/gts must not be group executable.
/zones/gts must not be world readable.
/zones/gts must not be world executable.
/zones/gts: changing permissions to 0700.

The VM can now be started. As I’m using the serial console aware image, it should boot straight away. But things have to be configured lately so that the VM always starts this way.

# zadm start -c gts

From there, simply follow the NetBSD documentation . There is nothing weird to expect here. It goes like any amd64 installation. Here’s what I’m doing / using:

When the installation is finished, the targetroot gets unmounted. Select the Utility menu and Halt the system to finish the VM configuration.

[ 1517.7829185] The operating system has halted.
[ 1517.7829185] Please press any key to reboot.

To exit the bhyve console from a remote SSH connection, use ~~..

Turn the VM off and remove the cdrom section from its configuration.

# zadm poweroff gts
# zadm edit gts

First boot

By default, the NetBSD installation boots using VGA. Which means we won’t be able to access the console. But this can be changed at the bootloader time. Wait for the bootloader to appear and hit 3 to drop to boot prompt. Then configure the console device and boot the system.

# zadm start -c gts

> consdev com0
> boot

Log in using the root user and modify the relevant configuration files for using the console only at every new boot.

# echo 'consdev=com0' >> /boot.cfg
# sed -i -e 's/wscons=YES/wscons=NO/' /etc/rc.conf

From there, reboot and the VM should properly be using the serial console only.

I can now install and run GoToSocial. But that will probably be another post.

One more thing

A dmesg of such a VM has been posted on NYC*BUG dmesgd

The record of the installation process for such a VM has been uploaded on my PeerTube instance. If you prefer visual content, it is there .