Machine virtuelle XEN
Introduction
Xen est un logiciel libre de virtualisation puissant. Je teste ici une installation rapide de cet outil.
Il faut d'abord que XEN soit intégré dans Linux (RPM xen et kernel-xen).
Préparation de la machine virtuelle
On crée un fichier vide de 1Mo.
[root@perseus]#cd /var/lib/xen/images
[root@perseus images]#dd if=/dev/zero of=/srv/xen/test.img oflag=direct bs=1M seek=2047 count=1
[root@perseus images]#ls -Z test.img
On récupère les fichiers de démarrage pour les systèmes et on prépare le fichier kickstart sur un serveur HTTP.
[root@perseus images]#cd /boot
[root@perseus boot]#wget mirror.centos.org/centos/5.2/os/i386/images/xen/initrd.img -O initrd-xen-test.img
[root@perseus boot]#wget mirror.centos.org/centos/5.2/os/i386/images/xen/vmlinuz -O vmlinuz-xen-test
[root@WRITER html]# cd /var/www/html
[root@WRITER html]# perl -e 'print crypt("***", "XEN") . "\n";'
XEklZ**Ke6oB.
[root@WRITER html]# cat ks.cfg
install
url --url ftp://mirrors.ircam.fr//pub/CentOS/5.2/os/i386
lang fr_FR.UTF-8
keyboard fr-latin9
network --device eth0 --bootproto dhcp
rootpw --iscrypted XEklZ**Ke6oB.
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --enforcing
timezone --utc Europe/Paris
bootloader --location=mbr --driveorder=xvda --append="console=xvc0"
clearpart --all --initlabel --drives=xvda
part /boot --fstype ext3 --size=100 --ondisk=xvda
part pv.2 --size=0 --grow --ondisk=xvda
volgroup VolGroup00 --pesize=32768 pv.2
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=256 --grow --maxsize=512
%packages
@core
@engineering-and-scientific
@web-server
Installation de la machine virtuelle
[root@perseus boot]#cd /etc/xen
[root@perseus xen]# cat /etc/xen/xmtest
kernel="/boot/vmlinuz-xen-test"
ramdisk="/boot/initrd-xen-test.img"
extra="text ks=http://157.159.226.31/ks.cfg"
name="install"
memory="256"
disk=['tap:aio:/var/lib/xen/images/test.img,xvda,w',]
vif=['bridge=xenbr0',]
on_reboot='destroy'
on_crash='destroy'
[root@perseus xen]# xm create xmtest
Using config file "/etc/xen/xmtest".
Started domain install
[root@perseus xen]#xm console install
...
Démarrage et utilisation de la machine virtuelle
[root@perseus xen]# cat xmtest2
name="test"
memory="256"
disk=['tap:aio:/var/lib/xen/images/test.img,xvda,w',]
vif=['bridge=xenbr0',]
bootloader="/usr/bin/pygrub"
on_reboot='destroy'
on_crash='destroy'
[root@perseus xen]# xm create -c xmtest2
...
[root@perseus xen]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 747 2 r----- 1238.0
test 2 256 1 r----- 7.6
[root@perseus xen]# xm destroy test