How to install Linux VM on FreeBSD using bhyve and ZFS

How to install Linux VM on FreeBSD using bhyve and ZFS

To install a Linux virtual machine (VM) on FreeBSD using bhyve and ZFS, follow these steps:

  1. Install the bhyve and bhyve-firmware packages from the package manager:
pkg install bhyve bhyve-firmware
Source‮ww:‬w.lautturi.com
  1. Create a ZFS volume to store the VM's files. Replace vm-name with the desired name for your VM and disk-size with the desired size of the disk:
zfs create -V disk-size -s -b $(getconf PAGESIZE) -o compression=lz4 -o logbias=throughput -o sync=always -o primarycache=metadata -o secondarycache=none -o dedup=off -o copies=1 zroot/vm/vm-name
  1. Download a Linux ISO image and copy it to a directory on your FreeBSD system. For example, you can use the following command to download the latest version of Ubuntu:
fetch http://releases.ubuntu.com/20.04/ubuntu-20.04-live-server-amd64.iso
  1. Create a configuration file for your VM. This file should specify the number of CPU cores, amount of memory, and other parameters for the VM. Here is an example configuration file that creates a VM with 1 CPU, 512MB of memory, and a 20GB disk:
vm:
  name: vm-name
  vcpus: 1
  memory: 512M
  disks:
    - name: disk0
      size: 20G
      zvol: zroot/vm/vm-name
  iso: /path/to/linux.iso
  bootloader: grub
  vnc: true
  vnc_port: 5900
  vnc_password: password

Replace vm-name with the name you chose for your VM, /path/to/linux.iso with the path to the Linux ISO image you downloaded, and password with a password for the VNC console.

  1. Use the bhyvectl command to create the VM and start it:
bhyvectl --create --vm=vm-name --config=vm.conf
bhyvectl --start --vm=vm-name
  1. Connect to the VNC console to finish installing Linux. You can use a VNC client such as TightVNC or RealVNC to connect to localhost:5900 (replace 5900 with the vnc_port specified in your configuration file). Use the password you specified in the configuration file to authenticate.

Follow the prompts to install Linux on the VM. Once the installation is complete, you can use the VM like any other Linux system.

Note: Make sure to shut down the VM properly before shutting down or rebooting the host system. You can do this by connecting to the VNC console and shutting down the VM from within Linux, or by using the bhyvectl --destroy --vm=vm-name command.

Created Time:2017-10-16 14:38:47  Author:lautturi