Howto create CentOS Xen VM under Ubuntu Dom0
In this article, I will show you how to create CentOS 5.2 virtual machines under a Ubuntu 8.04 server LTS dom0 (Xen 3.2).
First you need to create some directories :
mkdir /home/xen/domains/centos mkdir /mnt/img mkdir /mnt/vm1
Next get the image from jailtime.org.
Put the file in /home/xen/domains/centos and uncompress it (from here I will use the AMD64 file) :
cd /home/xen/domains/centos/ tar -xjf centos.5-2.64.20080708.img.tar.bz2
Next we create empty files for the filesystem (2GB) and swap (256MB) :
cd /home/xen/domains/centos dd if=/dev/zero of=Cent_base.img bs=1024k count=2048 dd if=/dev/zero of=Cent_swap.img bs=1024k count=256
mkfs.ext3 Cent_base.img
mkswap Cent_swap.img
Next we mount the img file from jailtime.org and copy everything to our empty img file :
mount -o loop centos.5-2.64.img /mnt/img mount -o loop /home/xen/domains/centos/Cent_base.img /mnt/vm1 cp -a /mnt/img/* /mnt/vm1/
Edit the network configuration file :
vi /mnt/vm1/etc/sysconfig/network-scripts/ifcfg-eth0
and make it look like this (modify according to your network settings) :
TYPE=Ethernet DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.0.100 NETMASK=255.255.255.0 GATEWAY=192.168.0.1
Next, modify the hostname :
vi /mnt/vm1/etc/sysconfig/network
NETWORKING=yes HOSTNAME=centos.example.com
Add your nameservers to resolv.conf :
vi /mnt/vm1/etc/resolv.conf
Change this according to your NS :
nameserver 24.200.241.37 nameserver 24.201.245.77 nameserver 24.200.243.189
Next we allow root login thru SSH :
vi /mnt/vm1/etc/ssh/sshd_config
and modify PermitRootLogin option :
[...] PermitRootLogin yes [...]
Next we copy some files :
cp -av /lib/modules/`uname -r` /mnt/vm1/lib/modules/
A little tweak needs to be done to access the VM in console mode :
vi /mnt/vm1/etc/inittab
find :
[...] 1:2345:respawn:/sbin/mingetty tty1 [...]
and replace with :
[...] 1:2345:respawn:/sbin/mingetty console [...]
Now we can unmount both img files :
umount /mnt/img /mnt/vm1
Now we will configure the VM :
cp /home/xen/domains/centos/centos.5-2.64.xen3.cfg /etc/xen/ vi /etc/xen/centos.5-2.64.xen3.cfg
and make it look like this (change kernel version if you have something different than 2.6.24-23, try 'uname -r') :
name = 'cent5' kernel = '/boot/vmlinuz-2.6.24-23-xen' ramdisk = '/boot/initrd.img-2.6.24-23-xen' memory = '256' root = '/dev/sda1 ro' disk = [ 'tap:aio:/home/xen/domains/centos/Cent_base.img,sda1,w', 'tap:aio:/home/xen/domains/centos/Cent_swap.img,sda2,w' ] dhcp = 'dhcp' vif = [ '' ] on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart'
Delete the files from jailtime.org :
rm -f /home/xen/domains/centos/centos.5-2.64.*
Now you can finally create the VM :
xm create -c /etc/xen/centos.5-2.64.xen3.cfg
Login as root, password is 'password'
To put this on a partition for better performance, read this article
Reference : http://www.howtoforge.com/create-centos5.2-domu-on-ubuntu-hardy-dom0
- subjects:

