Xen Hypervisor: Running multiple OS on the same machine

xen_gen_logo[1]

Editors Note: This post targets extremely advance users and power users of linux. Please follow the steps carefully if you don’t know what you are doing.

Most of us are aware of Dual-Boot or Virtualizing the OS using VMWare or VirtualBox but there are some problem with the above two techniques. In case of dual booting, if we want to move to another OS we will have to restart the whole system. In case of Virtualization using VMWare or VirtualBox though, you get rid of the restarting problem but the performance with the guest OS is not upto the mark. So, what is the solution to the above problems?

A hypervisor(bare-metal hypervisor) is the solution to the above problems. So, the question arises what is a hypervisor? So, lets go and find this answer.

Introduction to Hypervisors

A hypervisor can be defined as a piece of software, firmware or hardware that can run Virtual Machines. There are two types of hypervisors Type 1 and Type 2.

Hypervisors- Part 11x1

Type 1 Hypervisors(Fig. 1): These types of hypervisors run just above the hardware layer and has direct access to the hardware and are also called Bare-Metal Hypervisors. Thus the guest OS runs on a level above the hypervisor. The examples of these types of hypervisors are Xen, Citrix XenServer(commercial alternative to Xen), Microsoft Hyper-V, etc.

Type 2 Hypervisors(Fig. 2):  These type of hypervisors run within a conventional Operating System environment and are also called Hosted hypervisors. The examples of these types of hypervisors are VMWare Workstation, VirtualBox, etc.

These hypervisors provide a layer of hardware virtualization through which multiple OS can simultaneously. In this article I will explain on Type 1 or Bare-Metal hypervisors.

Type 1 Hypervisors

These hypervisors run just above the hardware and try to implement the basic layer of hardware virtualization. A number of guest OS can be made to run simultaneously on these type of hypervisors. The guest OS interacts with these hypervisors to do its various tasks like interfacing with the hardware devices or to allocate memory and control the processor execution.

Hypervisors provide a layer of separation between different guest OS so that the guest OS can run independently. There are mainly two types of virtualizations possible using Type 1 Hypervisors namely 1). ParaVirtualization and 2). Full Virtualization.

Lets compare both of these virtualizations.

Para-Virtualization: In this type of virtualization the guest OS needs to be modified so that instead of interacting with hardware directly it interacts with the hypervisor for resource allocation.

Para-Virtualization avoids the need to emulate full hardware and firmware services which makes managing a paravirtulized guest easy to manage and also reduces the potential attack surface to malicious guest.

Full Virtualization: Full Virtualization doesn’t need a modified guest OS. It is capable of running a unmodified OS or a proprietary OS like Microsoft Windows. To achieve such type of virtualization a hypervisor depends upon Hardware Assisted Virtualization. In this type of virtualization the guest OS can directly interact with the hardware and can run on its full potential.

Xen: A powerful hypervisor

Xen is a hypervisor providing services that allows multiple computer operating systems to execute on the same hardware concurrently.

Xen is a powerful hypervisor capable of running many different types of guest OS like linux, netBSD, Solaris and Microsoft Windows.

Xen is a bare-metal hypervisor which provides a layer to the Guest OS for interfacing with the hardware.

Xen is capable of providing both para-virtualization and full virtualization. For Full Virtualization their should be Hardware-assisted Virtualization support.

Xen also supports live migration from one OS to another and aims to provide 0 downtime in migration. For this Xen loads all the OS address space in the memory so switching can be ultra-fast.

System Requirements for Xen:

  • Processor: 64-bit processor with minimum clock speed of 1.5 Ghz with Intel VT or AMD-V for Full Virtualization
  • Ram: 1 GB (minimum), 2GB or more (Recommended)
  • Disk Space: 16GB (minimum), 60GB or more(Recommended)

A little explanation?

Now, we will know how to set dom0 and domU on Ubuntu 12.10.

Lets first know what exactly are these dom0 and domU.

Dom0

dom0 is the initial domain that is started by the Xen Hypervisor on boot. Without this the Xen hypervisor is just useless.

