{"canonical_url":"https://engineer.company/glossary/virtual-machine/","content_markdown":"# virtual machine\n\n## What it is\n\nA virtual machine presents a whole computer through software: processors, memory,\ndisks and network cards supplied by a virtualization layer on a physical host,\nwith an operating system booting on them as if they were dedicated hardware.\nIt is often shortened to VM. Some devices can be passed through from the host\nrather than emulated. NIST's guide to full virtualization, SP 800-125, defines it in\none line as “A simulated environment created by virtualization.” In the kind of\nvirtualization that guide covers, one or more operating systems run, together\nwith their programs, on virtual hardware, each in a VM of its own, where it is\ncalled a guest operating system.\n\nTwo words do most of the work around it. The real machine is the host and each\nvirtual one is a guest. The program that divides the host between its guests is\nthe hypervisor, also called the virtual machine monitor, which SP 800-125\ndescribes as the component that manages the guest operating systems on a host\nand controls the flow of instructions between them and the physical hardware:\nprocessor, disks, memory and network cards. The same guide names the two things\nthat make the arrangement useful. The hypervisor can split the host's resources\nso that each guest reaches its own allocated resources and any explicitly shared\nresources, and a guest can be wrapped up\ncompletely, which makes it portable from one host to another.\n\nA virtual machine differs from a container in where the line is drawn. A\ncontainer is a process on its host's kernel with a restricted view of the\nsystem. A virtual machine boots a kernel of its own on hardware that the\nhypervisor presents to it. That is why a Linux guest can run on a Windows or\nmacOS host, and also why every guest needs an operating system of its own,\ninstalled, patched and given enough memory to run.\n\n## Why it matters\n\nA server rented from a cloud provider is usually a virtual machine, and\ninfrastructure as a service is built on them. The provider runs the hypervisors\nand the physical fleet; the customer gets machines that can be created, resized\nand destroyed through an API instead of being ordered, delivered and racked. The\nhardware stays someone else's problem while the operating system becomes the\ncustomer's.\n\nIsolation is the second reason. The KVM project page says each virtual machine\nhas private virtualized hardware, with its own network card, disk and graphics\nadapter. Guests share no kernel, so a kernel crash or a bad update inside one\nguest stays inside it, and it is the hypervisor, not the guests, that decides\nwhat reaches the physical hardware. Two customers, or two environments of one\ncustomer, can share a physical machine without sharing an operating system.\n\nThird, with image-backed storage, a machine can become a set of files. A guest's\ndisk can be an image file on the host, which can be copied, kept as a template or used to start several\nidentical machines. QEMU's qcow2 format can record only the differences from a\nbase image and can store snapshots of the disk inside the same file, so one\ntemplate plus a thin layer per guest is a natural layout.\n\nFourth, emulation lets software built for one family of processors run on\nanother. In QEMU's system emulation, the guest operating system runs on a\nmachine modelled in software, with its own processor, memory and devices. With\nan accelerator, such as KVM on Linux, Hypervisor Framework on macOS or Windows\nHypervisor Platform on Windows, the host processor's virtualization support does\nthe heavy lifting. Without one, QEMU's Tiny Code Generator translates the\nguest's instructions in software, which is how the QEMU introduction's own\nexample boots an Arm64 machine with `-accel tcg`.\n\nThe cost is that every guest is a full computer to look after. Each carries its\nown operating system to patch, its own reserved memory and its own boot.\nContainers avoid that by sharing the host's kernel, which makes each one lighter\nand gives up a separate kernel as the wall between workloads. Choosing between\nthem means choosing where that wall should stand.\n\n## What it looks like in practice\n\nOn x86 Linux the usual pair is KVM and QEMU. KVM is the kernel half: a loadable\nmodule, `kvm.ko`, with a processor-specific companion, `kvm-intel.ko` or\n`kvm-amd.ko`, included in mainline Linux since 2.6.20. It needs the processor's\nvirtualization extensions, Intel VT or AMD-V. The KVM FAQ checks for their\nflags, `vmx` and `svm`, in `/proc/cpuinfo`, and its troubleshooting list\nincludes confirming that `/dev/kvm` exists and that the user has the rights to\nopen it:\n\n```sh\ngrep -E -c '^flags.*(vmx|svm)' /proc/cpuinfo\nls -l /dev/kvm\n```\n\nA count above zero means the processor reports the extensions. QEMU is the\nuser-space half, which builds the machine around KVM. The disk for a new guest\ncan be a thin layer on a shared base image:\n\n```sh\nqemu-img create -f qcow2 -b debian-base.qcow2 -F qcow2 web1.qcow2\nqemu-img info --backing-chain web1.qcow2\n```\n\nThe qemu-img manual says an image created with a backing file records only the\ndifferences from it, and that the backing file is never modified unless those\ndifferences are committed back into it. The second command lists every file in\nthe chain, which is worth reading before anything is moved or deleted. Starting\nthe guest then looks like this:\n\n```sh\nqemu-system-x86_64 -accel kvm -m 2G -smp 2 \\\n    -drive file=web1.qcow2,if=virtio,format=qcow2 \\\n    -nographic\n```\n\n`-accel kvm` hands the processor work to KVM, through `/dev/kvm` by default.\n`-m` sets the guest's memory and `-smp` its number of processors. On `-drive`,\n`if=virtio` attaches the disk on the virtio interface, one of the interface\ntypes the manual lists, and `format=qcow2` names the format instead of leaving\nQEMU to detect it. `-nographic` turns off the graphical window, so QEMU becomes\na plain command-line program with the guest's serial console in the terminal,\nshared with the QEMU monitor; Ctrl-a h shows how to switch between the two.\n\nWith the guest shut down, the same tool takes and restores snapshots of the\ndisk. `-c` creates one, `-l` lists them and `-a` reverts the disk to a saved\nstate:\n\n```sh\nqemu-img snapshot -c before-upgrade web1.qcow2\nqemu-img snapshot -l web1.qcow2\nqemu-img snapshot -a before-upgrade web1.qcow2\n```\n\nSizing is a design decision rather than a form field. The portfolio entry on\n[running the company's public services on one small server](/portfolio/a-whole-company-on-one-small-server/)\ndocuments a September 2026 setup with one processor core, a 10 GB disk and 512 MB of memory, of which\nprograms can use roughly 464 MB. That host serves seven domains over TLS and\nalso runs the git forge, with backup automation implemented separately; memory\nis the limit every design choice there answers to. Whether it could take an\nonion service on Tor as well was decided by a recorded day of samples, in which\nthe lowest reading of available memory was around 310 MB. Every guest's `-m`\nsetting poses the same question, and a measurement answers it better than a\nbigger plan does.\n\nThe entry on\n[managing thirty Ubuntu Linux VPS instances](/portfolio/managed-30-ubuntu-linux-vps-instances/)\nshows the other end of the scale. The setup of those instances had accumulated\nover the years instead of being designed, and their configurations had drifted\napart. From then on they were run as a single fleet: one hardened network\nconfiguration on every instance, and restores that were tried out rather than\ntaken on trust.\n\n## Where it goes wrong\n\nMost trouble with virtual machines comes from forgetting that each one is a real\ncomputer to look after, and that an image-backed disk is also an ordinary file on another\nmachine.\n\n**KVM is missing when the guest starts.** In the x86 setup above, absent or\nfirmware-disabled processor extensions prevent KVM acceleration and `/dev/kvm`\nmay be absent, so a guest started with `-accel kvm` stops at once. The KVM FAQ warns\nthat some manufacturers disable VT in the BIOS in a way that cannot be\nre-enabled. The fix is to run the flag check above, look for a firmware option\nthat enables virtualization, and confirm that `/dev/kvm` exists and belongs to a\ngroup the user is in; the FAQ suggests a group called `kvm`.\n\n**A guest started without a memory size gets 128 MiB.** That is QEMU's default\nfor `-m`, and it applies whatever the host has free, so a guest can start, then\nfail in ways that look like bugs in the software inside it. The fix is to set\n`-m` and `-smp` every time and size them from measurement, the way the\nsmall-server entry settled its onion-service question with a day of\nmeasurements.\n\n**An image changed while the guest runs can be destroyed.** The qemu-img manual\nis blunt: editing an image while a guest or another process has it in use can\ndestroy that image. Taking a snapshot of a live guest's disk with\n`qemu-img snapshot -c` is exactly that. The fix is to shut the guest down before\nqemu-img touches its disk, and to make that a step in every runbook that does.\n\n**Snapshots stand in for backups.** Snapshots made with qemu-img live inside the\nsame image file, which `qemu-img info` shows by listing them alongside the disk.\nWhen the file is lost or damaged, every snapshot goes with it. The fix is to\ncopy backups to storage on another machine and to test the restore, because a\nrestore that has never been run proves nothing.\n\n**A base image changes or moves under its overlays.** A thin image holds only\ndifferences, so it means nothing without the exact base it was made against. The\nmanual warns that changing the backing file in unsafe mode corrupts the\nguest-visible content if the new file is the wrong one, and a relative backing\npath is resolved from the overlay's own directory, so moving one file without\nthe other breaks the chain. The fix is to treat base images as read-only and\ngive each new version a new name, to read `qemu-img info --backing-chain` before\nmoving anything, and to run `qemu-img commit` only deliberately, since it writes\ninto the base and empties the overlay.\n\n**The disk format is guessed from the image itself.** Without `format=`, QEMU\ndetects the format from the contents of the file, and the manual recommends\n`format=raw` to avoid interpreting an untrusted format header. An image\ndownloaded from elsewhere, or one a guest has written to, is untrusted in\nexactly that sense. The fix is to name the format on every `-drive` line.\n\n**Every guest drifts into a pet.** Machines configured by hand drift apart one\nchange at a time until no two are alike, which is where the VPS fleet above\nstood before it came under management. The fix is to build every guest from the\nsame image and the same configuration, keep that configuration in version\ncontrol, and manage the machines as one fleet with one baseline.\n\n## Further reading\n\n- [Guide to Security for Full Virtualization Technologies (NIST SP 800-125)](https://csrc.nist.gov/pubs/sp/800/125/final)\n  — the VM definition, the hypervisor's job and how guests are kept apart.\n- [KVM](https://linux-kvm.org/page/Main_Page)\n  — the project page: modules, processor extensions and mainline version.\n- [KVM FAQ](https://linux-kvm.org/page/FAQ)\n  — the vmx and svm check, `/dev/kvm` permissions and the BIOS setting.\n- [QEMU System Emulation introduction](https://www.qemu.org/docs/master/system/introduction.html)\n  — the accelerators, the Tiny Code Generator and a full example command.\n- [QEMU invocation](https://www.qemu.org/docs/master/system/invocation.html)\n  — every option used above: `-accel`, `-m`, `-smp`, `-drive`, `-nographic`.\n- [QEMU disk image utility](https://www.qemu.org/docs/master/tools/qemu-img.html)\n  — qcow2, backing files, snapshots and the warning about images in use.\n\n\u003chttps://engineer.company/glossary/virtual-machine/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"What a virtual machine is, how a hypervisor shares one physical computer between several, how KVM and QEMU start one, and where it goes wrong.","formats":{"gemtext":"https://engineer.company/glossary/virtual-machine/index.gmi","gopher":"https://engineer.company/glossary/virtual-machine/gophermap","html":"https://engineer.company/glossary/virtual-machine/","json":"https://engineer.company/glossary/virtual-machine/index.json","markdown":"https://engineer.company/glossary/virtual-machine/index.md","pdf":"https://engineer.company/glossary/virtual-machine/index.pdf"},"kind":"page","language":"en","title":"What is a virtual machine?","url":"https://engineer.company/glossary/virtual-machine/","version":1}