DEV Community

Cover image for The Different Flavors of Virtualization
PGzlan
PGzlan

Posted on

The Different Flavors of Virtualization

With rise of cloud computing and the rapid growth in software development for products that have millions of users, virtualization has become somewhat of a cornerstone for building flexible and efficient systems. Virtualization comes in different flavors and we'll explore some of them in this blog post

Virtualization: What is it?

Virtualization is a technique of creating virtual versions of physical resources such as servers, storage devices, network resources, and operating systems. This helps improve scalability, efficiency, and allows multiple environments to coexist independently (to an extent) on the same physical hardware.

Let's look at the different types of virtualization:

  1. Nested Virtualization
  2. Paravirtualization
  3. Full Virtualization
  4. Containerization

1. Nested Virtualization

Nested virtualization refers to the ability of running a virtual machine (VM) inside another VM while the underlying hardware supports this operation. Essentially, it allows you to create a virtualization environment within another virtualization environment.

# Install the necessary packages for KVM
sudo apt-get update
sudo apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker

# Verify the installation
kvm-ok
Enter fullscreen mode Exit fullscreen mode

In the code snippet above, we're installing KVM (Kernel-based Virtual Machine), a type of virtualization software that supports nested virtualization. kvm-ok command checks if your server can run KVM.

Benefits and drawbacks of Nested Virtualization

Nested virtualization is a feature that lets you run a hypervisor inside a virtual machine (VM). This means that you can create and run virtual machines within a virtual machine. Nested virtualization can be useful for running applications or emulators in a nested VM, testing software releases on VMs, reducing deployment times for training environments, and using Hyper-V isolation for containers

Benefits Drawbacks
Reduced overall operating costs Performance regression when running in a VM
Faster software and app development and testing Incompatibility with dynamic memory
Running multiple virtual hypervisors with nested VMs on one real hypervisor installed on a physical machine Third party virtualization apps aren’t supported in Hyper-V virtual machines
Saving costs Nested Virtualization isn’t suitable for Windows Server Failover Clustering, and performance sensitive applications

2. Paravirtualization

In paravirtualization, the guest operating system (OS) is aware that it's running on a virtualized environment and can interact directly with the hypervisor. This interaction allows for better performance as the hypervisor and guest OS can cooperate at a deeper level.

Xen is a popular open-source hypervisor that supports paravirtualization. It provides services allowing multiple computer operating systems to execute on the same computer hardware concurrently. It was originally developed by the University of Cambridge Computer Laboratory and is now being developed by the Linux Foundation. It powers one of privacy oriented linux distros known as Qubes OS

Let's see an example of how Xen can be leveraged

# A simple example of creating a new domain with Xen's Python API

import XenAPI

session = XenAPI.Session('http://localhost')
session.xenapi.login_with_password('root', 'PassW0rd')

vm_record = {
    "name_label": "Xen VM",
    "memory_static_max": f"{1024 ^ 3}", # Sizes are in bytes
    "memory_dynamic_max": f"{1024 ^ 3}",
    "memory_dynamic_min": f"{1024 ^ 3}",
    "VCPUs_max": "2",
    "VCPUs_at_startup": "2",
    "actions_after_shutdown": "destroy",
    "actions_after_reboot": "restart",
    "actions_after_crash": "restart",
    "PV_bootloader": "pygrub",
}

vm_ref = session.xenapi.VM.create(vm_record)
Enter fullscreen mode Exit fullscreen mode

This script is an example of how to create a new domain (virtual machine) using the XenAPI Python library. The code starts by importing the XenAPI library and creating a new session object that connects to a Xen hypervisor running on the local machine. The session is authenticated using the login_with_password method, which takes the username and password as arguments.

Next, a dictionary called vm_record is created to hold the configuration details for the new virtual machine. This includes the name of the VM, the amount of memory it should have, the number of virtual CPUs, and various actions that should be taken when the VM is shut down, rebooted, or crashes. The PV_bootloader field specifies that the pygrub bootloader should be used to boot the VM.

Finally, the VM.create method is called on the session’s xenapi attribute to create a new virtual machine using the configuration specified in vm_record. The reference to the newly created VM is stored in the vm_ref variable.

This script can be used as a starting point for developing more complex scripts or applications that automate the process of creating and managing virtual machines on a Xen-based virtualization platform

Benefits and drawbacks of Para-virtualization

Paravirtualization is a virtualization technique that presents a software interface to virtual machines which is similar, yet not identical, to the underlying hardware–software interface. While it has several benefits, there are also some drawbacks to consider.

Here are some benefits and drawbacks of paravirtualization:

Benefits Drawbacks
Easier backups Erratic performance gains
Fast migrations Limited guest operating system support
Improved system utilization Dependency between the operating system and hypervisor
Server consolidation Possible security vulnerabilities
Power conservation

3. Full Virtualization

