A hypervisor is software that you can use to run multiple virtual machines on a single physical machine. Every virtual machine has its operating system and applications.

How does a hypervisor work?

Hypervisor software is installed on physical servers and it loads the virtual machine images to create multiple virtual operating systems. The physical machine is known as a host, and the virtual operating systems are guests.

The hypervisor ensures that each virtual machine receives the allocated resources as configured. It does so by acting as an intermediary between guest machines and the underlying physical hardware. The hypervisor relays requests for processing power, memory, storage, and other resources to the host machine in several ways, including API calls. An API is a software communication method that allows different applications to exchange data.

Types of hypervisors

There are two types of hypervisors, each differing in architecture and performance.

Image credits: IBM

Type 1 hypervisor

The type 1 hypervisor (also known as a bare-metal hypervisor) sits on top of the metal server and has direct access to the hardware resources. It acts as a lightweight operating system.

Pros and cons

Due to its architecture, the type 1 hypervisor is very efficient. It can directly manage and allocate resources for multiple virtual machines without going through the host operating system. These types of hypervisors are also more secure, as the absence of a host operating system reduces the risks of instability.

Type 2 hypervisor

The type 2 hypervisor (also known as a hosted or embedded hypervisor) is a hypervisor program installed on a host operating system. Like other software applications, hosted hypervisors do not have complete control of the computer resources. Instead, the system administrator allocates the resources for the hosted hypervisor, which it distributes to the virtual machines.

Pros and cons

The presence of the host operating system introduces latency to the virtualized environment. When the virtual machine requests computing resources, the hypervisor cannot directly access the underlying hardware but relays the request to the host operating system. Also, the hypervisor and its hosted virtual machines are dependent on the stability of the host operating system.

  • VMware hypervisors

  • Hyper-V hypervisor is Microsoft’s hypervisor designed for use on Windows systems.

  • Citrix hypervisors (XenServer) is a commercial Type 1 hypervisor that supports Linux and Windows operating systems.

  • Hypervisor KVM is a kernel-based Virtual Machine (KVM) (open source virtualization) technology built into Linux®. It is part of Linux*. It* converts Linux into a type-1 (bare-metal) hypervisor.

Virtualization Techniques

Full Virtualization

In full virtualization, the hypervisor completely emulates hardware for the guest OS. This means the guest OS interacts with what it perceives as physical hardware, but it's a software emulation provided by the hypervisor.

When the guest OS makes a system call or accesses hardware resources, the hypervisor intercepts these calls and emulates the response of the hardware, without the guest OS knowing about this intermediation by using a combination of binary translation and direct execution techniques. This approach, depicted in the Image below, translates the guest OS kernel code dynamically to replace nonvirtualizable (sensitive) instructions for direct access to the hardware with new instructions that are safe to execute in a virtual environment and produce the same end effect on the virtual hardware as the original instructions would have had on physical hardware. Meanwhile, user-level code is directly executed on the processor for high-performance virtualization. Each virtual machine monitor provides each Virtual Machine with all the services of the physical system, including a virtual BIOS, virtual devices, and virtualized memory management.

The hypervisor translates all operating system instructions on the fly and caches the results for future use, while user-level instructions run unmodified at native speed.

Full virtualization offers the best isolation and security for virtual machines and simplifies migration and portability as the same guest OS instance can run virtualized or on native hardware

Para Virtualization

Paravirtualization refers to communication between the guest OS and the hypervisor to improve performance and efficiency. Paravirtualization, as shown in the Figure below, involves modifying the OS kernel to replace nonvirtualizable instructions with hypercalls that communicate directly with the virtualization layer hypervisor. The hypervisor also provides hypercall interfaces for other critical kernel operations such as memory management, interrupt handling and timekeeping.

As paravirtualization cannot support unmodified operating systems (e.g. Windows 2000/XP), its compatibility and portability are poor.

Hands-on Lab Overview

This hands-on lab focuses on creating a CentOS7 virtual machine via Oracle VirtualBox on Ubuntu OS 22.04.03

Prerequisites:

  1. Ubuntu OS 22.04.03

  2. Installed Oracle VirtualBox

    💡
    To install VirtualBox check the following guide: How to Install Oracle VirtualBox on Ubuntu 22.04

