Skip to content

Instantly share code, notes, and snippets.

@mgerdts
Last active September 12, 2023 16:08
Show Gist options
  • Save mgerdts/6fabc913aca3acd2f1e435a7dc2bbd80 to your computer and use it in GitHub Desktop.
Save mgerdts/6fabc913aca3acd2f1e435a7dc2bbd80 to your computer and use it in GitHub Desktop.
Install windows with bhyve

These are bare-bones instructions for creating a Windows image for bhyve on SmartOS. You will need a platform image that has the fix for OS-7117. Platform images that I've used in testing are here: iso tgz usb

Create a volume that will be the disk.

zfs create -o volblocksize=4k -V 16g -s zones/hdd-windows

This script will be used for booting from the CD.

#!/bin/sh

bootrom=/usr/share/bhyve/uefi-rom.bin

[ "$1" = "-k" ] || pfexec bhyvectl --vm=windows --destroy
bhyve -H -w \
        -s 0,hostbridge \
        -B "1,product=SmartOS HVM" \
        -s 31,lpc \
        -l bootrom,$bootrom \
        -l com1,stdio \
        -c 2 \
        -m 2G \
        -s 3:0,ahci-cd,/zones/media/win2016eval.iso \
        -s 4:0,ahci-hd,/dev/zvol/rdsk/zones/hdd-windows \
        -s 28,fbuf,vga=off,tcp=0.0.0.0:5900,w=1024,h=768,wait -s 29,xhci,tablet \
        windows

You will need to connect via vnc and hit the any key to tell it to boot from the CD. After doing the first chunk of work, Windows willl reboot. You will need to re-run the script one or more times to complete the installation. In the subsequent boots, you do not want to boot from the CD, so don't hit the any key. Note that the ,wait on the fbuf argument will cause bhyve to wait for the VNC connection before booting.

Once the installation is complete, we need to associate zones/hdd-windows with a VM. The simplest way to do that is with the following.

First, stop the windows VM. Shutdown from within the VM or kill the bhyve process (-TERM for an orderly shutdown, -KILL or -9 for pull the cord).

Next, create an empty vm and swap disks.

vmadm create -f bhyve-empty.json
uuid=...
zfs destroy zones/$uuid/disk0
zfs rename zones/hdd-windows zones/$uuid/disk0

Now you should be able to start the Windows VM with vmadm start $uuid

Limitiations

Some things are not fully baked. We're working on them.

  • Currently you must configure networking statically or have an external DHCP server.
  • The procedure above does not include virtio drivers for disks or networking. It is unknown whether any other networking emulation works with bhyve on SmartOS. The virtio drivers we use on kvm and will likely use with bhyve are on this iso. It should be possible to add that iso to the command line during installation and adjust hdd-windows to use virtio-blk instead of ahci.
{
"brand": "bhyve",
"alias": "bhyve-uefi",
"vcpus": 2,
"autoboot": false,
"ram": 2048,
"disks": [
{
"boot": true,
"model": "ahci",
"size": 10240
}
]
}
@skirmess
Copy link

What does the -B "1,product=SmartOS HVM" do? Can't find it in the bhyve help.

@mgerdts
Copy link
Author

mgerdts commented Jan 15, 2021

It's been a while (I no longer work on SmartOS), but I believe it sets the BIOS product name, which is visible in a Linux guest with smbios -t 1. I think this was done so that cloud-init will recognize that it should use the SmartOS datasource, but it looks like that is looking for "SmartDC" not "SmartOS".

https://github.com/canonical/cloud-init/blob/0af1ff1eaf593c325b4f53181a572110eb016c50/cloudinit/sources/DataSourceSmartOS.py#L775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment