Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

7.4 (1 of 2): Virtual machines and hypervisors

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

A computer inside a computer

You want to test a risky program. You do not want to harm your laptop. So you make a second computer inside the first one. You try the program. Then you delete the second computer, and your laptop is not changed.

This is a virtual machine: a computer made of software. People use it everywhere, from small labs to very large data centres. A data centre is a building full of servers.

Key words

WordWhat it meansExample
Virtual machineA computer made of software, running inside a real one.A Windows computer inside a laptop
VirtualisationMaking a computer, or its parts, in software.Ten servers on one machine
HostThe real computer that runs the virtual machines.A powerful server
GuestA virtual machine running on a host.One virtual server
HypervisorSoftware that runs virtual machines and shares the host's parts between them.The software that starts each guest
Operating systemThe main program that runs a computer.Windows, Linux
CPUThe processor, which runs a program's instructions.The brain of a computer
NetworkComputers joined to share data.The college network
RouterA device that joins networks and sends data the right way.A home router
SnapshotA saved copy of a virtual machine at one moment, to go back to later.Before a risky change
EmulationMaking one computer act like a different one.An old games console on a laptop

The cells students fill in are left blank in this preview.

Match the word to its meaning

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Type 1 and type 2

flowchart TB
  subgraph T1["Type 1: runs on the hardware"]
    hw1["Hardware"] --> hy1["Hypervisor"] --> g1["Guest 1"]
    hy1 --> g2["Guest 2"]
  end
  subgraph T2["Type 2: runs on an operating system"]
    hw2["Hardware"] --> os2["Host operating system"] --> hy2["Hypervisor program"] --> g3["Guest 3"]
    hy2 --> g4["Guest 4"]
  end

A whole network can be virtual

A virtual machine can be a client, such as a virtual PC for a student. It can also be a server, such as a web server.

The network parts can be virtual too. A virtual switch joins virtual machines together. A virtual router joins virtual networks. So a whole network, with computers, switch and router, can live inside one real computer.

Type 1 and type 2 compared

Type 1 (no operating system below it)Type 2 (hosted)
Runs onDirectly on the hardwareOn a normal operating system
SpeedFaster: fewer layersSlower: more layers
Used forData centres and serversLaptops, learning and testing
ExampleA server in a data centreA student laptop

The cells students fill in are left blank in this preview.

Quick check

Have a go

Quick check

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Extra: Real hypervisors

Type 1 (bare metal)Type 2 (hosted)
KVM, Xen, Hyper-V, VMware ESXiVirtualBox, VMware Workstation, Parallels

The cells students fill in are left blank in this preview.

Extra: Ask this lab what it is

Command
systemd-detect-virt

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: How many virtual CPUs?

Command
nproc

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: How much memory does it have?

Command
free -m | head -2

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: You are inside a virtual machine

Note

The lab you are using is a virtual machine. The first command named the hypervisor technology that this lab runs on. The numbers you saw are the small share of CPU and memory the host gave to this guest.

Seven key features

FeatureWhat it meansExample
Increased securityRisky work stays inside the virtual machineOpen a suspicious file in a VM
Managed executionThe hypervisor controls and can pause, save or move a VMPause a VM and take a snapshot
SharingMany VMs share the parts of one real computerTen VMs on one server
AggregationMany real machines are joined and shown as one big shared amount (a pool)A group of hosts that gives one big pool of memory
EmulationA VM can act like different hardware or another systemRun an old program on a new computer
IsolationA problem in one VM does not reach the othersOne VM crashes, the other VMs keep working
PortabilityA VM is a set of files, so you can copy or move itMove a VM to a new host

The cells students fill in are left blank in this preview.

Which feature is it?

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Try it: sharing one host

Code: python
# A host has 8 CPUs and 16 GB of memory. Each VM takes a share.
cpus_left = 8
gb_left = 16
names = ["web", "mail", "files"]
cpus = [2, 2, 2]
gbs = [4, 4, 8]

for i in range(3):
    cpus_left = cpus_left - cpus[i]
    gb_left = gb_left - gbs[i]
    print(names[i], "started. Left:", cpus_left, "CPUs and", gb_left, "GB")

# Add a fourth VM: put "games" in names, 2 in cpus, 4 in gbs.
# Change range(3) to range(4) and run it. Does it fit?

Make a free account to save your work and track your progress.

Your turn: will they fit?

A host has some CPUs and some gigabytes of memory. Each virtual machine needs some CPUs and some memory.

  1. Write can_host(vm_cpus, vm_gb, host_cpus, host_gb). The first two are lists, one number for each virtual machine.
  2. Add up the CPUs and the memory of all the virtual machines.
  3. Give back True if they all fit on the host. Give back False if not. Exactly full is fine.

Press Run Tests to check.

Code: python
def can_host(vm_cpus, vm_gb, host_cpus, host_gb):
    # vm_cpus is a list: the CPUs each virtual machine needs.
    # vm_gb is a list: the gigabytes of memory each virtual machine needs.
    # Give back True if the host has enough CPUs and enough memory for all of them together.
    return False

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Final check

Have a go

Final check

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.