Virtualization

Virtualization has been around for a long time:

  • 1960s for time sharing.
  • 1970s in mainframes
  • 1980s with the client/server boom
  • The dificulty of virtualizing x86 architecture led to a period of no virtualization.
  • 2005 - cpus added hardware support for viritualization, x86 can be virtualized

Question

Well this is confusing.. I thought virtualization was something the OS did to a process to gaslight it to think it had underlying hardware (CPU, memory)?

Answer

You’re right, but this is in the context of a sysadmin, the word is used to mean a different layer of virtualization in this context. In this case the kernel is being virtualized to think IT has soul access to underlying hardware. Finally someone is gaslighting the kernel, sweet justice.

LayerResourceGuestBook Context
OSCPU, memoryprocessOSTEP
Machinehardwarekernelsysadmin handbook

Virutalization Terms

Hypervisors

A hypervisor is a software layer that sits between virtual machines and the underlying hardware.

Hypervisors are responsibile for sharing system responses among the guest operating systems, which are isolated from one another.

Full virtualization

Fully emulate the underlying hardware so the OS truely thinks it’s runnnig on bare metal. This is hard to implement.

The most popular is open-source QEMU.

Paravirtualization

The Xen hypervisor introduced “paravirtualization,” in which modified guest operating systems detect their virtualized state and actively cooperate with the hypervisor to access hardware.

This approach improves performance by an order of magnitude or more. However, guest operating systems need substantial updates to run this way, and the exact modifications depend on the specific hypervisor in use.

Hardware-assisted virtualization

Note

Modern hypervisors: this is actually whats used by hypervisors to share cpu and memory controller

2004/2005 Intel and AMD introduced CPU features (Intel VT and AMD-V) that facilitate virtualization on the x86 platform. These extensions gave rise to “hardware-assisted virtualization”.

In this scheme, the CPU and memory controller are virtualized by the hardware, albeit under the control of the hypervisor.

Performance is very good, and guest operating systems need not know that they’re running on a virtualized CPU. These days, hardware-assisted virtualization is the assumed baseline.

Although the CPU is a primary point of contact between the hardware and guest operating systems, it is only one component of the system. So we still have to full emuate access to other parts of a computer.

Paravirtualized drivers

We’ve got Hardware-assisted virtualization so now hypervisors work, but some hardware still needs full emulation, which is slow. PV drivers to the rescue! The guest driver talks to the hypervisor through a shared-memory ring buffer instead of pretending to poke hardware registers (slow).

Type 1 vs Type 2 Hypervisors

  • Type 1 (proxmox, esxi) hypervisor runs directly on the hardware without a supoort OS, sometimes called a bare-metal hypervisor.
  • Type 2 (virutalbox, vmware workstation) hypervisors are user-space applications that run on top of another general-purpose OS.

hypervisors

Containerization

OS-level virtualiztion (containerization) doesn’t use a hypervisor, it uses kernel features that isolate processes from the rest of the system. Each group of processes “container” has a private file system and process namespace. They share the kernel and other services of the host OS.

Most impleminations offer native or near-native performance.

Linux LXC, Docker containers and FreeBSD jails are implementations of containers.

VMs and containers seem similar but their implemenations are completely different.

Virtual machineContainer
A full-fledged OS that shares underlying hardware through a hypervisorAn isolated group of processes managed by a shared kernel
Requires a complete boot procedure to initialize; starts in 1-2 minutesProcesses run directly by the kernel; no boot required; starts in < 1 second
Has one or more dedicated virtual disks attached through the hypervisorFilesystem view is a layered construct defined by the container engine
Complete isolation among guestsOS kernel and services shared with host
Multiple independent operating systems running side by sideMust run the same kernel as the host (OS distribution may differ)

A true VM has a OS kernel, init process, drivers to talk to hardware and the rest of a UNIX OS. A container just a facade of ann OS.

Virtualization with Linux

KVM

KVM is the kernel-based virtual machine integrated into the mainline Linux kernel, it is the leading virtualization project for Linux.

KVM takes advantage of the Intel VT and AMD-V CPU extensions and relies (in a typical setup) on QEMU to implement a fully virtualized hardware system.

Under KVM, the Linux kernel itself serves as the hypervisor. Memory management and scheduling are handled through the host’s kernel and guest machines are normal Linux processes

KVM guest installation

Definition

guest: is an abstraction in the os virtualization context, meaning an os running ontop of another OS or hypervisor.

You can use make different wrappers (like Proxmox, virsh, Vagrant (most of these use libvirt library as their api to talk to KVM )) around KVM (rather than using syscalls directly) to create VMs.

Heres an example installing ubuntu using virsh, the cli client for libvert C library.

Bash
sudo apt install -y cloud-image-utils

cd /var/lib/libvirt/images
printf '#cloud-config\npassword: test\nchpasswd: {expire: false}\nssh_pwauth: true\n' > /tmp/ud
sudo cloud-localds seed.iso /tmp/ud

sudo virt-install --name t1 --memory 2048 --vcpus 2 \
  --disk noble-server-cloudimg-amd64.img \
  --disk seed.iso,device=cdrom \
  --os-variant ubuntu24.04 --import --graphics none
sudo virsh -c qemu:///system
virsh # list --all
 Id   Name    State
------------------------
 3    t1      running
 -    win11   shut off

virsh # console t1
ubuntu@ubuntu           # connected!

ctrl + shift + ] # to exit

Virtualization Platforms

ESXI

ESXi, which is a bare-metal hypervisor for the Intel x86 architecture. The name stands for “Elastic Sky X, integrated” - you really can’t make this stuff up!

Vagrant

Also developed by HashiCorp, Vagrant is a wrapper that sits on top of virtualization platforms such as VMware, VirtualBox, and Docker. However, it is not itself a virtualization platform.

Vagrant simplifies virtual environment provisioning and configuration. Its mission is to quickly and easily create disposable, preconfigured development environments that closely mirror production environments.