All tutorials
  • #vm
  • #virtualization
  • #devops

VM 101: Virtual Machines From Zero

What a virtual machine is, in plain words: hosts, guests, hypervisors and why every cloud server is a VM. Then launch, explore and delete a real Ubuntu VM on your own machine.

Akshit Bansal8 min readTutorial 1

a computer inside your computer
on this page

In one minute

Virtual machine
  • A virtual machine (VM) is a computer made of software, running inside a real computer.
  • It has its own operating system, its own files and its own pretend hardware.
  • One real machine can run many VMs, each sealed off from the others.
  • Almost every cloud server you can rent (AWS EC2, Azure Virtual Machines, Google Compute Engine) is a VM.

Words you need

Read these once. Every one of them is used below.

  • Hardware

    The physical parts of a computer: the processor (CPU), memory (RAM), disk and network card.

    Like the body of a person

  • Operating system (OS)

    The main program that runs the computer and lets other apps use the hardware. Windows, macOS, Linux and Android are operating systems.

    Like the manager of a shop who gives every worker a desk and tools

  • Kernel

    The core of the operating system. It is the only part allowed to touch the hardware directly; every app has to ask it.

    Like the back office every request in the shop goes through

  • Host

    The real, physical computer that everything else runs on.

    Like the building

  • Guest

    The operating system running inside a VM. It believes it owns real hardware.

    Like a tenant in one flat of the building

  • Hypervisor

    The software that creates VMs, shares the real CPU, RAM and disk between them, and keeps them apart.

    Like a landlord who splits one building into flats

  • Virtualization

    Making one physical thing behave like several separate pretend ones.

    Like one big hall split into rooms with partition walls

  • Disk image

    One file that holds a VM's whole disk: the OS plus every file on it. Copy it and you have copied the computer.

    Like a full backup of a phone

  • Snapshot

    A saved moment of a VM that you can roll back to if you break something.

    Like a save point in a game

What a VM really is

Say you have a Windows laptop and need to try Linux. You can buy a second computer, wipe your laptop, or run Linux in a window on the laptop you already have. A VM is that third option.

Your laptop (the host)

VM 1

Appsa web server, a database
Guest OS: Ubuntu Linuxwith its own kernel

VM 2

Appsan old accounting tool
Guest OS: Windows 10with its own kernel
Hypervisorshares out the hardware, keeps VMs apart
Real hardwareCPU, RAM, disk, network card
One host, two guests. Each VM gets its own slice of the real hardware and its own OS.

What the guest gets is all pretend, but it behaves like the real thing:

  • Virtual CPU (vCPU)

    --cpus 2

    A share of the real processor's time. The guest sees it as a normal CPU.

  • Virtual memory

    --memory 4G

    A part of the host's RAM set aside for the VM while it runs.

  • Virtual disk

    .vdi .vmdk .vhdx .qcow2

    Just a big file on the host's disk. The guest thinks it is a whole drive.

  • Virtual network card

    NAT / bridged

    A pretend network port. The hypervisor connects it to the host's real network.

How a VM starts

  1. 01

    You ask for a VM

    2 CPUs, 4 GB RAM, 20 GB disk

  2. 02

    The hypervisor sets aside resources

    and creates the disk file

  3. 03

    It attaches an OS

    an installer (ISO) or a ready-made disk image

  4. 04

    The guest OS boots

    exactly like a real PC: kernel first, then services

  5. 05

    Apps run inside

    they never see the host

Two kinds of hypervisor

Type 1: bare metal

VM
VM
HypervisorESXi, Hyper-V, KVM, Xen
Hardware

Type 2: hosted

VM
VM
Hypervisor appVirtualBox, VMware Workstation
Host OSWindows, macOS, Linux
Hardware
Type 1 sits on the bare hardware. Type 2 is an app on your normal OS, so it has one more layer underneath.
Type 1 (bare metal)Type 2 (hosted)
Runs onDirectly on the hardwareAs an app on Windows, macOS or Linux
ExamplesVMware ESXi, Microsoft Hyper-V, KVM (built into Linux), XenOracle VirtualBox, VMware Workstation, Parallels Desktop
Who uses itData centres and cloud providersDevelopers and learners on laptops
SpeedFaster: no extra OS in betweenA bit slower: the host OS takes its share

