Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Answer

A virtual machine (VM) is a complete computer built in software. It has its own processors, memory, disks, and network cards, all provided from a real machine, and it runs its own operating system with its own kernel. Many VMs can run side by side on one physical server, and each behaves as if it had the machine to itself.

The software that creates and runs VMs is the hypervisor; see what is a hypervisor. The physical machine is called the host, and each VM is a guest.

What the Hypervisor Does

  • Divides the hardware: it gives each VM a share of processor time, a block of memory, and space on storage.
  • Keeps guests apart: one VM cannot read another's memory or disks.
  • Presents virtual devices: the guest sees a disk controller and a network card and loads drivers for them, as on real hardware.
  • Starts, stops, and moves VMs: a VM can be powered off, resized, or copied without touching the physical machine.

On Linux the usual hypervisor is KVM, which is part of the kernel itself; see what is KVM virtualization.

The Virtual Hardware

PartInside the VM
CPUVirtual CPUs (vCPUs)
MemoryA set amount of RAM
DiskAn image file or volume
NetworkA virtual network card
ConsoleA virtual screen and keyboard

A vCPU is scheduled on a thread of the host's processor; what is a vCPU explains how that compares with a physical core. The disk is usually one large file or a volume on the host's storage, which is why VMs are easy to copy and move.

Images, Templates, and Snapshots

Because a VM's disk is data on the host, it can be handled like data. An image is a prepared disk with an operating system already installed. A new VM starts from a copy of it in moments, and a tool such as cloud-init sets the host name, users, and SSH keys on the first boot. A snapshot records the disk at one moment so that a failed change can be undone. A snapshot is not a backup, as explained in snapshot vs backup.

VM vs Physical Server

Virtual machinePhysical server
HardwareA share of a hostAll of it
SetupMinutesHours to days
ResizeChange settings, restartAdd or swap parts
NeighborsOther VMs on the hostNone

A physical server rented whole is called a dedicated or bare metal server; see what is a bare metal server.

A VPS and a Cloud Server Are Virtual Machines

A virtual private server is a VM on a provider's host, with root access for you; see what is a VPS. A cloud server is also a VM. The word "cloud" usually means that the hosts form a pool, so a VM can be started on, or moved to, another host. What is a cloud server covers the difference. From inside, all of them look like an ordinary Linux machine.

Check Whether You Are in a VM

systemd-detect-virt

It prints the name of the hypervisor, such as kvm, or none on physical hardware. Inside a container it names the container technology instead; systemd-detect-virt --vm looks only for a VM. Inside a VM, lscpu also shows a "Hypervisor vendor" line, and sudo dmidecode -s system-product-name shows the machine model that the hypervisor reports.

Overhead and Paravirtual Drivers

Modern processors run guest code directly, so pure computation in a VM is close to native speed. Disk and network input and output cost more, because each request passes through the hypervisor. Paravirtual devices reduce that cost: the guest knows it is virtual and talks to the host through a lean interface instead of an emulated piece of hardware. On KVM these are the VirtIO drivers; see VirtIO drivers. On a busy host, time when your vCPU waits for a real one shows up as CPU steal time.

A Container Is Not a VM

A container isolates processes but runs on the host's kernel, while a VM boots a kernel of its own; see what is a container. The wider idea behind both is covered in what is virtualization.

Was this answer helpful?
Loading...