First start with partitioning the partition (in my case it is /dev/sda4) by executing fdisk /dev/sda4. I’ve used the following layout:
Device Boot Start End Blocks Id System
/dev/sda4p1 1 16654 133773223+ 83 Linux
/dev/sda4p2 16655 16898 1959930 82 Linux swap / Solaris
After finishing this step it may be possible that you need to reboot the server, because the kernel can’t read the new partition table. Pay attention on the output which is written to the screen after quitting fdisk.
Now we need to install the package multipath-tools to get the tool kpartx. This is necessary to create the appropriate files in dev to access the partitions of the partition.
Installing multipath-tools
aptitude install multipath-tools
Create files in dev
kpartx -a -v /dev/sda4
This command will create the files sda4p1 and sda4p2 in /dev/mapper. Now we are able to format the root-filesystem and to create the swap area of the new domU.
mke2fs -j /dev/mapper/sda4p1 && mkswap /dev/mapper/sda4p2 && swapon /dev/mapper/sda4p2
When the formatting process is finished, we can start installing the OS for the new domU to the partition. In my case I’ve had a second harddisk (/dev/sdb) on which a Debian Etch has been installed. So I just sync the content of this disk to the new filesystem.
mkdir /mnt/source
mkdir /mnt/target
mount /dev/sdb1 /mnt/source
mount /dev/mapper/sda4p1 /mnt/target
rsync -avxH --numeric-ids /mnt/source /mnt/target
cp -av /lib/modules/2.6.22-14-xen /mnt/target/lib/modules/
umount /mnt/target
umount /mnt/source
After installing the guest OS you should be able to boot the freshly created domU with the Xen-Hypervisor. My domU-config (/etc/xen/domu.example.com) to achieve this goal looks like like below.
arch = os.uname()[4]
if re.search('64', arch):
arch_libdir = 'lib64'
else:
arch_libdir = 'lib'
kernel = "/boot/vmlinuz-2.6.22-14-xen"
ramdisk = "/boot/initrd.img-2.6.22-14-xen"
builder='linux'
memory = 1024
name = "domu.example.com"
vcpus=2
vif = [ 'bridge=xenbr0' ]
disk = [ 'phy:sda4,sda,w' ]
root = "/dev/sda1 ro"
extra = "2 TERM=xterm xencons=tty console=tty1 clock=jiffies"
device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
boot="c"
sdl=0
vnc=0
vncpasswd=''
stdvga=0
serial='pty'
Let’s come to the end and start the domU!
xm create domu.example.com