Showing posts with label Virtualization. Show all posts
Showing posts with label Virtualization. Show all posts

Monday, June 29, 2009

UML (User Mode Linux)

In this Blog I will take you to a tour to a new dimension of Virtualization. That is the world of UML.

Many of us have spent time using VMware, VBox, Qemu etc, or debugging on how to start Xen/OpenVZ.
But the truth of above two is, applications like VMware are heavy on system resources and applications like Xen are a bit tricky (kernel should be Xen specific).

One thing I will admit, that I was also amongst the people who have spent a huge amount of time on different Virtualization technologies, until here at Openbravo I was given an opportunity to setup virtual environment on Amazon servers.
* For those who haven't worked with Amazon servers, Amazon servers are like domU of Xen virtual environment.

The aim was to setup an Openbravo instance (which can be made available on demand) on the top of an Amazon instance.
The main problem in working with amazon server is that you don't have access to host (domO) and neither Amazon people allow you to use custom kernel for domU (custom kernel: so that we can build another xen domU over it).
So taking these things in to account we were left with options like VMware but looking upon their load on system we needed something light and usable.
In our hunt for a perfect virtual environment my manager told me about UML. And truly speaking it turned up to be the perfect tool (it matched all our requirements and expectations).

UML works very differently from all other Virtualization techniques, all it needs to work smoothly is uml-utilities package, one kernel (binary script) and a block device(which contains minimal/full OS).
It is like doing chroot to a directory and installing a full OS in that.
It has many other features like
  • Mounting host filesystem.
  • Adding a COW (copy on write) file.
  • etc.

This COW file is used if you want to use same block device (filesystem) for more than one Virtual system. This COW file writes the difference to a separate file (just like a diff patch).

The use of UML gave us one more flexibility, that was using Xen image (pre-installed Openbravo instance) with UML kernel.
And an advantage over Xen (i.e. access over host system is not required in UML).

Reference:
UML Howto
UML Wiki
Download Page

Tuesday, November 4, 2008

Vitualization

Virtualization

To start with Virtualization I can say it is the one of the most helpful technology known to man. The basics which make it a great technology is the feature that user can have more than one machine at the cost of one single machine.
Or for a software guy he can get a number of machines to test his development.

In Virtualization we have 2 different types.
They are ->
* Full Virtualization.
* Para Virtualization.

Full Virtualization, in computer science, is a Virtualization technique used to implement a certain kind of virtual machine environment: one that provides a complete simulation of the underlying hardware. The result is a system in which all software capable of execution on the raw hardware can be run in the virtual machine. In particular, this includes all operating systems. (This is different from other forms of Virtualization – which allow only certain or modified software to run within a virtual machine.)
Some examples of such are VMware/QEMU/KVM.



Para Virtualization, In computing, paravirtualization is a Virtualization technique that presents a software interface to virtual machines that is similar but not identical to that of the underlying hardware.

Paravirtualization may allow the virtual machine monitor (VMM) to be simpler or virtual machines that run on it to achieve performance closer to non-virtualized hardware. However, operating systems must be explicitly ported to run on top of a paravirtualized VMM.

And according to me I personally prefer this due to its feature of not using too much of RAM and other resources, as it uses host's resources and that too when required.
Some examples of such are XEN/OpenVZ.



How to?
In terms of how to do virtualization it can be done through GUI or Command line. I prefer Command line for doing the job.

Full Virtualization.

I will start explaining this hoping that you have QEMU installed.

QEMU

qemu-img create -f raw image.img 5G

This will create a blank image named image.img you can define the size of the image by changing the 5G option to any size.
Now it's time to boot it with a cdrom to give it an Operating System. To do this you need either a CDROM on host machine o an ISO image.
If you have an ISO image then enter this command ->

qemu -cdrom linux/windows.iso -hda image.img -m 600 -boot d

Where linux/windows.iso is your ISO image, image.img is the disk image you just created,-m 600 is the RAM you want to allocate to the Virtual Machine and -boot d is to tell the Virtual Machine to boot from the CDROM.

After the installation is over then run the Virtual Machine with the following command ->

qemu -hda image.img -m 600 -net tap -net nic

Where -net tap tell it to connect to a virtual interface(tap device -- tap0/tap1 etc) on the host and -net nic defines 1 network card present on the Virtual Machine.
And if you don't know how to configure tap device you can refer my next post which will be TAP/TUN.



Para Virtualization.

XEN

Under this I will go on with XEN, to have virtualization with xen you need to have the kernel which supports XEN virtualization.
I now suppose that you have upgraded your kernel to support XEN.

To start with XEN you must be familiar with two terms which we will be using a number of times.
* dom0 -> this refers to the host on which the Virtual Machine or the domU is situated.
* domU -> this refers to the guest machine which we are going to create now.

Now if you have upgraded your kernel of the host machine to support XEN, this means yours dom0 is ready.
And it's time to create domU but before that just reboot your machine to boot into the upgraded kernel.


Creating - domU


File Based Setup of Virtual Disk

* mkdir -p /home/haps/
* dd if=/dev/zero of=/home/haps/diskimage.img bs=1024k count=5000

* dd if=/dev/zero of=/home/haps/swapimage.img bs=1024k count=512


* mkfs.ext3 /home/haps/diskimage.img

* mkswap /home/haps/swapimage.img


* mount -o loop /home/haps/diskimage.img /mnt




Debootstrap New OS onto Virtual Disk

* debootstrap --arch i386 lenny /mnt http://ftp.de.debian.org/debian/

* mv /mnt/lib/tls /mnt/lib/tls.disabled


* cp /etc/apt/sources.list /mnt/etc/apt/

* vi /mnt/etc/apt/sources.list


* cp -a /lib/modules/2.6.16-1-xen-k7/ /mnt/lib/modules/


* cp /etc/resolve.conf /mnt/etc/


* cp /etc/network/interfaces /mnt/etc/network/

* vi /mnt/etc/network/interfaces (and make it look like this)


#To use Specific IP address - edit the /mnt/etc/network/interfaces manually.
#To use DHCP, edit and include the following:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp

* vi /mnt/etc/hostname


* vi /mnt/etc/fstab
(and make it look like this)

proc /proc proc defaults 0 0
/dev/sda1 / ext3 defaults 0 0
/dev/sda2 none swap sw 0 0



Setup domU Xen Config

* vi /etc/xen/haps (and make it look like this)
kernel = "/boot/vmlinuz-2.6.16-1-xen-k7"
ramdisk = "/boot/initrd.img-2.6.16-1-xen-k7"
memory = 192
name = "haps"
vif = ['bridge=xenbr0']
ip = "ip 192.168.1.5"
gateway = "ip add"
netmask = "255.255.0.0"
root = "/dev/sda1 rw"


* ln -s /etc/xen/haps /etc/xen/auto/haps
//link in the config file so that the Virtal Machine starts on Bootup of Dom0



Run and Update DomU

* xm create haps -c
// CTRL + ] Gets out of the Console



All going well you should see domU booting up. Login as "root" with no password. Execute the following commands to update:

* passwd

* apt-get update
* apt-get upgrade

* apt-get install module-init-tools //for iptables
* apt-get install iptables

* iptables -L


For other commands on xen do .


Thats it.
Hope this helps a lot of people.