XEN CentOS as host and guest

Posted on Sun 11 July 2010 by Pavlo Khmel

Installation and configuration in command line without GUI.

Install

yum install xen virt-manager kernel-xen
chkconfig xend on
reboot

Full virtualization (hardware VMX) should be supported by CPU: Intel®Virtualization Technology (VT) or Pacifica (AMD). Other case paravirtualization only. Check:

# Intel CPU
$ xm dmesg | grep VMX
(XEN) VMXON is done
(XEN) VMXON is done
...
(XEN) VMXON is done
(XEN) VMXON is done
(XEN) VMXON is done

# AMD CPU
$ xm dmesg | grep -i svm
(XEN) AMD SVM Extension is enabled for cpu 0.
(XEN) AMD SVM Extension is enabled for cpu 1.

# Or:
$ xm info | grep caps
...
xen_caps              : xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p

hvm-3.0-x86_32 - mean that XEN have detected CPU with Intel VT or AMD-V technology.

This installation without hardware VMX:

$ xm info | grep caps
hw_caps         : afebfbff:20100000:00000000:00000140:0000e31d:00000000:00000001
xen_caps        : xen-3.0-x86_32p

Paravirtualization support guest install only via NFS, FTP or HTTP source.

mkdir /vm
cp -vR /media/CentOS_5.4_Final /vm
# Guest IP address 192.168.0.10.
cat /etc/exports
/vm/CentOS_5.4_Final 192.168.0.0/24(rw,sync)
/etc/init.d/nfs start

Guest install

Interaction mode

virt-install --prompt

One command line:

$ virt-install -n phn-node1 -r 256 -f /vm/phn-node1.dsk -s 3 --nographics -p -l nfs:192.168.0.10:/vm/CentOS_5.4_Final
Starting install...
Retrieving file .treeinfo...                             | 413 B     00:00
Retrieving file vmlinuz...                               |2.1 MB     00:00
Retrieving file initrd.img...                            |6.6 MB     00:00
Creating domain...                                       |   0 B     00:00
error: Failed to get local hostname

Domain installation still in progress. You can reconnect to
the console to complete the installation process.

Explanation:
-n phn-node1 - guest name;
-r 256 - RAM amount for guest;
-f /vm/phn-node1.dsk - disk file location;
-s 3 - disk size;
--nographics - without GUI console (VNC);
-p - paravirtualization;
-l nfs:192.168.0.10:/vm/CentOS_5.4_Fina - path to installation files.

Ignore "error: Failed to get local hostname".

I have DHCP in my network.

Connect to VM console:

xm console phn-node1

Disconnect: Ctrl + ]

If there are not DHCP. You still need access to NFS share. Use IP in the same subnet.

Second VM was created phn-node2.

List VMs:

$ xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0    1762     1 r-----     41.7

Run first VM:

$ xm create phn-node1
Using config file "/etc/xen/phn-node1".
Started domain phn-node1

Run second VM:

$ xm create phn-node2
Using config file "/etc/xen/phn-node2".
Started domain phn-node2

List again:

$ xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0    1501     1 r-----     44.7
phn-node1                                  1     256     1 ------      2.5
phn-node2                                  2     256     1 ------      0.3

Autoboot

mv /etc/xen/phn-node1 /etc/xen/auto
# or link
ln -s /etc/xen/phn-node1 /etc/xen/auto/phn-node1

Remove VM

# Get name:
xm list
# Destroy system
xm destroy phn-node1
# remove autoboot
rm /etc/xen/auto/phn-node1
# remove config
rm /etc/xen/phn-node1
# remove disk file
rm /vm/phn-node1.dsk

More information

virsh help
man xm
virt-install --help

If you have error "xenconsole: Could not read tty from store: No such file or directory":

$ xm console node1
xenconsole: Could not read tty from store: No such file or directory
# fix
$ /usr/sbin/xenconsoled
$ xm console node1

After adding new NIC on XEN host. If xenbr0 disappeared, try:

/etc/xen/scripts/network-bridge stop
/etc/xen/scripts/network-bridge start
/etc/xen/scripts/network-bridge status