Virtualization - The Basics
Tags: virtualmachine, linux, sre, virtualization
Published: 2024-07-01 14:45:56

**Virtualization** in computing means creating a virtual version of something instead of a physical one. This includes virtual versions of computer hardware, storage devices, and network resources.
In this post, I will focus on discussing virtual machines on bare metal or a host machine, specifically in terms of Linux.

**Virtual Machine**: A VM is a software version of a physical computer. It allows you to run an operating system and applications just like on a real computer, but it works within another computer (the host), sharing its resources like CPU, memory, and storage. In fact, each VM believes it is the only system running on the hardware.

**Hypervisor**: A hypervisor is software that lets you run multiple VMs on one physical computer. It manages the computer's resources and makes sure each VM operates independently.

Type-1: A Type-1 hypervisor, also known as a bare-metal hypervisors, are installed directly onto the physical hardware without needing a separate operating system. It manages the VMs directly, providing them with access to the hardware resources.
Examples include KVM (Kernel-based Virtual Machine), Proxmox, VMware ESXi, Microsoft Hyper-V Server and Citrix Hypervisor (formerly XenServer).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhinq4zyy43fmjrye76n.png)

Type-2: A Type-2 hypervisor is like a software application that you install on your computer's operating system (like Windows, macOS, or Linux). It creates VMs that can run different operating systems alongside your main operating system. 
Examples include VirtualBox, VMware Workstation, and QEMU.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgsp8jqjlk3yx28wvqtl.png)

Different virtualization techniques used in VMs are as follows:

**Fully Virtualized**: When a guest OS running in a VM attempts to access hardware (like CPU, memory, or network), it interacts with virtual hardware interfaces provided by the hypervisor. The hypervisor translates these hardware calls into commands that the physical hardware can execute. This process involves emulating the actual hardware interfaces and translating the commands to ensure they are compatible with the host hardware. The guest OS are unaware that they are running on virtualized hardware.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o48l2zc5ueyxftbuh42j.png)

**Paravirtualization**: In paravirtualization, the guest OS is modified to replace certain privileged instructions with hypercalls, which are calls directly to the hypervisor. Hypercalls are specific function calls that the guest OS uses to request services from the hypervisor, such as memory management, I/O operations, or scheduling. It reduced overhead and improve efficiency compared to traditional fully virtualized approaches.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9t2r6bthyabtcy2lr34.png)

**Emulation**: When a guest software running on an emulated environment makes a hardware call, such as accessing memory or processing data, the emulated software (QEMU) translates these calls into instructions that the host system can understand and execute.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jq53aqsee7zk0vfeyxwp.png)

**Shared Hardware Virtualization**: Suppose a VM running a high-performance application requires direct access to a specialized GPU for computational tasks. The hypervisor identifies the GPU and assigns it to the VM using pass-through. When the VM makes hardware calls related to GPU operations those calls are handled directly by the GPU without involving the hypervisor's virtualization layer.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/om3a6m2ctm5au3pprrgv.png)

**Conclusion**: virtualization improves efficiency by maximizing hardware use(overcommiting). This optimizes hardware use, reduces costs, enhances security by isolating each VM, and makes IT systems more flexible and easier to manage. It also speeds up deploying new software and recovering from failures.