Dom0 is essentially the host operating system on which Xen hypervisor run Xen Mangement toolstack and has special privileges, like being able to access the hardware directly.

DomU

domU is the counterpart to dom0. It has no special privileges and can not interface the hardware directly. The kernel of domU comes from dom0 ‘s filesystem, not from filesystem exported to domU.

Now when we know what are dom0 and domU, lets have a look on how to install Xen as dom0 and domu on Ubuntu 12.10.

Installing Xen as dom0 and domU on Ubuntu

Installing Xen dom0 and domU on Ubuntu is very much easier. Lets have a look how to do it.

Open terminal in Ubuntu by pressing Ctrl+Alt+T and follow this guide.

Step 1: Write the following command in the terminal

sudo apt-get install xen-hypervisor-4.1-amd64 xen-utils-4.1 xenwatchxen-tools xen-utils-common xenstore-utils virtinst virt-viewer virt-manager

Running this command you will prompted to enter your password. Enter it and Ubuntu will ask you whether you want to install it or not. Just Press Y followed by Enter.

1

Step 2: Now all the required packages have been installed. Now you need to run your dom0. For this you will have to restart your system. But wait… there is one thing left. We need to edit a file “/etc/xen/xend-config.sxp”. For this run this command

 sudo gedit /etc/xen/xend-config.conf

2

In this file find “#(xend-unix-server no)” and change it to “(xend-unix-server yes)”.

Now restart and choose Ubuntu with Xen Hypervisor from GRUB boot menu.

Step 3: Now you will be in Ubuntu running with Xen hypervisor. Now lets proceed. Now use this command and you will see your system running.

sudo xm list

3

Step 4: Now lets create a domU. First we need to configure a file“/etc/xen-tools/xen-tools.conf”. For this execute this command.

sudo gedit /etc/xen-tools/xen-tools.conf

4

Now find these enteries in this file and chnage them as given here. If these enteries are preceeded by # remove the hashes

dir=/mnt/xen

This command will set the directory where Xen will mount the guest OS

install-method=debootstrap

This method tells how to install the guest OS

size=8Gb

This will set the disk image size

memory=1024Mb

This sets the amount of memory available to guest OS

swap=128Mb

This sets the disk space available as swap

fs=ext3

This sets the type of filesystem for the disk image

dist=lucid

This sets the default distribution to install

image=sparse

This sets the type of image to be used

dhcp=1

This sets the dynamic IP allocation for guest OS

nameserver=< IP address of the DNS server>

If this property is not set then the configuration for this will be taken from host OS

bridge=virbr0

This sets the bridge mode

kernel = /boot/vmlinuz-`uname -r`

This will set the kernel for the guest OS

initrd = /boot/initrd.img-`uname -r`

This will set the initial ramdisk file for the guest OS

mirror = http://archive.ubuntu.com/ubuntu

This will set the place from where the guest OS is downloaded

ext3_options = noatime,nodiratime,errors=remount-ro

ext2_options = noatime,nodiratime,errors=remount-ro

These two commands sets the filesystem options

xfs_options = defaults

reiserfs_options = defaults btrfs_options = defaults

These two commands sets the filesystem options

boot = 1 passwd = 1

serial_device = hvc0 disk_device = xvda

Step 5: Now we are 90% done with our work. Now lets complete the remaining 10% and take some rest.

Now lets create the image. Issue this command to create the image

sudo xen-create-image –hostname=ubuntu10

When your image is being created it may ask for root password. Just provide any password and your domain will start automatically.

Step 6: Now you can login to it using

xm console ubuntu10

to terminate

xm destroy ubuntu10

to restart

xm create -c /etc/ubuntu10.cfg

Conclusion

So after such a long process, now we are over with the Xen dom0 and domU creation on ubuntu 12.10. Now you can run the 2 OS concurrently and enjoy.

Saurabh Badhwar

A tech freak, likes programming and love developing technologies that can change the way we use computers.

Loading Facebook Comments ...
Loading Disqus Comments ...