- #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 computeron 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
VM 2
What the guest gets is all pretend, but it behaves like the real thing:
Virtual CPU (vCPU)
--cpus 2A share of the real processor's time. The guest sees it as a normal CPU.
Virtual memory
--memory 4GA part of the host's RAM set aside for the VM while it runs.
Virtual disk
.vdi .vmdk .vhdx .qcow2Just a big file on the host's disk. The guest thinks it is a whole drive.
Virtual network card
NAT / bridgedA pretend network port. The hypervisor connects it to the host's real network.
How a VM starts
- 01
You ask for a VM
2 CPUs, 4 GB RAM, 20 GB disk
- 02
The hypervisor sets aside resources
and creates the disk file
- 03
It attaches an OS
an installer (ISO) or a ready-made disk image
- 04
The guest OS boots
exactly like a real PC: kernel first, then services
- 05
Apps run inside
they never see the host
Two kinds of hypervisor
Type 1: bare metal
Type 2: hosted
| Type 1 (bare metal) | Type 2 (hosted) | |
|---|---|---|
| Runs on | Directly on the hardware | As an app on Windows, macOS or Linux |
| Examples | VMware ESXi, Microsoft Hyper-V, KVM (built into Linux), Xen | Oracle VirtualBox, VMware Workstation, Parallels Desktop |
| Who uses it | Data centres and cloud providers | Developers and learners on laptops |
| Speed | Faster: no extra OS in between | A bit slower: the host OS takes its share |
How a VM reaches the network
| Mode | What happens | Use 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 |
| Bridged | The VM joins your network like a separate device with its own IP address. | When other devices must reach the VM |
| Host-only | Only 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 is | One OS directly on one physical machine | Many OSes sharing one physical machine |
| Speed | Full speed | Close to full speed with VT-x / AMD-V |
| Getting a new one | Buy and set up hardware: days | Click or one command: minutes |
| If it breaks | Repair or reinstall | Roll back to a snapshot, or delete and recreate |
| Isolation | Separate machines | Strong: each VM has its own kernel |
Where VMs are used today
| Use | Why a VM |
|---|---|
| Cloud servers | Renting a slice of a big machine is cheaper than buying one |
| Trying another OS | Linux on Windows, Windows on a Mac, without touching your main system |
| Hard security walls | Each VM has its own kernel, so a break-in stays inside one VM. Clouds separate customers this way |
| Old software | It needs one specific old OS that you can freeze in a VM |
| Under containers | Docker Desktop, WSL 2 and most Kubernetes nodes run inside VMs |
| # | Good | Costs |
|---|---|---|
| 1 | Strong isolation: each VM has its own kernel | A full OS in every VM: gigabytes on disk |
| 2 | Any OS on any host | Boots in seconds to minutes |
| 3 | Snapshots: break things, roll back | Every 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.
Download the installer from canonical.com/multipass (opens in a new tab) and run it. You need an account with administrator rights.
sudo snap install multipassLaunch a VM and time it
The first launch downloads an Ubuntu image, which takes a while. Launch is much quicker after that.
multipass launch --name tutorial-vm --cpus 1 --memory 1G --disk 5Gmultipass listYou should see
After a download on the first run, multipass list shows tutorial-vm as Running with an IP address.Step inside
multipass shell tutorial-vmuname -rfree -hdf -hexitRemember 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.Look at it from outside
multipass info tutorial-vmmultipass exec tutorial-vm -- lsb_release -amultipass stop tutorial-vmmultipass listmultipass start tutorial-vmYou 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.Throw it away
multipass delete tutorial-vm --purgemultipass listYou 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
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
Fix
Enable the feature from an administrator PowerShell, restart, and try again.
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatformIf it still fails, try another machine. The diagrams above show the same idea.
Next steps and sources
- Next: Docker 101, to see how containers skip the guest OS.
- Then Docker vs Kubernetes vs VM for the side-by-side comparison.
- Multipass docs: canonical.com/multipass (opens in a new tab)
- Background reading: the "Bare metal vs VMs vs containers" topic on the roadmap.sh Docker roadmap (opens in a new tab)
- Video this was planned around: Docker vs virtual machines (opens in a new tab) by IBM Technology