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.

Create a 20GB sparse file-backed VBD:

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

Make a ext3 file system in the disk file:

# mkfs -t ext3 vmdisk0

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:

Download.

Create an installation profile f11.install:

name="F11INSTALL"
memory=1536
disk = ['tap:aio:/home/xen/vmdisk0,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/vmdisk0,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:

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *