A Virtual Machine (VM) is a software-based emulation of a physical computer that can run an operating system and applications as if they were running on physical hardware.
Definition
A virtual machine provides an environment that is logically separated from the underlying physical hardware. The hardware elements (CPU, memory, storage, network) presented to the VM are abstract and virtualized, allowing multiple VMs to share physical resources while maintaining isolation.
Key Components
Hypervisor (Virtual Machine Monitor)
The hypervisor is the software layer that enables the creation and management of virtual machines:
- Type 1 Hypervisors: Run directly on hardware (bare-metal)
- Examples: VMware ESXi, Microsoft Hyper-V, Xen, KVM
- More efficient, commonly used in data centers and cloud environments
- Type 2 Hypervisors: Run on top of a host operating system
- Examples: VMware Workstation, Oracle VirtualBox, QEMU
- Common for desktop virtualization and development environments
Guest Operating System
The operating system that runs inside the VM, which can be different from the host system.
Virtual Hardware
Virtualized components presented to the VM:
- Virtual CPUs (vCPUs)
- Virtual RAM
- Virtual Disks
- Virtual Network Interfaces
- Virtual I/O devices
VM Images
Templates containing the VM configuration and virtual disk content:
- Pre-configured operating systems and applications
- Stored as files on the host system
- Can be used to rapidly deploy new VMs
Virtualizability
For a system to be efficiently virtualized, certain conditions must be met. Popek and Goldberg’s theorem states:
“A virtual machine monitor may be constructed if the set of sensitive instructions for that computer is a subset of the set of privileged instructions.”
Where:
- Privileged instructions: Instructions that can only execute in system mode
- Sensitive instructions: Instructions that could affect system resources or behave differently based on system state
This theorem is the foundation for understanding the challenges in virtualizing architectures like x86.
Virtualization Approaches
Different approaches to virtualization have emerged to address architectural challenges:
-
Full Virtualization: Guest OS runs unmodified, unaware it’s being virtualized
- May require techniques like binary translation to handle non-virtualizable instructions
-
OS-Assisted Virtualization: Guest OS is modified to cooperate with the hypervisor
- Example: Xen paravirtualization
- Better performance but requires modified guest OS
-
Hardware-Assisted Virtualization: Uses CPU extensions that support virtualization
- Examples: Intel VT-x, AMD-V
- Enables efficient virtualization with unmodified guest OSes
Use Cases for Virtual Machines
- Running different operating systems than the host system
- Operating multiple isolated environments on a single host
- Resource pooling for multiple users and applications in private clouds
- Infrastructure as a Service (IaaS) in public clouds like AWS EC2
Performance Considerations
Virtual machines introduce some overhead compared to bare-metal execution:
- CPU virtualization overhead
- Memory management overhead (especially with shadow page tables)
- I/O virtualization overhead
- Context switches between guest and hypervisor
VM Pausing vs Suspending
Suspending:
- Full VM state is written to disk, so only disk resources and networking resources remain required
- Resuming takes little time (way less than booting)
Pausing:
- Only the CPU activity is halted, so the VM does not run but does require main memory (and other resources)
- Resuming takes very little time (less than resuming a suspended VM)