Installing and configuring the Xen hypervisor on the FreeBSD 14 operating system.
First we need to install the Xen hypervisor, we can install it from ports or packages with the following commands:
cd /usr/ports/emulators/xen-kernel/ && make install clean
or
pkg install -y xen-kernel xen-tools
Next, after installing Xen, add the following to /boot/loader.conf:
xen_kernel="/boot/xen"
xen_cmdline="dom0_mem=2048M dom0_max_vcpus=4 dom0=pvh com1=115200,8n1 guest_loglvl=all loglvl=all"
Where dom0_mem is the amount of allocated memory and dom0_max_vcpus and the number of allocated processors.
In /etc/ttys add:
xc0 "/usr/libexec/getty Pc" xterm onifconsole secure
Also add the following line to /etc/sysctl.conf:
vm.max_user_wired=-1
Then we will create a network bridge, for which in /etc/rc.conf add:
cloned_interfaces="bridge0"
ifconfig_bridge0="addm re0"
ifconfig_bge0="up"
Where re0 is our network interface, then reboot the system.
After that we need to create a virtual machine, let's start by creating a virtual disk
truncate -s 50G windows.img
Then create a virtual machine configuration file windows.cfg DomU, which looks like this:
type = "hvm"
name = "win10"
memory = 4096
vcpus = 4
vif = ['bridge=bridge0']
disk = [
'/Xen/windows.img,raw,xvda,rw',
'/Downloads/W10.iso,raw,hdc,cdrom'
]
boot = "c" # Boot to hard disk image
#boot = "d" # Boot to ISO image
vnc = 1
To load this DomU we execute:
xl create windows.cfg
and connect to DomU using the default vnc 0.0.0.0.0:5900.
View the list of virtual machines xl list
To destroy execute:
xl destroy windows.cfg
If you want to enable Nested Virtualization in Xen, add the following to the configuration file:
hap=1
nestedhvm=1
That's it, BSD is so easy and most importantly fun!