XEN Virtual Machine

Create partition and File-system

Now that you can see the iSCSI device we can create partitions for the virtual machine to use. We just need to create the simplest of patitions, one for the root file-system of the virtual machine and one for swap. You can use fdisk or cfdisk for this, or any other partitioning programme. Your partitions in fdisk might look something like this:

dangermouse:~# fdisk /dev/iscsi_0
Command (m for help): p

Disk /dev/iscs_0: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/iscsi_01               1         249     2000061   82  Linux swap / Solaris
/dev/iscsi_02             250        7296    56605027+  83  Linux

Now that we have created the partitions we need to create file-systems on them.

dangermouse:~# mkswap /dev/iscsi_01
Setting up swapspace version 1, size = 5115 kB
no label, UUID=055d2ab4-d2ab-4779-818c-71d4950c08df
dangermouse:~# mke2fs -j /dev/iscsi_02
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1256 inodes, 5000 blocks
250 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=5242880
1 block group
8192 blocks per group, 8192 fragments per group
1256 inodes per group

Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Create Virtual Machine

I am going to create a Debian virtual machine using debootstrap.

dangermouse:~# mount /dev/iscsi_02 /mnt
dangermouse:~# debootstrap sarge /mnt
I: Retrieving Release
I: Retrieving Packages
......

Once debootstrap is completed we need to setup the machine a little bit. We need to disable tls again, setup the /etc/fstab and the network interfaces and create tty and console devices. We also need to copy the kernel modules to the virtual machine.

dangermouse:~# mv /mnt/lib/tls /mnt/lib/tls.disabled
dangermouse:~# cat <<! > /mnt/etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/hda1       none            swap    sw              0       0
/dev/hda2       /               ext3    defaults,errors=remount-ro 0       1
!
dangermouse:~# echo "virtaul01" > /mnt/etc/hostname
dangermouse:~# cat <<! >/mnt/etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static
        address 192.168.1.10
        netmask 255.255.255.0
        broadcast 192.168.1.255
        network 192.168.1.0
        gateway 192.168.1.254
!
dangermouse:~# cd /mnt/dev
dangermouse:/mnt/dev# ./MAKEDEV console tty1 tty2 tty3 tty4 tty5 tty6
dangermouse:~# cp -a /lib/modules/`uname -r` /mnt/lib/modules
dangermouse:~# umount /mnt

Make sure you unmount the disk ready for XEN to run the machine. If you don't you will destroy the filesystem.

Setup and Start Virtual Machine

Now that we have a basic Debian machine ready, we need to setup the XEN virtual machine config file. This file needs to be on both clients, buggles and dangermouse.

dangermouse:~# cat <<! >/etc/xen/virtual01
kernel = "/boot/vmlinuz-2.6.16-1-xen-686"
memory = 128
name = "virtual01"
vif = [ 'ip=192.168.1.10' ]
disk = [ 'phy:/dev/iscsi_02,hda2,w','phy:/dev/iscsi_01,hda1,w' ]
root = "/dev/hda2 ro"
extra = "2"
ramdisk = '/boot/initrd.img-2.6.16-1-xen-686'
!

Now that we have a config file lets try starting the virtual machine on both of the clients one after the other, shuting it down each time.

dangermouse:~# xm create -c virtual01

This command should produce what looks to be a machine booting, and hopefully it will get all the way to the console where you can log in as root. Once logged in, shut the machine down in the normal way, eg shutdown -h now.

Celebrate! Well done we have a working XEN virtual machine, also known as a domain U. Now repeat the xm create -c virtual01 command on buggles (the other client) to ensure everything is setup and working on there. In each instance test you can ping the ethernet interface from a remote machine.