What is a virtual machine? Explained with flats in one building
A virtual machine is a whole computer made of software, with its own operating system, running on a share of a real server. Like a separate flat inside one building.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- DevOps
In one sentence: A virtual machine is a complete computer made of software, with its own operating system and apps, that runs on a share of a real computer's processor, memory and storage, walled off from the other virtual machines on the same machine.
The everyday picture
Think of a large building split into separate flats. There is one roof, one set of foundations and one water and power supply. But each flat has its own front door, its own kitchen and its own lock.
The tenants in one flat cannot walk into the next one. One tenant can paint the walls, rearrange the furniture or leave the lights on without touching anyone else. A building manager decides how much space and power each flat gets.
Virtual machines work the same way. One physical computer, usually a server, is the building. Each virtual machine is a flat inside it.
The hypervisor (building manager) shares out one server's hardware into separate virtual machines (flats). Each runs its own operating system, walled off from its neighbours.
How it works, step by step
- The physical server (the building) has real hardware: processors, memory, disks and network cards. This hardware still does all the actual work.
- The hypervisor (the building manager) is a layer of software that pools that hardware and hands out portions of it. Red Hat describes it as software that pools computing resources and reallocates them among virtual machines.
- Each virtual machine (a flat) is given its own set share of processing power, memory and storage. To the software inside, it looks and behaves like a whole computer of its own.
- Each virtual machine runs its own operating system (its own kitchen), called the guest operating system. One flat can run Windows and the next can run Linux, side by side on the same server.
- Apps run inside the flat. If one virtual machine crashes or gets infected, the walls keep the problem inside it, and the others carry on.
Try it · Side by side
Own flat or shared kitchen: virtual machine or container?
Tap what matters to you (pick one or more) and see which option fits.
Virtual machine
- Each has its own full operating system, managed by the hypervisor
- Boots a whole operating system, so it is heavier
- Each can run a different operating system
- Each copy needs its own operating system
- The old system can live on inside its own machine
Container
- Shares the host's operating system core, so the walls are thinner
- Carries only the app and what it needs, so it starts quickly
- Must match the kind of operating system core it runs on
- Many copies can share one host and use less memory
- Not every app can be packed into a container easily
Pick what matters to you and the better fit lights up.
Where the picture stops
- A flat cannot be picked up and carried away. A virtual machine is stored as files, often called an image, so it can be copied, backed up or moved to a hypervisor on another server.
- Flats have fixed walls. A virtual machine's share of processor, memory and storage is set in software, so it can be made bigger or smaller far more easily than knocking down a wall.
- A dishonest building manager could open every door. In the same way, if the hypervisor itself is hacked, Red Hat warns that this can cause problems for all of the virtual machines on that server.
Why it matters for your business
- Lower hardware cost: several half-idle servers can become virtual machines on one machine. Microsoft lists a smaller physical footprint and lower maintenance and electricity costs among the benefits.
- Faster recovery: because a virtual machine is a set of files, it can be backed up and started again on another server if its host fails.
- Old and new side by side: an old app that needs an older operating system can live in its own virtual machine, next to modern systems on the same hardware.
- A risk to manage: every virtual machine has its own operating system, and each one needs security updates. AWS calls patching them a critical security activity.
An example
Imagine a 30-person architecture firm with three ageing servers in a cupboard. One runs file sharing, one runs the accounts software, and one runs an old drawing-licence tool that only works on an older version of Windows.
The firm buys one newer server and installs a hypervisor on it. Each old server becomes a virtual machine: three flats in one building. The old licence tool keeps its older Windows inside its own flat, cut off from the rest. Every night, copies of all three virtual machines are saved, so if the new server fails, they can be started on another machine or in the cloud.
Frequently asked questions
What is the difference between a virtual machine and a container?
A virtual machine has its own full operating system, like a flat with its own kitchen. Containers share the host's operating system core, which makes them lighter and faster to start, but less strongly separated.
What is a hypervisor?
It is the software that creates and runs virtual machines and shares out the real hardware between them. It is also called a virtual machine monitor.
Can I run a virtual machine on my own laptop?
Yes. Tools such as Oracle VirtualBox or VMware Workstation run as an ordinary app on your laptop's operating system. These are called type 2, or hosted, hypervisors. Servers usually use type 1 hypervisors, which run directly on the hardware.
Is a cloud server a virtual machine?
Very often, yes. When you rent a server from a cloud provider such as AWS or Microsoft Azure, you usually get a virtual machine on the provider's hardware, shared with other customers but walled off from them.
Related explainers
The DevDrift sets up cloud hosting and deployments for web platforms: see how.
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.