OS Notes
Introduction to virtualization — virtual machines, hypervisors (Type 1 and Type 2), containers (Docker), comparison of VMs vs containers, and how virtualization enables cloud computing.
Introduction
Virtualization is the technology that allows you to run multiple operating systems on a single physical machine simultaneously. It creates an abstraction layer between hardware and software, enabling efficient resource utilization, isolation between workloads, and flexibility in deploying applications.
Think of it this way: without virtualization, a powerful server running at 10% CPU utilization wastes 90% of its capacity. With virtualization, you can run ten separate workloads on that same server, each believing it has its own dedicated machine. This single insight revolutionized data centers and gave birth to cloud computing.
Virtual Machines
A Virtual Machine (VM) is a software emulation of a complete physical computer. Each VM has its own virtual CPU, RAM, disk, and network interface. It runs a full operating system (called the guest OS) that is completely unaware it is running on virtualized hardware.
How VMs Work
The key component is the hypervisor (also called Virtual Machine Monitor or VMM). The hypervisor sits between the hardware and guest operating systems, managing resource allocation and ensuring isolation.
| Guest | Guest | Guest | ||
|---|---|---|---|---|
| OS 1 | OS 2 | OS 3 | ||
| (Linux) | (Windows) | (Linux) | ||
| VM 1 | VM 2 | VM 3 |
Type 1 Hypervisor (Bare-Metal)
Runs directly on physical hardware without a host OS. The hypervisor IS the operating system for the machine.
Examples: VMware ESXi, Microsoft Hyper-V, Xen, KVM (technically Linux kernel module)
Advantages: Near-native performance, direct hardware access, better security (smaller attack surface), used in production data centers.
Type 2 Hypervisor (Hosted)
Runs as an application on top of a host operating system. The host OS manages hardware; the hypervisor runs as a regular program.
Examples: VirtualBox, VMware Workstation, Parallels Desktop, QEMU
Advantages: Easy to install (just another app), good for development/testing, can coexist with normal desktop applications.
Disadvantage: Additional overhead from the host OS layer, less efficient for production workloads.
Hardware Virtualization Support
Modern CPUs include hardware extensions that make virtualization efficient:
- Intel VT-x and AMD-V: Allow the hypervisor to run guest OS kernel instructions without emulation. The CPU has a special "guest mode" where the guest believes it is running at Ring 0, but the hypervisor can intercept sensitive operations.
- Intel EPT (Extended Page Tables) / AMD NPT (Nested Page Tables): Hardware-assisted memory translation that eliminates the overhead of shadow page tables.
- SR-IOV: Allows a single physical network card to appear as multiple virtual network cards, each assignable to a different VM.
Containers
Containers provide lightweight isolation by sharing the host OS kernel. Instead of virtualizing hardware, containers virtualize the operating system — each container sees its own isolated filesystem, process tree, and network stack, but all containers share the same kernel.
| App 1 | App 2 | App 3 | ||
|---|---|---|---|---|
| + deps | + deps | + deps | ||
| Container | Container | Container | ||
| Runtime | Runtime | Runtime |
Docker — The Container Standard
Docker popularized containers by making them easy to build, ship, and run. A Docker container is created from an image — a layered filesystem containing the application and all its dependencies.
Linux Technologies Behind Containers
Containers are not a single technology — they combine several Linux kernel features:
- Namespaces: Provide isolation (PID namespace = isolated process tree, NET namespace = isolated network, MNT namespace = isolated filesystem view)
- cgroups (Control Groups): Limit resource usage (CPU, memory, I/O bandwidth)
- Union Filesystems (OverlayFS): Layer filesystems efficiently so containers share base image layers
VMs vs. Containers — Comparison
| Feature | Virtual Machines | Containers |
|---|---|---|
| Isolation level | Hardware-level (strongest) | Process-level (kernel shared) |
| Boot time | Minutes | Seconds |
| Size | GBs (full OS) | MBs (app + deps only) |
| Performance | Near-native (with VT-x) | Native (no hypervisor overhead) |
| Guest OS | Any OS (Linux on Windows) | Same kernel family only |
| Density | 10-20 VMs per host | 100s of containers per host |
| Security | Stronger isolation | Kernel vulnerability affects all |
| Use case | Multi-OS, legacy apps | Microservices, CI/CD |
When to Use What
Use VMs when:
- You need to run different operating systems (Windows + Linux on same hardware)
- Strong security isolation is critical (multi-tenant cloud)
- Running legacy applications that require specific OS versions
- Full hardware emulation is needed
Use Containers when:
- Deploying microservices at scale
- You need fast startup and high density
- All workloads run on the same OS family
- CI/CD pipelines need reproducible environments
- Development/production parity is important
Virtualization in Cloud Computing
Cloud providers like AWS, Azure, and GCP built their infrastructure on virtualization:
- EC2 instances are VMs running on AWS's custom hypervisor (Nitro, based on KVM)
- AWS Lambda uses lightweight micro-VMs (Firecracker) that boot in 125ms
- Kubernetes orchestrates containers across clusters of machines
The evolution: Physical servers → VMs (better utilization) → Containers (better density) → Serverless (no server management).
Key Takeaways
- Virtualization abstracts physical resources, enabling sharing and isolation
- Type 1 hypervisors run on bare metal (production); Type 2 run on a host OS (development)
- Containers share the host kernel — faster and lighter but weaker isolation than VMs
- Modern solutions often combine both: VMs for isolation between tenants, containers within VMs for application deployment
- Hardware virtualization extensions (VT-x, EPT) make VM overhead negligible for most workloads
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Virtualization - Containers and Virtual Machines.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, distributed, and, modern, virtualization
Related Operating Systems Topics