Home » Linux, Virtualization

Create and manage virtual machines on Xen

In this post, these content are introduced:

  • Create and manage file-backed virtual block device (VBD) for virtual machines on xen.
  • Install Fedora 11 via internet as DomU on top of xen.
  • Manage virtual machines using xm.

Create file-backed VBD:

The actual space of VBD will be the amount of disk the virtual machine used. And it will be convenient if the virtual machine will be duplicated since the work is just copying the VBD file and changing some configurations. But file-backed VBDs may not be appropriate for I/O-intensive domains because of the I/O handling cost to support file-backed VBDs in dom0.
Create a 20GB sparse file-backed VBD:

# dd if=/dev/zero of=vmdisk1 bs=1k seek=20480k count=1

Make a ext3 file system in the disk file:

# mkfs -t ext3 vmdisk1

Install Fedora 11 Linux via Internet:

First download the pxeboot kernel of Fedora 11 for installation via Internet. Download vmlinuz and initrd.img from here:

http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/x86_64/os/images/pxeboot/

Create an installation profile f11.install:

name="F11INSTALL"
memory=1536
disk = ['tap:aio:/home/xen/vmdisk1,xvda,w' ]
vif = [ 'bridge=eth0' ]
kernel = "/home/xen/fedora/vmlinuz"
ramdisk = "/home/xen/fedora/initrd.img"
vcpus=2
on_reboot = 'restart'
on_crash = 'restart'

Here the blktap2 VBD driver is used. If the loopback backed driver is used, the disk like should be changed to:

disk = ['file:/home/xen/vmdisk1,xvda,w' ]

The virtual machine’s name is “F11INSTALL”, memory is 1.5G, CPU number is 2, disk, kernel and ramdisk is prepared in the above steps.

Start this virtual machine:

# xm create f11.install

Connect to this virtual machine’s console and complete the installation:

# xm console F11INSTALL

The installation of Fedora 11 will start. The URL of installation source I used during installation is:

http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/x86_64/os/

Load DomU:

Create a profile vm1.run for loading the virtual machine:

name="vm1"
memory=1536
disk = ['tap:aio:/home/xen/vm1/vmdisk1,xvda,w' ]
vif = [ 'bridge=eth0' ]
bootloader = "/usr/bin/pygrub"
vcpus=2
on_reboot = 'restart'
on_crash = 'restart'

Here we use the PyGrub (“/usr/bin/pygrub”) as the bootloader. PyGrub starts Linux DomUs with the kernels that lie in the filesystem of the DomU instead of the kernels that lie in the filesystem of the Dom0. That makes the kernel update and management easier.

Then the DomU can be started using this profile:

# xm create vm1.run

The console of this DomU can be connected to:

# xm console vm1

Manage DomUs:

Start Domu:

 # xm create DomU_profile

List running DomUs:

 # xm list

Shutdown DomU:

 # xm shutdown DomU_name

Console of DomU:

 # xm console DomU_name

Top of DomUs:

 # xm top

Reset a DomU:

 # xm reset DomU_name

And others more which can be find in the xm manuals.

After configured a DomU, duplication of the DomU is easy: Just make a copy of the VBD file and the profile, and then change the profile.

I have set up 8 DomUs on the server. There are total 9 machines on top of xen and a lot of interesting things can be done with these “machines” ;)

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1826    16     r—–    244.8
vm1                                         25  1536     2     -b—-      4.9
vm2                                         24  1536     2     -b—-      5.4
vm3                                         23  1536     2     -b—-      5.4
vm4                                         22  1536     2     -b—-      5.8
vm5                                         27  1536     2     -b—-      5.4
vm6                                         20  1536     2     -b—-      6.0
vm7                                         19  1536     2     -b—-      6.3
vm8                                         18  1536     2     -b—-     18.8

References:

http://tx.downloads.xensource.com/downloads/docs/user/#SECTION03300000000000000000

http://bderzhavets.wordpress.com/2009/06/10/setup-fedora-11-pv-domu-at-xen-3-4-1-dom0-kernel-2-6-30-rc6-tip-on-top-of-fedora-11/

http://wiki.xensource.com/xenwiki/PyGrub

Updated history
Feb. 8, 2010. Change loopback backed driver to blktap backed one.
Jul. 10, 2001. Add loopback backed dirver information for configuration file.

Read more:

Digg del.icio.us Stumble Techorati Facebook Newsvine Reddit Twitter
Mixx LinkedIn Google Bookmark Yahoo Bookmark MySpace LiveJournal Blogger RSS feed
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

One Comment »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.