Full virtualization is a technique in which the complete simulation of the actual hardware is done to run the guest OS. The guest OS is unaware that it's running on a virtual machine.

Oracle's VirtualBox is a software that offers full virtualization. Here's how you can create a new VM using the VirtualBox CLI:

# Create a new VM
VBoxManage createvm --name "MyVM" --ostype "Ubuntu_64" --register

# Set VM memory and boot order
VBoxManage modifyvm "MyVM" --memory 2048 --boot1 dvd --boot2 disk --boot3 none --boot4 none

# Create a new virtual hard drive
VBoxManage createmedium --filename "MyVM.vdi" --size 10000
Enter fullscreen mode Exit fullscreen mode

In the example above, we first create a new VM named "MyVM" with an Ubuntu 64-bit OS. We then modify the VM's settings to use 2GB of memory and set the boot order. Finally, we create a new 10GB virtual hard drive for the VM.

Benefits and drawbacks of Full Virtualization

Full virtualization is a virtualization technique that allows the guest operating system to run on the host hardware without any modification. While it has several benefits, there are also some drawbacks to consider.

Here are some benefits and drawbacks of full virtualization:

Benefits Drawbacks
Uses hardware efficiently High initial investment
Available at all times Data can be at risk
Recovery is easy Quick scalability is a challenge
Quick and easy setup Performance witnesses a dip
Cloud migration is easier Unintended server sprawl

4. Containerization

Containerization is a lightweight alternative to a full virtual machine. Instead of virtualizing the entire hardware stack, containerization applications such as Docker allow the containerized applications to share the host system's OS kernel.

# Pull an Ubuntu image
docker pull ubuntu:18.04

# Run a container
docker run -it ubuntu:18.04 /bin/bash
Enter fullscreen mode Exit fullscreen mode

In this Docker example, we first pull an Ubuntu 18.04 image from the Docker Hub. We then use this image to start a new container, in which we can run commands as if we were on a full Ubuntu 18.04 system.

Benefits and drawbacks of Containerization

Containerization is a method of virtualization that allows multiple isolated user-space instances to run on a single host operating system. It has several benefits and drawbacks.

Here are some benefits and drawbacks of containerization:

Open in browser

Benefits Drawbacks
Portability Complexity
Scalability Security risks
Resource efficiency Storage and networking challenges

Conclusion

Technique Description
Nested Virtualization A feature that lets you run a hypervisor inside a virtual machine (VM). This means that you can create and run virtual machines within a virtual machine. Nested virtualization can be useful for running applications or emulators in a nested VM, testing software releases on VMs, reducing deployment times for training environments, and using Hyper-V isolation for containers.
Paravirtualization A virtualization technique that presents a software interface to virtual machines which is similar, yet not identical, to the underlying hardware–software interface. The intent of the modified interface is to reduce the portion of the guest’s execution time spent performing operations which are substantially more difficult to run in a virtual environment compared to a non-virtualized environment. Paravirtualization requires the guest operating system to be explicitly ported for the para-API – a conventional OS distribution that is not paravirtualization-aware cannot be run on top of a 7paravirtualizing VMM.
Full Virtualization A virtualization technique that allows the guest operating system to run on the host hardware without any modification. Full virtualization uses binary translation and direct execution to provide an unmodified guest operating system with an interface that is identical to the underlying hardware.
Containerization A method of virtualization that allows multiple isolated user-space instances to run on a single host operating system. Containers are lightweight and portable, allowing applications to be easily moved between environments. They also provide improved resource efficiency and scalability compared to traditional virtual machines.

In conclusion, virtualization is a powerful tool that can help developers and system administrators create flexible, isolated, and efficient systems. Whether you're using nested virtualization to run VMs within VMs, paravirtualization for improved performance, full virtualization for complete OS isolation, or containerization for lightweight, sharable environments, virtualization can offer a host of benefits.

Different types of virtualization are suitable for different use cases. Full and nested virtualization are great when you need to run multiple, entirely separate operating systems on a single physical machine. Paravirtualization is excellent when performance is a concern, and the guest operating system supports it. Containerization is the way to go for packaging applications and their dependencies into a standalone unit that can run almost anywhere.

As always, the best tool depends on the job at hand. By understanding these different types of virtualization, you can make more informed decisions about how to structure your systems and applications. Happy virtualizing!


References:

  1. Nested Virtualization in KVM ↗
  2. Xen Project Beginners Guide ↗
  3. VirtualBox Command-Line Management Interface ↗
  4. Docker Get Started ↗
  5. Xapi Project Docs - Memory (xapi-project.github.io) ↗
  6. Hyper-V Nested Virtualization ↗
  7. VMware Nested Virtualization Explained: Use Cases and Tutorial ↗
  8. VPS with Nested Virtualization – An Overview ↗
  9. Virtualization In Cloud Computing | Pros & Cons of Virtual Platform ↗
  10. The Advantages and Disadvantages of Containers ↗

Top comments (0)