Xen 
 
Home About Community Support Downloads
 
   

Xen Manual P2V process

Here are some notes on creating a Xen virtual machine from a physical linux machine. This document is in no way complete, but outlines the process I used to "virtualize" a SLES9 machine as a guest on a SUSE 10.1 host in the absence of a p2v tool.

create partitions

Create one or more partitions to hold the physical machine

rsync filesystem to the new partitions

Example rsync command from the physical host

cd /;rsync -av --delete --exclude-from="/root/rsync_exclude" -e ssh * 172.16.1.199:/mnt/pinot

this assumes that the partition you are rsync-ing to is mounted on /mnt/pinot on the destination host (172.16.1.199). Example rsync exclude file

Here we are excluding the pseudo filesystem /proc for obvious reasons, /media because we don't want to transfer removable media, /var/Backups and /SLES9 becuase it is a lot of stuff that doesn't need to be in the virtual machine. The commented lines are to preserve updated files after the initial rsync and setup of the virtual machine. Uncomment those lines for subsequent rsync's.

/media/
/proc/
/SLES9/
/var/Data
/var/data
/usr/local/src/
/var/Backups
#/etc/inittab
#/etc/fstab
#/etc/ssh/sshd_config
#/etc/sysconfig/network
#/etc/rc.d/rc3.d
#/etc/rc.d/rc4.d
#/etc/rc.d/rc5.d 

create a 'vm' definition file

  • Specify a unique MAC address. Otherwise Xen will specify a random one and I find networking is more straightforward if you specify one yourself. Only modify the last three values in the mac address.

Example

kernel = "/boot/vmlinuz-xen"
ramdisk = "/boot/initrd-xen"
memory = 1024
name = "pinot"
vif = [ 'mac=00:16:3e:00:25:c9' ]
disk = [ 'phy:/dev/system/pinot_root,hda1,w','phy:/dev/system/pinot_swap,hda2,w']
root = "/dev/hda1 ro"
extra = "3" 

after rsyncing edit /etc/fstab

Example fstab

/dev/hda1    /                    ext3       acl,user_xattr        1 1
/dev/hda2    swap                 swap       pri=42                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
#/dev/cdrom           /media/cdrom         subfs      fs=cdfss,ro,procuid,nosuid,nodev,exec,iocharset=utf8 0 0
#/dev/fd0             /media/floppy        subfs      fs=floppyfss,procuid,nodev,nosuid,sync 0 0
#/dev/shm             /var/spool/amavis/tmp tmpfs     defaults,size=500m,mode=700,uid=65,gid=101 0 0
/dev/shm             /var/spool/amavis/tmp tmpfs     defaults,size=64m,mode=700,uid=65,gid=101 0 0 

edit /etc/inittab

Example inittab

id:3:initdefault:
si::bootwait:/etc/init.d/boot
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
ls:S:wait:/etc/init.d/rc S
~~:S:respawn:/sbin/sulogin
ca::ctrlaltdel:/sbin/shutdown -r -t 4 now
kb::kbrequest:/bin/echo "Keyboard Request -- edit /etc/inittab to let this work."
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
sh:12345:powerfail:/sbin/shutdown -h now THE POWER IS FAILING
1:2345:respawn:/sbin/mingetty --noclear tty1

Booting the VM

It is recommended that you disable networking when first booting the vm. This can be done by commenting the vif line in /etc/xen/vm/<virtualhostname>. This is recommended to avoid IP conflicts. Once you change the IP of either the physical or virtual host, you can boot them both.

Final rsync

Once you are fairly confident that the new VM is working properly, you will want to do a "final" rsync to make sure the VM matches the physical machine as closely as possible. shut down services on the physical machine for the final rsync, shut down virtually all services on the physical machine, especially any services that rely on underlying databases like mysql, ldap, etc. The more you can shut down the better. This will insure that you get good copies of the underlying data. Then do your final rsync being careful to exclude files like /etc/inittab, /etc/fstab as discussed above.

Caveats

initrd

Don't remember the details, but I seem to remember something about the defaul initrd-xen not working until I unzipped it and rezipped it (on SUSE 10.1) like below. I also remember reading an explanation about why this was so. Here's the quote from http://gentoo-wiki.com/HOWTO_Xen_and_Gentoo

If your domain 0 uses an initrd, you can load that by adding another module line. Xen won't work with genkernel initrd images. You literally need to gunzip then gzip the initrd file again to get it to boot. It's not obvious why such a simple fix is necessary. For example to boot a non-enforcing SELinux system with EVMS on the root disk then try: The process for unzipping and zipping looks like this.

mv initrd-xen initrd-xen.gz
gunzip initrd-xen.gz
gzip initrd-xen
mv initrd-xen.gz initrd-xen

IPv6 issues

As I understand it, the Xen kernels do not currently support IPv6. Some services (most notably openLDAP) are configured by default to bind to IPv6. I needed to add the "-4" flag to my ldap server (via /etc/sysconfig/openldap) to

XenManualPtoVProcess (last edited 2006-07-10 01:06:54 by DerekDresser)