How to install FreeBSD VM on FreeBSD using bhyve and ZFS.

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 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

If ZFS is available on the host machine, using ZFS volumes instead of disk 
image file can provide significant performance benefits for the guest VMs. 
A ZFS volume can be created by:
# zfs create -V16G -o volmode=dev zroot/freebsddisk0
Download an installation image of FreeBSD to install: 
https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.0/
or  
https://wiki.freebsd.org/Torrents to iso via qiBttorrent.
FreeBSD comes with an example script for running a virtual machine in bhyve.
The script will start the virtual machine and run it in a loop, so it will 
automatically restart if it crashes. The script takes a number of options to 
control the configuration of the machine: -c controls the number of virtual 
CPUs, -m limits the amount of memory available to the guest, -t defines which  
tap device to use, -d indicates which disk image to use, -i tells bhyve to 
boot from the CD image instead of the disk, and -I defines which CD image 
to use.The last parameter is the name of the virtual machine, used to track 
the running machines. This example starts the virtual machine in installation 
mode: 
# sh /usr/share/examples/bhyve/vmrun.sh \
-c 1 -m 1024M -t tap0 -d /dev/zvol/zroot/freebsddisk0 -i \
-I /path/to/FreeBSD.iso freebsdguest
The virtual machine will boot and start the installer.After installing a 
system in the virtual machine, when the system asks about dropping in to a 
shell at the end of the installation, choose Yes.

Reboot the virtual machine. While rebooting the virtual machine causes 
bhyve to exit, the vmrun.sh script runs bhyve in a loop and will automatically 
restart it. When this happens, choose the reboot option from the boot loader 
menu in order to escape the loop. Now the guest can be started from the virtual disk:
# sh /usr/share/examples/bhyve/vmrun.sh -c 1 -m 1024M \
-t tap0 -d /dev/zvol/zroot/freebsddisk0 freebsdguest

3. Persistent Configuration

In order to configure the system to start bhyve guests at boot time, the 
 
following configurations must be made in the specified files: 
 
3.1. /etc/sysctl.conf
net.link.tap.up_on_open=1
3.2. /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 Install Nginx, MySQL and PHP (FEMP) Stack on FreeBSD 13.0

Install samba on FreeBSD(on VMware Workstation) to share files with Window.