Hands-on Lab: Create a Virtual Machine

  1. Click New in the VirtualBox Manager window for setting up a new virtual machine (VM).

  2. Use the Create Virtual Machine: Memory Size wizard to select the amount of RAM that Oracle VM VirtualBox should allocate every time the virtual machine is started.

    The amount of memory selected here will be taken away from your host machine and presented to the guest OS, which will report this size as the virtual machine's installed RAM.

    💡
    Choose this setting carefully. The memory you give to the VM will not be available to your host OS while the VM is running, so do not specify more than you can spare.
  3. Use the Create Virtual Machine: Hard Disk to specify a virtual hard disk for the virtual machine.

    The following fields are available on this wizard page:

    • Create a Virtual Hard Disk Now. Creates a new empty virtual hard disk image, located in the VM's machine folder.

    • Use an Existing Hard Disk File. Enables you to select an existing disk image file to use with the new VM.

    • Do Not Add a Virtual Hard Disk. The new VM is created without a hard disk.

💡
Disk image files reside on the host system and are seen by the guest systems as hard disks of a certain geometry. When a guest OS reads from or writes to a hard disk, Oracle VM VirtualBox redirects the request to the image file. Like a physical disk, a virtual disk has a size, or capacity, which must be specified when the image file is created. As opposed to a physical disk however, Oracle VM VirtualBox enables you to expand an image file after creation, even if it has data already.
  1. Use the Create Virtual Hard Disk: Hard Disk File Type to select a file type for the new virtual hard disk image.

    Oracle VM VirtualBox supports the following types of disk image files:

    • VDI. Normally, Oracle VM VirtualBox uses its own container format for guest hard disks. This is called a Virtual Disk Image (VDI) file. This format is used when you create a new virtual machine with a new disk.

    • VHD. Oracle VM VirtualBox also fully supports the VHD format used by Microsoft.

    • VMDK. Oracle VM VirtualBox also fully supports the popular and open VMDK container format that is used by many other virtualization products, such as VMware.

  2. Use the Create Virtual Hard Disk: Storage on Physical Hard Disk page to select whether the size of the virtual hard disk file is dynamically allocated or is of fixed size.

  3. Use the File Location and Size page to configure the location of the virtual hard disk file and use the slider to set the size limit for the virtual hard disk.

    The virtual hard disk image is created in the specified location and added to the Hard Disks tab in Virtual Media Manager.

Run the Virtual Machine

  1. Before running the new virtual machine, go to "Settings" > "System" > "Motherboard" > "Pointing Device" > "USB Tablet":

    Oracle VM VirtualBox provides a virtual USB tablet device to new virtual machines through which mouse events are communicated to the guest OS.

    Otherwise, if the virtual machine detects only standard PS/2 mouse and keyboard devices, since the OS in the virtual machine does not know that it is not running on a real computer, it expects to have exclusive control over your keyboard and mouse. But unless you are running the VM in full screen mode, your VM needs to share keyboard and mouse with other applications and possibly other VMs on your host.

  2. When you start a VM for the first time the OS installation process is started automatically, using the ISO image file specified in the Create Virtual Machine wizard.

  3. If the ISO image file was not specified, select your VM in VirtualBox and click "Settings".

  4. Go to "Storage" > "Controller: SATA" > "Empty".

  5. Click on the disk icon next to "Optical Drive" and select "Choose a disk file". Locate and select the downloaded CentOS 7 ISO .

  6. Follow the onscreen instructions to install your OS.

  7. After the installation process, before rebooting the VM, go and click "Devices" > "Optical drivers" > "Remove disk from optical drive"

Resizing the Machine's Window

If you have scaled mode enabled, then the virtual machine's screen will be scaled to the size of the window.

To enable scaled mode, press Host key + C, or select Scaled Mode from the View menu in the VM window. To leave scaled mode, press Host key + C again.

This can be useful if you have many machines running and want to have a look at one of them while it is running in the background. Alternatively, it might be useful to enlarge a window if the VM's output screen is very small, for example because you are running an old OS in it.

References

  1. What is a Hypervisor?

  2. What is a hypervisor?

  3. What is VMware?

  4. What are hypervisors?

  5. What is a hypervisor?

  6. What is a Hypervisor? What's the Difference Between Type 1 and 2?

  7. What is KVM?

  8. Microsoft Word - VMware_paravirtualization - 2007-10-15.doc

  9. Chapter 3. Configuring Virtual Machines - Supported Guest OS

  10. Creating Your First Virtual Machine

  11. Disk Image Files (VDI, VMDK, VHD, HDD)

  12. Learn about hypervisors, system virtualization, and how it works in a cloud environment