# How To Install Windows Server 2019 on Bhyve



## ScopeDog (Sep 11, 2020)

A few weeks ago, I was new to bhyve and had pretty hard time to install Windows Server 2019 on FreeBSD 12.1R + bhyve. However, I could manage to install it and would like to share the how-to because there's little information available on it. Any suggestions on modification, additional information, etc are welcome.
Note I have skipped AutoUnattend.xml as none of AutoUnattend.xml I tested worked including ones automatically created online.


Load the following kernel modules (aesni is optional):

`# kldload vmm nmdm aesni`

Also add those modules to kld_list on /etc/rc.conf like:

`kld_list="vmm nmdm aesni"`

Install the following packages:

`# pkg install p7zip cdrtools uefi-edk2-bhyve tightvnc`

Suppose your bhyve home directory is /home/bhyve, then go there and mkdir iso-remaster:

`# mkdir iso-remaster`

Download a Windows Server 2019 iso file and put it under the current dir.
Download the latest Linux virtio iso file such as virtio-win-0.1.189.iso from https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/ and put it under the current dir.
Suppose the downloaded Windows iso file is windows.iso, then unarchive it by:

`# 7z x windows.iso -oiso-remaster`

Create an installation iso file install.iso as follows:

`mkisofs \
      -b boot/etfsboot.com -no-emul-boot -c BOOT.CAT \
     -iso-level 4 -J -l -D \
     -N -joliet-long \
     -relaxed-filenames -v \
     -V "Custom" -udf \
     -boot-info-table -eltorito-alt-boot -eltorito-platform 0xEF \
     -eltorito-boot efi/microsoft/boot/efisys_noprompt.bin \
     -no-emul-boot \
     -o install.iso iso-remaster`

Create a bhyve image file as follows (replace ‘80GB’ with your favorite size):

`# truncate -s 80GB win2019.img`

Start installing Windows Server 2019 as follows:

`bhyve \
-c 2 \
-s 0,hostbridge \
-s 3,ahci-hd,win2019.img \
-s 4,ahci-cd,install.iso \
-s 10,virtio-net,tap0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1280,h=720,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l com1,/dev/nmdm0A \
-l com2,/dev/nmdm1A \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
-m 8G -H -w \
  win2019`

Also, monitor the Windows screen by:

`% vncviewer localhost:5900`

Note you may need to run it as a non-root user.
Once the first step of the installation is done,  Windows tries to reboot and bhyve exits.
In the next step, you need to start bhyve as follows. This also mounts virtio-win-XX.iso as a CD drive so you can install virtio virtual ethernet driver later. Replace virtio-win-0.1.189.iso with your virtio driver downloaded above.

`bhyve \
-c 2 \
-s 0,hostbridge \
-s 3,ahci-hd,win2019.img \
-s 4,ahci-cd,virtio-win-0.1.189.iso \
-s 10,virtio-net,tap0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1280,h=720 \
-s 30,xhci,tablet \
-s 31,lpc \
-l com1,/dev/nmdm0A \
-l com2,/dev/nmdm1A \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
-m 8G -H -w \
win2019`

Access the Windows screen with:

`% vncviewer localhost:5900`

Open Windows Explorer and go to “CD Drive (D: ) - NetKVM - 2k19 - amd64”. Then right click ‘netkvm.inf’ and install it. The virtual network adaptor will now be active.
After the installation, you can start bhyve with the above command or the same command without:

`-s 4,ahci-cd,virtio-win-0.1.189.iso \`

line.


----------



## Martin Paredes (Sep 16, 2020)

Can't you use the origional ISO from windows (the windows.iso) for the installation?

Why you need to emulate serial ports?


----------



## ScopeDog (Sep 16, 2020)

Well, I don't actually know but I guess the remastering is required for booting. Ya, I don't think serial ports are necessary in many cases but just wanted to include. Some people may need them.

I hope somebody posts a better answer for your question.


----------



## Selin (Oct 1, 2020)

I've used vm-bhyve and VNC to install Windows 2016. Hope the same will work for 2019 as well.
Just set the following options in the vm-guest config file:

```
graphics_port=<port>
graphics_wait="yes"
```
Then start installation using original MS ISO file:
`vm install <vm_guest_name> <.iso file>`
connected to that VM using VNC client;
and installed Windos the same way as via regular IPMI of IP-KVM interface.

_added_
When the installation is complete - `graphics_wait="yes"` should be either commented or removed - to let starting this guest in the future without having VNC connection.
And as I understand - vm-bhyve guest settings are reloaded only when this guest makes power cycle.


----------



## m0nkey_ (Oct 1, 2020)

Martin Paredes said:


> Why you need to emulate serial ports?


Windows has something called SAC that listens on a serial port, so I imagine that's what it could be used for. SAC is pretty much a serial admin console allowing the user to effectively fix the Windows install should things go wrong.









						Azure Serial Console for Windows - Virtual Machines
					

Bi-Directional Serial Console for Azure Virtual Machines and Virtual Machine Scale Sets using a Windows example.



					docs.microsoft.com


----------



## usdmatt (Oct 1, 2020)

> I've used vm-bhyve and VNC to install Windows 2016. Hope the same will work for 2019 as well.
> Just set the following options in the vm-guest config file:



Assuming it all works correctly you shouldn't really need anything in the config other than `graphics="yes"` (unless you specifically want to also set the resolution as well).

vm-bhyve will try to find an available port starting at 5900, which can be seen in `vm list`, and the wait option should default to yes during the first run on an install, allowing you to get to the "boot from cd" option in time.

Before graphics support in bhyve, you had to use a custom ISO and install script, using the SAC to monitor progress. It was a PITA but shouldn't be necessary now we can use VNC to access the graphical installer.


----------

