Why virtual machines

Several pretend computers can share one real one

THREE SERVERS, ONE JOB EACHMailmostly idleFilesmostly idleWeb sitemostly idleBars show how busy each is. Illustrative.ONE SERVER, THREE PRETEND COMPUTERS INSIDEMailits own systemFilesits own systemWeb siteits own systemone real machine, shared between thembetter used; two machines fewer to buy, power and coolA server with one job often sits mostly idle. A virtual machine is a pretend computer, so several can share one real one.Each still has its own operating system and cannot see the others, as if it were a separate box.The same trick lets a Windows laptop run Linux in a window, with no second machine.

A virtual machine is a pretend computer. Several share one real machine that would otherwise sit idle.

Three ways to run software

A virtual machine brings its own operating system

Bare metalone system owns the hardwareVirtual machineseach has its own operating systemContainersall share one operating systemHardwareOperating systemApplicationsHardwareHypervisorGuest OSGuest OSGuest OSAppAppAppHardwareOperating systemContainer engineApp + libsApp + libsApp + libsA virtual machine brings its own operating system. A container shares the host's.Virtualisation lets one physical machine do the work of many. The hypervisor gives each virtual machinewhat looks like its own processor, memory, drive and network card. A container is lighter: an isolatedgroup of processes on a kernel it shares with its neighbours.

A virtual machine has its own operating system. A container shares the host's.

Hypervisors

A hypervisor runs on the hardware, or on an operating system

Type 1: on the hardwareVMware ESXi, Microsoft Hyper-V, KVM, ProxmoxHardwareHypervisorVirtual machineVirtual machineVirtual machineType 2: on an operating systemVirtualBox, VMware Workstation, ParallelsHardwareHost operating systemHypervisorOther programsVirtual machineVirtual machineType 1 is the machine's only job. Type 2 is a program on a computer you also use.Servers and clouds run type 1 for speed and isolation. Type 2 suits a technician's own laptop: a testmachine in a window. Both need the processor's virtualisation support (Intel VT-x or AMD-V) switched onin firmware, and enough memory for every system running at once.

Type 1 runs directly on the hardware. Type 2 is a program on your own system.

Hypervisors · Going deeper

Virtual network modes

Network modeThe virtual machine can reachUse it forBridgedthe same network as the host, with its own addressservers that others must reachNATthe outside world, through the host's addresseveryday use; the usual defaultHost-onlyonly the host and its other virtual machinesclosed test labsNonenothingexamining suspect filesThe network mode decides what a virtual machine can touch, and what can touch it.A virtual machine is a full computer on the network. It needs its own updates, its own protection andits own licence, exactly like a physical one.

Bridged joins the network. NAT hides behind the host. Host-only stays inside.

Sharing a host

Processor time can be promised twice. Memory cannot.

Physical cores16Virtual processors promisedWeb 4Database 8Files 4Test 824: 1.5 to 1Physical memory64 GBMemory promisedWeb 8Database 32Files 8Test 856 GB: 8 GB left for the hostProcessor time can be promised more than once. Memory cannot.Most machines idle most of the time, so 24 virtual processors share 16 cores without trouble. Memory is heldwhether it is used or not, so the total must fit, with some left for the host. A host that runs out ofmemory slows every machine on it.

Virtual processors may exceed the cores. Memory must fit.

Snapshots

A snapshot freezes the disk and records changes beside it

The virtual disk: one file of 60 GB, to scaleBeforeread and writtenSnapshot takenfrozen: read only from now onchanges: 0 GBA week laterchanges: 6 GBRevertchanges discardedA snapshot freezes the disk and writes every later change to a separate file.Reverting throws the changes away, which makes a snapshot ideal before a risky update. It is not a backup:it lives on the same storage as the machine, and it grows until it is deleted. Because a virtual machineis only files, it can also be copied (cloned), moved to another host, or backed up whole.

After a snapshot, changes go to a separate file. Reverting discards them.

Containers

A container carries the application, not a kernel

A container image, in layersYour applicationRuntime and librariesBase system files, no kernelThe host's kernel, sharedDisk space before any application is added, to scaleAlpine container image8 MBUbuntu container image78 MBWindows 11 virtual machine64 GB at leastA container carries an application and its libraries, but no kernel.So it is megabytes where a virtual machine is gigabytes, and it starts in about a second. The price isweaker isolation, since all containers share one kernel, and a tie to that kernel: Linux containers needLinux. Docker on Windows or macOS quietly runs them inside a small Linux virtual machine.

An image holds the application and its libraries. The kernel is the host's.

Choosing

Choose by what must be kept apart

The needUseBecauseRun a Windows-only program on a MacVirtual machineit needs a whole different operating systemOpen a suspicious file safelyVirtual machine, no networka sandbox: revert the snapshot afterwardsKeep old software that needs Windows 7Virtual machinethe old system stays walled offTry an update before everyone gets itClone or snapshottest on a copy, and undo if it failsGive staff a desktop from the data centreVirtual desktops (VDI)data never leaves; any device will doShip a service that runs the same anywhereContainersmall, quick and identical everywhereChoose by what must be kept apart: a whole operating system, or one application.A virtual machine is a complete computer, and must be patched, protected and licensed like one. Forgottenvirtual machines, left running and unpatched, are a common way in for attackers.

A different operating system needs a virtual machine. A portable application suits a container.

Lesson complete

You finished “Virtual machines and containers”

Nicely done.

Open in a new tab