Tuesday, July 28, 2015

Installing and running NetBSD and OpenBSD under bhyve

These instructions assume that you have downloaded the install ISO from the respective sources.  These were doing with specific versions, and there may be minor changes with older and newer versions.

These instructions could possibly be more simple, such as not using separate device maps for grub-bhyve.   These were testing on a month old HEAD.

There are other guides that cover most of this, and probably in more detail.  The issue that I had was the exact commands to grub to load kernels was not well documented.  Both of the images boot and are able to get DHCP leases and pass basic traffic.

Hope this helps others!

NetBSD

  1. Install grub2-bhyve:
    pkg install grub2-bhyve
  2. Create a file called instdev.map containing:(cd0) NetBSD-6.1.5-amd64.iso
    (hd1) netbsd.img
  3. Create the file netbsd.img with the correct size:
    truncate -s 3g netbsd.img
  4. Run the following commands (or put into a script file) under sh:MEM=512MVM=nbsd615
    bhyvectl --destroy --vm=$VM
    grub-bhyve -r cd0 -M $MEM -m instdev.map $VM <<EOFknetbsd -h -r cd0a (cd0)/netbsdbootEOFbhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc \
        -s 2:0,virtio-net,tap3 -s 3:0,virtio-blk,./netbsd.img \
        -s 4:0,ahci-cd,./NetBSD-6.1.5-amd64.iso \
        -l com1,stdio -c 2 -m $MEM $VM
  5. This will run the installer, complete the installation.
  6. Create a file called dev.map containing:
    (hd1) netbsd.img
  7. Now in the future, to run NetBSD from the image, run the following commands:
    MEM=512MVM=nbsd615
    bhyvectl --destroy --vm=$VM
    grub-bhyve -r cd0 -M $MEM -m dev.map $VM <<EOFknetbsd -h -r ld0a (hd1,msdos1)/netbsdbootEOFbhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc \
        -s 2:0,virtio-net,tap3 -s 3:0,virtio-blk,./netbsd.img \
        -l com1,stdio -c 2 -m $MEM $VM
  8. Profit!

OpenBSD

  1. Install grub2-bhyve:
    pkg install grub2-bhyve
  2. Create a file called instdev.map containing:
    (cd0) install57.iso(hd1) openbsd.img
  3.  Create the file openbsd.img with the correct size:
    truncate -s 3g openbsd.img
  4. Run the following commands (or put into a script file) under sh:MEM=512MVM=obsd57
    bhyvectl --destroy --vm=$VM
    grub-bhyve -r cd0 -M $MEM -m instdev.map $VM <<EOFkopenbsd -h com0 (cd0)/5.7/amd64/bsd.rdbootEOFbhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc \    -s 2:0,virtio-net,tap3 -s 3:0,virtio-blk,./openbsd.img \    -s 4:0,ahci-cd,./install57.iso \    -l com1,stdio -c 2 -m $MEM $VM
  5. This will run the installer, complete the installation.
  6. Create a file called dev.map containing:
    (hd1) netbsd.img
  7. Now in the future, to run OpenBSD from the image, run the following commands:
    MEM=512MVM=obsd57
    bhyvectl --destroy --vm=$VM
    grub-bhyve -r hd1 -M $MEM -m dev.map $VM <<EOFkopenbsd -h com0 -r sd0a (hd1,openbsd1)/bsdbootEOFbhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc \
        -s 2:0,virtio-net,tap3 -s 3:0,virtio-blk,./openbsd.img \
        -s 4:0,ahci-cd,./install57.iso \
        -l com1,stdio -c 2 -m $MEM $VM
  8. Profit!