Install needed packages
pkg infoCheck which packages are installed. Needed are:
vm-bhyve— Management system for bhyve virtual machinesbhyve-firmware— Collection of Firmware for bhyvekldstatKernel modules
vmm.ko— virtualzation driverzfs.ko— for the file systemsysrc vm_enable="YES"- enable
vm sysrc vm_dir="zfs:vmzfs/vm"- set root directory for the vm; after the reboot the templates will show up; alternatively
vm init vm init- set templates and config files in the
vm_dirdirectory vm switch create public- create the public bridge which is used by the virtual machine for the taptun virtual divices. the bridge is called
vm-publicbut in the config files of the virtual machines the name is onlypublic vm switch add public em0- add a physical intervace
em0that is used by the bridge to access he internet. Note that if you have multiple physical devices you have to add the device that has internet access. For exampleem1may be the device that has access to the internet in which case you have to change the above command accordingly. You can check that the bridge has the correct information by issuingifconfig vm-publicor justifconfigif the bridge name is notvm-publicand check undermembersto see which interfaces are in the bridge. The correctemXshould be listed vi /path/to/vm_dir/.config/system.conf- if there are two physical ethernet devices say
em0andem1theports_public="emX"lists which the interface the switch public is used. Note also in this file there isswitch_list="public"which is used in the config files in each virtual machine
Working with vm
This the the management system with which we will start, stop update and maintain the guests
vm start jupyter- start a virtual machine with name jupyter
vm list- list all virtual machine
vm info- Check information about running virtual machines (guests)
vm stop jupyter- stop gracefully the virtual machine with name jupyter
vm poweroff jupyter- stop forcefully the virtual machine with name jupyter
vm console jupyter- connect to the virtual machine console and log on
exit- It is a good idea to logoff the host before exiting the vm console
- Press
~(tilde) then^D(Ctrl+D) to terminate the console - you may need to press
Shiftto enter the tilde character; only the righthand shift works, pressing left shift with tilde simply supplies tilde to the guest (console) vm snapshot jupyter@snapshotname- create a snapshot of a virtual machine. It is (should be) stopped at the time of taking the snapshot
vm info jupyter- will give information about the virtual machine include the list of available snapshots of that machine
vm clone existing new- Will create a copy of a virtual machine - for example create a single base system and to test various things simply clone the virtual machine and work with it. Note that you can modify the above command to clone a snapshot of a virtual machine
Managing virtual machines
Most options of a virtual machine can be modifed in the config file.
Disk size
Increase the disk size of a virtual machine, first increase the size of the virtual drive from the host, then apply the changes in the guest.
truncate -s +4G DiskFile- Enlarge the file which corresponds to the virtual drive
gpart show- find the name of the disk for example
vtbd0 => 40 16777136 vtbd0 GPT (8.0G) [CORRUPT] 40 1024 1 freebsd-boot (512K) 1064 984 - free - (492K) 2048 4194304 2 freebsd-swap (2.0G) 4196352 4190208 3 freebsd-zfs (2.0G) 8386560 8390616 - free - (4.0G)gpart recover vtbd0- After the file is enlarged it seen as
Corrupt; fix it => 40 16777136 vtbd0 GPT (8.0G) 40 1024 1 freebsd-boot (512K) 1064 984 - free - (492K) 2048 4194304 2 freebsd-swap (2.0G) 4196352 4190208 3 freebsd-zfs (2.0G) 8386560 8390616 - free - (4.0G)swapoff -a- disables the swap:
/dev/vtbd0p2— if the swap is at the second partition gpart resize -i 3 /dev/vtbd0- grow the root partition
zpool list- check which zfs pool is used (we use zfs partitions)
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT zroot 1.88G 1.27G 616M - - 18% 67% 1.00x ONLINE -zpool online -e zroot vtbd0p3- expand the pool to the whole disk