Transferring usb devices from the host system to a virtual one
Bhyve supports the transfer of usb devices from the host system to a virtual one so we can bring an external usb device from our FreeBSD host system into our virtual Windows environment with the Bhyve hypervisor.
Let's install Bhyve and configure it first, then proceed to install Windows, open a terminal and type the command:
pkg install vm-bhyve bhyve-firmware
Then using any text editor you like like ee or mc add the following lines to /etc/rc.conf
vm_enable="YES"
vm_dir="/vm"
Then run and copy all the templates to the virtual machines directory:
vm init
cp /usr/local/share/examples/vm-bhyve/* /vm/.templates
Now create a switch which will bring the Internet to the virtual machines:
vm switch create public
vm switch add public re0
Next we create a configuration file using a Windows template and a disk image named Win or something else:
vm create -t windows -s 50G Win
Install Windows using any vnc client to connect to the system. The default address is 0.0.0.0:5900 or you can do it with
vm list
vm install Win/Windows-10.iso
After installing the system we need to list our USB devices:
pciconf -lv
Or search for our USB controllers like this:
pciconf -lv | grep USB
pciconf -lv | grep xhci
For example this would be xhci0@pci0:2:0:0:
To transfer the USB controller to the Bhyve run this command:
devctl set driver -f pci0:2:0:0 ppt
Then see if the device is ready
vm passthru
If yes we set the configuration file of the virtual machine. Go to the directory with the virtual machine and edit it by adding the line:
cd vm/Win/Win.conf
ee Win.conf
#USB
passthru0="2/0/0"
That is it, start vm start Win and plug in any external USB device.
BSD is so easy and fun!