14. VMs

A Virtual Machine (VM) is an environment on a host computer that can be used as if it were a separate physical computer. VMs can be used to run multiple operating systems simultaneously. Operating systems running inside a VM see emulated virtual hardware rather than the actual hardware of the host computer. This provides more isolation than Jails, although there is additional overhead. A portion of system RAM is assigned to each VM, and each VM uses a zvol for storage. While a VM is running, these resources are not available to the host computer or other VMs.

FreeNAS® VMs use the bhyve(8) virtual machine software. This type of virtualization requires an Intel processor with Extended Page Tables (EPT) or an AMD processor with Rapid Virtualization Indexing (RVI) or Nested Page Tables (NPT).

To verify that an Intel processor has the required features, use Shell to run grep VT-x /var/run/dmesg.boot. If the EPT and UG features are shown, this processor can be used with bhyve.

To verify that an AMD processor has the required features, use Shell to run grep POPCNT /var/run/dmesg.boot. If the output shows the POPCNT feature, this processor can be used with bhyve.

Note

AMD K10 “Kuma” processors include POPCNT but do not support NRIPS, which is required for use with bhyve. Production of these processors ceased in 2012 or 2013.

14.1. Creating VMs

Select VMs Add VM for the Add VM dialog shown in Figure 14.1.1:

_images/vms-add1a.png

Fig. 14.1.1 Add VM

VM configuration options are described in Table 14.1.1.

Table 14.1.1 VM Options
Setting Value Description
Name string a name to identify the VM
Description string a short description of the VM or its purpose
Virtual CPUs integer quantity of virtual CPUs allocated to the VM, up to 16; although these are virtual and not strictly related to host processor cores, the host CPU might limit the maximum number; the operating system used in the VM might also have operational or licensing restrictions on the number of CPUs allowed
Memory Size (MiB) integer megabytes of RAM allocated to the VM
Boot Method drop-down menu UEFI for newer operating systems, or UEFI-CSM (Compatibility Support Mode) for older operating systems that only understand BIOS booting
Autostart checkbox when checked, start the VM automatically on boot

14.2. Adding Devices to a VM

After creating the VM, click it to select it, then click Devices and Add Device to add virtual hardware to it:

_images/vms-devices1.png

Fig. 14.2.1 Add Devices to a VM

Select the name of the VM from the VM drop-down menu, then select the Type of device to add. The following types are available:

  • Network Interface
  • Disk
  • Raw File
  • CD-ROM
  • VNC

Figure 14.2.2 shows the fields that appear when Network Interface is the selected Type.

_images/vms-nic1a.png

Fig. 14.2.2 VM Network Interface Device

The default Adapter Type emulates an Intel E1000 (82545) Ethernet card for compatibility with most operating systems. This can be changed to VirtIO to provide better performance when the operating system installed in the VM supports VirtIO paravirtualized network drivers.

If the system has multiple physical network interface cards, the Nic to attach drop-down menu can be used to specify which physical interface to associate with the VM.

By default, the VM receives an auto-generated random MAC address. To override the default with a custom value, enter the desired address into the MAC Address field.

VMs set to UEFI booting are also given a VNC (Virtual Network Computing) remote connection. A standard VNC client can connect to the VM to provide screen output and keyboard and mouse input.

Figure 14.2.3 shows the fields that appear when VNC is the selected Type.

_images/vms-vnc1.png

Fig. 14.2.3 VM VNC Device

The Resolution drop-down menu can be used to modify the default screen resolution used by the VNC session.

The VNC port can be set to 0, left empty for FreeNAS® to assign a port when the VM is started, or set to a fixed, preferred port number.

By default, VNC will bind to all available IP addresse (0.0.0.0). To specify the IP address to use, select it from the Bind to drop-down menu.

Check the Wait to boot checkbox to indicate that the VNC client should wait until the VM has booted before attempting the connection.

To automatically pass the VNC password, enter it into the Password field. Note that the password is limited to 8 characters.

To use the VNC web interface, check the VNC Web checkbox.

Tip

If a RealVNC 5.X Client shows the error RFB protocol error: invalid message type, disable the Adapt to network speed option and move the slider to Best quality. On later versions of RealVNC, select File Preferences, click Expert, ProtocolVersion, then select 4.1 from the drop-down menu.

Zvols are used as virtual hard drives. After creating a zvol, associate it with the VM by selecting Add device, choose the VM, select a Type of Disk, select the created zvol, then set the Mode. If a specific sector size is required, enter the number of bytes into Disk sectorsize. The default of 0 leaves the sector size unset.

_images/vms-disk1.png

Fig. 14.2.4 VM Disk Device

AHCI emulates an AHCI hard disk for best software compatibility. VirtIO uses paravirtualized drivers and can provide better performance, but requires the operating system installed in the VM to support VirtIO disk devices.

Adding a CD-ROM device makes it possible to boot the VM from a CD-ROM image, typically an installation CD. The image must be present on an accessible portion of the FreeNAS® storage. In this example, a FreeBSD installation image is shown:

_images/vms-cdrom.png

Fig. 14.2.5 VM CD-ROM Device

Note

VMs from other virtual machine systems can be recreated for use in FreeNAS®. Back up the original VM, then create a new FreeNAS® VM with virtual hardware as close as possible to the original VM. Binary-copy the disk image data into the zvol created for the FreeNAS® VM with a tool that operates at the level of disk blocks, like dd(1). For some VM systems, it is best to back up data, install the operating system from scratch in a new FreeNAS® VM, and restore the data into the new VM.

14.3. Virtual Serial Ports

VMs automatically include a virtual serial port.

  • /dev/nmdm1B is assigned to the first VM
  • /dev/nmdm2B is assigned to the second VM

And so on. These virtual serial ports allow connecting to the VM console from the Shell. To connect to the first VM:

cu -s 9600 -l /dev/nmdm1B

See cu(1) for more information on operating cu.

14.4. Running VMs

Select VMs to see a list of configured VMs. Configuration and control buttons appear at the bottom of the screen when an individual VM is selected with a mouse click:

_images/vms-control1.png

Fig. 14.4.1 VM Configuration and Control Buttons

The name, description, running state, VNC port (if present), and other configuration values are shown. A Start button is shown when the VM is not running. Click this to start the VM. If a VNC port is present, use VNC client software to connect to that port for screen output and keyboard and mouse input.

On running VMs, the button is shown as Stop, and used, unsurprisingly, to stop them.