Virtualization and Containers
In the old days, “one computer = one OS.” If you wanted to run a Linux web server and a Windows database server, you had to buy two physical boxes. Today, we use Virtualization to run dozens, or even hundreds, of isolated environments on a single physical machine.
The Hypervisor: The OS for OSs
To run multiple operating systems, we need a “Hypervisor” (also called a Virtual Machine Monitor or VMM).
Type 1: Bare Metal
The hypervisor is the only thing running on the hardware. It is a tiny, highly efficient kernel whose only job is to manage “Guest” OSs (VMs).
- Examples: VMware ESXi, Microsoft Hyper-V, Xen.
- Usage: These power the enterprise data centers and the public cloud (AWS/Azure).
Type 2: Hosted
The hypervisor runs like an application inside a normal OS (like Windows or Mac).
- Examples: Oracle VirtualBox, VMware Workstation.
- Usage: Great for developers who want to run a Linux VM on their Mac to test code.
Virtual Machines vs. Containers
A Virtual Machine (VM) virtualizes the Hardware.
- It includes a full copy of the kernel, the drivers, and all the libraries.
- Pros: Complete isolation (you can run Windows on Linux).
- Cons: Slow to boot, uses a lot of RAM and Disk.
A Container (like Docker) virtualizes the Operating System.
- All containers share the same host kernel. They only include the specific application and its libraries.
- Pros: Starts in milliseconds, uses almost no extra RAM.
- Cons: You can only run “Linux containers on a Linux host” (though Windows and Mac use a tiny hidden VM to cheat and run Linux containers).
WSL2: The Best of Both Worlds
In 2020, Microsoft released WSL2 (Windows Subsystem for Linux 2). Unlike WSL1 (which translated Linux calls to Windows calls), WSL2 includes a real Linux kernel provided by Microsoft.
- It uses a lightweight Type-1 Hypervisor (Hyper-V).
- When you open a terminal, it boots the Linux kernel in less than a second.
- This allows developers to have the best UI tools of Windows while having the real-world engineering power of a Linux environment.
The Cloud Revolution
Virtualization is what made the “Cloud” possible. When you “rent a server” from Amazon (AWS EC2), you aren’t getting a physical computer. You are getting a slice of a massive 128-core server. Because of the hypervisor, you can’t see the other users on that machine, and they can’t see you.
Serverless Computing (Lambda/FaaS)
The next step is “Serverless.” Instead of a VM or even a container, you just upload a single function (calculate_tax). The OS/Hypervisor spins up a micro-container, runs your function for 100 milliseconds, and then destroys it. You only pay for the exact 100ms of CPU time you used.
Why is it so fast now?
Early virtualization was slow because the software had to “emulate” every single instruction. Today, almost every CPU (Intel VT-x, AMD-V) has Hardware-Assisted Virtualization. The CPU itself has special instructions that allow the Guest OS to run directly on the physical cores at near-native speed, only trapping back to the hypervisor when it needs to access a sensitive resource like the Network or Disk.
In our final module, we will look at Modern Trends and the “Next Generation” of operating systems that are being built for the era of AI and the Edge.