How a VM reaches the network

ModeWhat happensUse it for
NAT (usual default)The VM goes out to the internet through the host. Other machines cannot reach the VM directly.Browsing, downloading, everyday use
BridgedThe VM joins your network like a separate device with its own IP address.When other devices must reach the VM
Host-onlyOnly the host and its VMs can talk to each other. No internet.Private test labs

Bare metal vs VM

Bare metal (no VM)Virtual machine
What it isOne OS directly on one physical machineMany OSes sharing one physical machine
SpeedFull speedClose to full speed with VT-x / AMD-V
Getting a new oneBuy and set up hardware: daysClick or one command: minutes
If it breaksRepair or reinstallRoll back to a snapshot, or delete and recreate
IsolationSeparate machinesStrong: each VM has its own kernel

Where VMs are used today

UseWhy a VM
Cloud serversRenting a slice of a big machine is cheaper than buying one
Trying another OSLinux on Windows, Windows on a Mac, without touching your main system
Hard security wallsEach VM has its own kernel, so a break-in stays inside one VM. Clouds separate customers this way
Old softwareIt needs one specific old OS that you can freeze in a VM
Under containersDocker Desktop, WSL 2 and most Kubernetes nodes run inside VMs
#GoodCosts
1Strong isolation: each VM has its own kernelA full OS in every VM: gigabytes on disk
2Any OS on any hostBoots in seconds to minutes
3Snapshots: break things, roll backEvery guest OS needs its own RAM first

Quick check: An Ubuntu VM runs on a Windows laptop. Which kernel do the Linux apps inside the VM use?

DIY walkthrough

You will launch a real Ubuntu VM with Multipass, a free tool from Canonical (the company behind Ubuntu), look inside it, and delete it.

Install Multipass

Multipass is Canonical's tool for quickly launching Ubuntu VMs. Its install page lists Windows 10 and 11 on Home, Pro and Enterprise as supported, from build 1809 up, and asks for the Virtual Machine Platform Windows feature to be enabled. You need administrator rights to run the installer. Download it from canonical.com/multipass (opens in a new tab). I did not verify which hypervisor driver it uses on Home, so if launch fails, see the troubleshooting section.

  1. Launch a VM and time it

    The first launch downloads an Ubuntu image, which takes a while. Launch is much quicker after that.

    bash
    multipass launch --name tutorial-vm --cpus 1 --memory 1G --disk 5Gmultipass list

    You should see

    After a download on the first run, multipass list shows tutorial-vm as Running with an IP address.
  2. Step inside

    bash
    multipass shell tutorial-vmuname -rfree -hdf -hexit

    Remember that kernel line. In Docker 101 you will see what a container reports instead.

    You should see

    Your prompt changes to ubuntu@tutorial-vm. uname -r prints a kernel version, free -h shows about 1 GB of memory, and df -h shows a disk of about 5 GB. This is a complete computer with its own kernel.
  3. Look at it from outside

    bash
    multipass info tutorial-vmmultipass exec tutorial-vm -- lsb_release -amultipass stop tutorial-vmmultipass listmultipass start tutorial-vm

    You should see

    multipass info shows the VM's state, IP address, memory and disk use. exec prints Ubuntu's release details without opening a shell. After stop, multipass list shows it as Stopped; after start, Running again.
  4. Throw it away

    bash
    multipass delete tutorial-vm --purgemultipass list

    You should see

    multipass list no longer shows tutorial-vm.

Troubleshooting

Multipass and virtual machines

multipass : The term 'multipass' is not recognized as the name of a cmdlet

Cause

Multipass is not installed, or this terminal was opened before the install and has an old PATH.

Fix

Close the terminal, open a new one and try multipass version. If it is still missing, run the installer again (Windows needs administrator rights).

multipass launch fails or hangs on Windows Home

Cause

Multipass lists Windows Home as supported but needs the Virtual Machine Platform Windows feature, and hardware virtualization, to be on. I could not verify the exact message you will see, so check these first.

Fix

Enable the feature from an administrator PowerShell, restart, and try again.

powershell
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

If it still fails, try another machine. The diagrams above show the same idea.

Next steps and sources