Page Body

Virtualization With GNU/Linux

Virtualization refers to the creation of virtual versions of computing components. This can include hardware, software (programs or entire operating systems), storage devices, and computer resources. Virtualization can be offered on various hardware/software layers, e.g., Central Processing Unit (CPU), disk, memory, file systems.

On the host hardware, a piece of software, the hypervisor, creates virtual machines (VMs) that act as guests on the host system. The hypervisor may also be referred to as the virtual machine monitor (VMM).

Example hypervisors include:

Often, the hypervisor works with an emulator, a piece of hardware or software that enables the host to behave more like the guest. The emulator enables host systems to run software or use peripherals designed for guest systems.

Note: If you are not familiar with the GNU/Linux command line interface, review the Conventions page before proceeding.

Oracle VM VirtualBox

If you are not yet using GNU/Linux and want to experiment with several distributions, you can always create a live USB key with a tool like Etcher or Fedora Media Writer to do your testing with. However, you may desire a more convenient and complete system environment. Virtual machines are perfect vehicles for this kind of experimentation.

Oracle's VM VirtualBox is a Free/Libre open source (FLOSS), cross-platform solution for creating and managing virtual machines. The base package for VirtualBox is free (as in freedom), but specific functionality, like USB 3.0 support, requires a proprietary extension licensed under the Personal Use and Evaluation License.

VirtualBox can be installed on:

  • Windows
  • macOS
  • GNU/Linux
  • Solaris

Oracle makes a comprehensive user manual available online, but if you are looking for something simpler and brief, How-To Geek has a nice primer.

Kernel-Based Virtual Machine (KVM) and the Red Hat Virtual Machine Manager (virt-manager)

If you are already using GNU/Linux, relying on a non-native hypervisor like VirtualBox is not required. The Linux kernel comes with the Kernel-Based Virtual Machine (KVM) and there are software solutions available that can utilize it.

KVM and Quick Emulator (QEMU)

KVM is a full virtualization solution designed for GNU/Linux on x86 hardware (it has also been ported to S/390, PowerPC, IA-64, and ARM). It is FLOSS and supports various guest operating systems (e.g., GNU/Linux, BSD, Solaris, Windows, macOS).

KVM itself does not perform any emulation, but exposes the /dev/kvm interface. It is via this /dev/kvm interface that an external userspace host can perform emulation. The Quick Emulator (QEMU) is one such host.

Kernel-based Virtual Machine
"Kernel-based Virtual Machine.svg" by V4711 is licensed under a CC BY-SA 4.0 license

After it has access to the /dev/kvm interface, a usermode host like QEMU can use it to:

  • Set up a guest VM's address space. It supplies a firmware image that the guest can use to bootstrap its main operating system (OS).
  • Pass the guest simulated input/output (I/O).
  • Map the guest's video display back onto the system host.

KVM supports nested guests (i.e., running VMs within VMs), as well as overcommitting, which allows a host to allocate more virtualized resources (CPUs or memory) than the available physical resources on a system. KVM accomplishes overcommitting by dynamically swapping resources from another guest that is not using them.

KVM employs advanced security features and utilizes Security-Enhanced Linux (SELinux). In addition, it provides Mandatory Access Control (MAC) security between virtual machines.

virt-manager

The Red Hat Virtual Machine Manager (virt-manager) is a desktop virtual machine monitor. The virt-manager application is a graphical user interface (GUI) that can be used to manage virtual machines (domains) through libvirt. libvirt is an open source application programming interface (API), daemon, and management tool for handling platform virtualization.

libvirt
"Libvirt support.svg" by ScotXW is licensed under a CC BY-SA 3.0 license

virt-manager allows users to:

  • Create, edit, start, and stop VMs
  • View and control each VM's console
  • View running VMs and hosts, as well as their live performance and utilization statistics
  • Use wizards to create new VMs and configure each VMs resource allocation and virtual hardware
  • Manage Xen VMs and Linux Containers (LXC)

An embedded Virtual Network Computing (VNC) and Simple Protocol for Independent Computing Environments (SPICE) client viewer provides a full graphical console to guest operating systems.

virt-manager Console, virt-viewer
"console.png" by Daniel P. Berrangé is licensed under a GNU GPL v3+ license

virt-manager also offers several command line tools:

virt-install
Provides an easy way to provision operating systems into virtual machines.
virt-clone
For cloning existing inactive guests. It copies the disk images and defines a configuration with a new name, UUID, and MAC address pointing to the copied disks.
virt-xml
For easily editing libvirt domain XML using virt-install's command line options.
virt-bootstrap
Provides an easy way to set up the root file system for libvirt-based containers.

By default, you can create two kinds of virtual machines with virt-manager:

  1. QEMU/KVM: These VMs connect to the system libvirtd instance, i.e., the one launched by systemd. Here, libvirtd is running as root and has access to all host resources. VMs are launched as the unprivileged qemu user, but libvirtd can grant the VM selective access to root-owned resources.

    The daemon configuration file is located in /etc/libvirt, logs are stored in /var/lib/libvirt/, disk images are stored in /var/lib/libvirt/images/, and snapshots are stored in /var/lib/libvirt/qemu/snapshot/.

  2. QEMU/KVM User Session: These VMs connect to a session libvirtd instance running as the app user and the daemon is auto launched, if it is not already running. libvirtd and all VMs run as the app user.

    Configuration files and logs are stored in ${HOME}/, disk images are stored in ${HOME}/.local/share/libvirt/images/, and snapshots are stored in ${HOME}/.config/libvirt/qemu/snapshot/. Each system user will have their own qemu:///session VMs.

File Sharing

By default, you should be able to drag and drop a file system object from the host OS to the guest OS in the virt-manager console window. When using a graphical guest OS, the directory in the guest OS where the object was saved to should be automatically opened in a new window.

spice-vdagent

In order to have convenient features (e.g., automatic X-session resolution matching the client resolution, copy/paste sync between the active X-session and the client), the spice-vdagent needs to be running in the guest OS. If the guest OS is a GNU/Linux distribution, spice-vdagent may already be installed and running (e.g., Fedora). For other GNU/Linux distributions, you may need to install it from the distribution's repository (e.g., Debian, # apt install spice-vdagent).

If the guest OS is Windows, additional steps will need to be taken to get this working. First, you will need to download and install (direct download link) the latest spice guest tools for Windows in the Windows guest OS. Then, the following steps need to be taken for the Windows VM in virt-manager in the host OS:

  • Add Hardware > Channel
  • Set name to com.redhat.spice.0
  • Set device type to Spice agent (spicevmc)

libvrt and virsh

The virsh command is a command line interface (CLI) for managing guest domains (VMs) created through libvirt. It is part of of the libvirt API. Its syntax is:

virsh ex_command ex_domain

virsh has many options and commands, but here are a few of the most commonly used ones:

virsh list --all
List all inactive and active domains.
virsh start ex_domain
Start a (previously defined) inactive domain.
virsh shutdown ex_domain
Gracefully shut down a domain.

Documentation

virt-manager CLI command documentation can be viewed by running the following commands:

  • man 1 virt-install
  • man 1 virt-clone
  • man 1 virt-xml

For more on libvrt, check out its documentation. For more on virsh, run man 1 virsh at the command line, or view its man page online.

Enjoyed this post?

Subscribe to the feed for the latest updates.