Virtualization In Linux With Xen

Virtualization In Linux With Xen


This post was last updated on August 3rd, 2020 at 02:20 pm

Virtualization Technology

Virtualization means creating a virtual version of something like computer hardware, storage devices, and network resources, etc. It allows you to create multiple simulated environments from a single physical hardware system. For example, a Windows operating system can host a system with Linux Os or it can be any other operating system. It provides the functionality of a physical computer. Each virtual system that is hosted on a system (like Windows in this case)is known as a virtual machine(VM) or a guest machine. The system that is used for virtualization is known as the host machine.

Hardware Virtualization

Using single physical computer hardware to create multiple virtual machines that are running different operating systems. The software that is executed on the virtual machine is separated from the underlying hardware resources. The software, hardware, or firmware that creates a virtual machine on the host hardware is known as a hypervisor or virtual machine monitor(VMM). Broadly hardware virtualization can be categorized into two primary types-

1. Full virtualization

Also, know as type-1 virtualization is almost complete Simulation of the actual hardware. It requires every salient feature of hardware to be reflected in virtual machines including full instruction set, input/output operations, interrupts, Memory access, and many other features that are used by a software that runs on the bare machine. Examples of software that supports full virtualization are VMware ESXi/ESX, Hyper-V, Xen, VMWare Server, etc.

2. Paravirtualization

In this type of virtualization, the programs that are running in virtual machines are executed in their own isolated domain as if they are running on a separate system, but the hardware environment is not simulated. The programs of guest machines need to be specifically modified to run in this environment. Example of software that supports paravirtualization are IBM LPAR, Oracle VM for SPARC(LDOM), Xen(supports both types of virtualization)

Other types of virtualization are hybrid and OS-level virtualization that are explained below-

3. OS level virtualization

This type of virtualization is widely used. Os level virtualization is also known as “containerization”. In this type of virtualization, the kernel allows the existence of multiple isolated user-space instances. Such instances, called containers, zones, virtual private servers, virtual kernels, jails, etc. Examples of the software that supports this type of virtualization are Solaris, Docker, dragonfly BSD, free BSD jail, etc.

4. Hybrid virtualization

It is the combination of both full and paravirtualization. In this paravirtualization can be used for one feature while full virtualization can be used for other features. Examples of the software that support this type of virtualization are Oracle VM for x86, Xen, VMware ESXi, etc.

Why Use Virtualization

  • Isolated, virtual networks can be created from one original network
  • A single server can be made to act as multiple servers
  • A computer can be transformed to run multiple different operating systems
  • Computing infrastructure which is expensive to maintain can be virtualized for optimal use

Virtualization In Linux With Xen

The Xen project creates a VMM or hypervisor that allows the execution of multiple virtual guests operating systems on a physical machine. Since it is a type 1 hypervisor it runs directly on the top of a physical machine instead of running within the operating system.


Guest virtual machines running on Xen hypervisor are known as domains. A special domain known as domain0(or dom0) is responsible for controlling hypervisor and starting of guest Operating systems. other operating systems are known as domUs(or unprivileged domain) as these don’t control hypervisor.

Installing Xen

sudo su
apt-get install xen-system-amd64

This will install a 64bit hypervisor. If you are using a recent version of grub, it will automatically get listed in the boot menu. Now reboot your system. And usesudo xl list in the terminal to verify the installation success.

Setup LVM storage for guests

LVM stands for “logical volume manager”. It is a technology that allows Linux to manage logical volumes or filesystem that is much more advanced and flexible than the traditional method of the partitioning of a disk into one or more parts. Unlike disk partitions, these virtualized blocks don’t need to be contiguous. Generally, Linux distributions come with preinstalled LVM but if you don’t have in your system you can use the following command to install it-
apt-get install lvm2

Now configure the lvm to use one or more physical volumes like given below-
pvcreate /dev/sda4 (you can use other disks to create physical volumes )

Create a volume group to use the available spaces of created physical volumes-
vgcreate vg0 /dev/sda4

A group of physical volumes is created. Now we can create multiple logical volumes to utilize it in a virtual machine-
lvcreate -n Volume_name -L Size_of_volume(with M-megabyte or G-Gigabyte) volume_group

For example, if you want to create volume with 20GB use the following command
lvcreate -n vol1 -L 20G vg0

and if you want to remove this volume at a later stage you can use the following command
lvremove /dev/vg0/vol1

Once the lvm storage is set up follow the next step to configure the network interface for it.

Network configuration

To connect virtual machines from the external network we need to set up the Linux bridge in our system which can be done by creating a virtual switch in dom0. This switch will send/receive the data to or from the physical network from the virtual machine. The software used to implement this switch is called a Linux bridge.
Use the following command to install it-
sudo apt-get install bridge-utils

The network can be configured via /etc/network/interfaces
Open this file using a text editor-

nano /etc/network/interfaces

Depending on the hardware it will look something like this-

Edit it so that it should look like this-

now restart the networking by using given command

service networking restart

Check if it is working or not by using the given command –
brctl show

bridge networking will now start automatically on every boot.

Some basic commands used in the Xen are

xl info– will return the information about the hypervisor and dom0 including version, free memory, etc
xl list– List running domains, their IDs, Memory, state and CPU time consumed
xl top– Will display the running domains

Creating Virtual Machines

You can manually create a VM or the process can be automated by using tools like virt-builder, virt-manager or Xen-tools.
To install the Xen-tools in your system use the following command in the terminal & within the domain-
sudo apt-get install xen-tools

and used the given command to create a guest –

xen-create-image --hostname= Guest_OS \
--memory=512mb \
--vcpu=2 \
--lvm=vg0 \
--dhcp \
--pygrub \

This process will take some time to complete.

Starting guest in the console

Use the command below to start a guest

xl create -c /etc/xen/Guest_OS.cfg

-c tells xl or xm(in older versions of Xen) that we wish to connect the guest’s virtual console.

you can leave the console by using the given command-

xl shutdown Guest_OS

For creating a para-virtualized VM guest manually or setting up an HVM i.e Hardware virtualized guest you can follow Create PV Guest and HVM Manually which explains it in detail. If you still have a query you can drop a comment below.

Previous Package Management In Arch Linux
Next UmixOS 19.10 (Unity Remix)

About author

You might also like

Administration 0 Comments

How To Backup And Restore Files Using Tar In Linux/Unix?

This post was last updated on August 1st, 2020 at 03:09 pmA system backup is a process in which the state, files, and data of a computer system are copied

Linux Topics 0 Comments

How To Connect A Remote Linux Server Using SSH?

This post was last updated on August 2nd, 2020 at 08:28 pmSecure Shell(SSH) is a cryptographic networking protocol for securely getting access to a remote computer with the command line

Linux Topics 0 Comments

How To Set Password On A RAR Archive In Linux?

This post was last updated on August 1st, 2020 at 01:19 pmFiles inside a RAR archive can have important data. So you may want to protect it from the unusual


No Comments Yet!

You can be first to comment this post!

Leave a Reply