Booting bhyve Debian/Ubuntu Linux VM with UEFI Firmware on FreeBSD

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

Using ZFS with bhyve Guests

A ZFS volume can be created by:
# zfs create -V88G -o volmode=dev zroot/linuxdisk0
 
If you want to destroy ZFS file.
# zfs list
 
For example the ZFS file you want to destroy is  win10disk0:
# zfs destroy  zroot/linuxdisk0

Preparing for the Installation

Download Debian/Ubuntu Linux iso.

Install VNC client
# pkg install tightvnc

 
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

Install Linux

# sh install_linux.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=guestlinux

The install_linux.sh script is as follows(change the /path/to/linux.iso to your own path ):
#!/bin/sh
bhyve -c 1 -m 1G -w -H \
-s 0,hostbridge \
-s 1,ahci-cd,/path/to/linux.iso \
-s 2,ahci-hd,/dev/zvol/zroot/linuxdisk0 \
-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 \
guestlinux

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 linux. The VNC window will close when linux restart.
 

Start Linux

# sh start_linux.sh
start_linux.sh is as follows:
#!/bin/sh
bhyve -c 1 -m 1G -w -H \
-s 0,hostbridge \
-s 2,ahci-hd,/dev/zvol/zroot/linuxdisk0 \
-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 \
guestlinux

As you can see,if you install_linux.sh remove the line -s 1,ahci-cd,/path/to/linux.iso \  from install_linux.sh, it will become start_linux.sh.

The error you will encounter.

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"

Comments

Popular posts from this blog

BdsDex: failed to load Boot0001 "UEFI BHYVE SATA DISK BHYVE-OABE-20A5-E582" from PciRoot(0x0)/Pci (0x2, 0x0)/Stat(0x0,0xFFFF,0x0) : Not Found

How to Dockerizing LEMP Stack with Docker-Compose

FreeBSD安装SCIM中文输入法(csh/tcsh)