A virtual machine (VM) is a software-based computer that exists within another computer’s operating system, often used for the purposes of testing, backing up data, or running SaaS applications. To fully grasp how VMs work, it’s important to first understand how computer software and hardware are typically integrated by an operating system.
Traditional computers are built out of physical hardware, including hard disk drives, processor chips, RAM, etc. In order to utilize this hardware, computers rely on a type of software known as an operating system (OS). Some common examples of OSes are Mac OSX, Microsoft Windows, Linux, and Android.
The OS is what manages the computer’s hardware in ways that are useful to the user. For example, if the user wants to access the Internet, the OS directs the network interface card to make the connection. If the user wants to download a file, the OS will partition space on the hard drive for that file. The OS also runs and manages other pieces of software. For example, it can run a web browser and provide the browser with enough random access memory (RAM) to operate smoothly. Typically, operating systems exist within a physical computer at a one-to-one ratio; for each machine there is a single OS managing its physical resources.
Some users want to be able to run multiple operating systems simultaneously on one computer, either for testing or one of the other reasons listed in the section below. This can be achieved through a process called virtualization. In virtualization, a piece of software behaves as if it were an independent computer. This piece of software is called a virtual machine, also known as a ‘guest’ computer. (The computer on which the VM is running is called the ‘host’.) The guest has an OS as well as its own virtual hardware.
‘Virtual hardware’ may sound like a bit of an oxymoron, but it works by mapping to real hardware on the host computer. For example, the VM’s ‘hard drive’ is really just a file on the host computer’s hard drive. When the VM wants to save a new file, it actually has to communicate with the host OS, which will write this file to the host hard drive. Because virtual hardware must perform this added step of negotiating with the host to access hardware resources, virtual machines can’t run quite as fast as their host computers.
With virtualization, one computer can run two or more operating systems. The number of VMs that can run on one host is limited only by the host’s available resources. The user can run the OS of a VM in a window like any other program, or they can run it in fullscreen so that it looks and feels like a genuine host OS.
Some of the most popular reasons people run virtual machines include:
Several cloud providers offer virtual machines to their customers. These virtual machines typically live on powerful servers that can act as a host to multiple VMs and can be used for a variety of reasons that wouldn’t be practical with a locally-hosted VM. These include:
Cloudflare helps protect and manage any type of cloud deployment, including cloud VMs. Additionally, for users who want the functionality of running code on the edge without all the overhead of virtual machines, we have Cloudflare Workers, a serverless platform that provides edge computation to customers in a completely scalable way, allowing developers to augment existing applications or create entirely new ones without configuring or maintaining infrastructure.