在FreeBSD(13.0)上用bhyve,ZFS安装windows10

1. Preparing the Host

First, load the bhyve kernel module:

# kldload vmm

Then, create a tap interface for the network device in the virtual machine to attach to. In order to for the network device to participate in the network, also create a bridge interface containing the tap interface and the physical interface as members. In this example, the physical interface is em0:

# ifconfig tap0 create
# sysctl net.link.tap.up_on_open=1
net.link.tap.up_on_open: 0 -> 1
# ifconfig bridge0 create
# ifconfig bridge0 addm em0 addm tap0
# ifconfig bridge0 up

2. Using ZFS with bhyve Guests

A ZFS volume can be created by:

# zfs create -V88G -o volmode=dev zroot/win10disk0

If you want to destroy ZFS file.

# zfs list

For example the ZFS file you want to destroy is win10disk0:

# zfs destroy  zroot/win10disk0

3. Preparing for the Installation

Download an installation image of Windows10 to install:
https://www.microsoft.com/en-us/software-download/windows10ISO

Install VNC client

# pkg install tightvnc

Download virtio-win driver.

In order to make use of the UEFI support in bhyve, first obtain the UEFI firmware images. This can be done by installing sysutils/bhyve-firmware as follows:

# pkg install sysutils/bhyve-firmware

4. Installation Windows10

# sh installwin10.sh

If there is warning message as follows:

vm_reinit: Device busy

The instance of the virtual machine needs to be destroyed before it can be started again:

# bhyvectl --destroy --vm=guestwin10

The installwin10.sh script is as follows(change the /path/to/windows10.iso to your own path ):

#!/bin/sh
bhyve -c 2 -m 2G -w -H \
-s 0,hostbridge \
-s 1,ahci-cd,/path/to/windows10.iso \
-s 2,ahci-hd,/dev/zvol/zroot/win10disk0 \
-s 3,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 bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
guestwin10

Understanding bhyve command-line options:

  • -c : number of virtual CPUs
  • -m : RAM/memory size for VM
  • -w : ignore unimplemented MSRs
  • -H : host filesystem to export to the loader
  • -s : Configure a virtual PCI slot and other function such as hard disk, cdrom, and other devices
  • -l : the OS loader to use(uefi needed for non-FreeBSD oses such as Linux/Windows guests)

Open a new terminal to use VNC client.

$ vncviewer 

Input 0.0.0.0:5900 into the popup window. And installing windows10. The VNC window will close when windows10 restart.

5. Continue to installing Windows10

Continue to finish installing windows10.

# sh startwin10.sh

The startwin.sh script is as follows(change the /path/to/virtio-win-0.1.118.iso to your own path ):

#!/bin/sh
bhyve -c 2 -m 2G -w -H \
-s 0,hostbridge \
-s 1,ahci-cd,/path/to/virtio-win-0.1.118.iso \
-s 2,ahci-hd,/dev/zvol/zroot/win10disk0 \
-s 3,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 bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
guestwin10 

The VNC window will close again when windows10 restart.

Let's run startwin10.sh AGAIN.

# sh startwin10.sh

6. Installing network driver virtio-win

Click source file manager, and click the computer to find the CD driver virtio-win.
virtio-win -> NetKVM -> w10 -> amd64 or x86(depend on your CPU type) -> netkvm(right click) -> Installation.

After configured the network of windows10, you can start windows10 without virtio-win. So the script win10.sh that starting windows10 as follows:

#!/bin/sh
bhyve -c 2 -m 2G -w -H \
-s 0,hostbridge \
-s 2,ahci-hd,/dev/zvol/zroot/win10disk0 \
-s 3,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 bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
guestwin10

7. Persistent Configuration

In order to configure the system to start bhyve guest at boot time, the following configurations must be made in the specified files:

/etc/sysctl.conf

net.link.tap.up_on_open=1

/etc/rc.conf

cloned_interfaces="bridge0 tap0"
ifconfig_bridge0="addm em0 addm tap0"
kld_list="vmm"

欢迎爱好FreeBSD的朋友加QQ群 993640279 交流.

posted @ 2021-11-11 11:29  enjoy_jun  阅读(693)  评论(0编辑  收藏  举报