Inicio / Blog's y documentación / Blogs / jmedina / Como crear maquinas virtuales con xen-tools usando un CD o ISO como repositorio

Como crear maquinas virtuales con xen-tools usando un CD o ISO como repositorio

Si usamos las herramientas xen-tools para la creación de maquinas virtuales, es posible que utilices el metodo bootstrap para hacer la instalación de maquinas Debian/Ubuntu, el metodo bootstrap por default utiliza como fuente de instalación un mirror de debian en Internet, por ejemplo: http://ftp.us.debian.org/debian/, posiblemente nosotros ya tenemos CD de instalación o la imagen ISO del CD por lo que queremos utilizar este medio y así ahorrarnos el ancho de banda que por default usa el metodo bootstrap.

Para poder utilizar un CD como fuente de instalación para xen-tools haremos lo siguiente:

- Montar el CD de Ubuntu:

# mount /dev/hdd /media/cdrom/
mount: block device /dev/hdd is write-protected, mounting read-only

- Comprobamos que el CD este montado:

# mount | grep cd
/dev/scd0 on /media/cdrom type iso9660 (ro)

El CD esta montado en /media/cdrom/

En el caso que desee utilizar una imagen ISO, entonces puede usar algo así:

# mount -o loop /tmp/ubuntu-8.04.1-server-i386.iso /media/cdrom

- Ejecutar el comando xen-create-image para crear el DomU

# xen-create-image --dir=/xen-images --hostname=vmbase --dhcp \
--install-method=debootstrap --dist=hardy --mirror=file://media/cdrom/ \
--passwd
General Information
--------------------
Hostname : vmbase
Distribution : hardy
Partitions : swap 128Mb (swap)
 / 4Gb (ext3)
Image type : sparse
Memory size : 128Mb
Kernel path : /boot/vmlinuz-2.6.24-22-xen
Initrd path : /boot/initrd.img-2.6.24-22-xen
Networking Information
----------------------
IP Address : DHCP [MAC: 00:16:3E:A9:AA:B4]
Creating partition image: /xen-images/domains/vmbase/swap.img
Done
Creating swap on /xen-images/domains/vmbase/swap.img
Done
Creating partition image: /xen-images/domains/vmbase/disk.img
Done
Creating ext3 filesystem on /xen-images/domains/vmbase/disk.img
Done
Installation method: debootstrap
Done
Running hooks
Done
No role scripts were specified. Skipping
Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done
Logfile produced at:
 /var/log/xen-tools/vmbase.log

- Viendo el archivo de configuración del DomU vmbase:

# grep -vE '^#|^$' /etc/xen/vmbase.cfg
kernel = '/boot/vmlinuz-2.6.24-22-xen'
ramdisk = '/boot/initrd.img-2.6.24-22-xen'
memory = '128'
root = '/dev/xvda2 ro'
disk = [
 'file:/xen-images/domains/vmbase/swap.img,xvda1,w',
 'file:/xen-images/domains/vmbase/disk.img,xvda2,w',
 ]
name = 'vmbase'
dhcp = 'dhcp'
vif = [ 'mac=00:16:3E:A9:AA:B4' ]
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
extra = '2 console=xvc0'

NOTA: Los archivos de confguración que genera xen-tools utilizan el parametro file:// dentro del
bloque de configuración disk para indicar la ruta a los dispositivos que usará la maquina virtual,
en Xen 3.2, el parametro file se ha dejado de usar en favor del parametro tap:aio, por ejemplo
para vmbase:

disk = [
 'file:/xen-images/domains/vmbase/swap.img,xvda1,w',
 'file:/xen-images/domains/vmbase/disk.img,xvda2,w',
 ]

Debemos de cambiar file por tap:aio, podemos hacer una busqueda/reemplazo con sed:

# sed -e 's/file/tap:aio/' -i /etc/xen/vmbase.cfg
y podemos comprobar la configuración:
# grep -A3 ^disk /etc/xen/vmbase.cfg
disk = [
 'tap:aio:/xen-images/domains/vmbase/swap.img,xvda1,w',
 'tap:aio:/xen-images/domains/vmbase/disk.img,xvda2,w',
 ]

Si no se cambia el parametro file, entonces, al tratar de arrrancar un domU veremos un mensaje algo así:

# Error: Device 51713 (vbd) could not be connected.

 losetup /dev/loop2 /xen-images/domains/vmbase/swap.img failed

- Arrancando el DomU vmbase

# xm create -c vmbase.cfg
Using config file ./vmbase.cfg;.
Started domain vmbase
 [ 0.000000] Linux version 2.6.24-22-xen (buildd@vernadsky) (gcc version 4.2.3

 (Ubuntu 4.2.3-2ubuntu7))

 #1 SMP Mon Nov 24 21:30:37 UTC 2008 (Ubuntu 2.6.24-4.6-generic)

...
...
 * Mounting local filesystems...                   [ OK ]
 * Activating swapfile swap...                      [ OK ]
 * Checking minimum space in /tmp...        [ OK ]
 * Configuring network interfaces...            [ OK ]
 * Starting system log daemon...                [ OK ]
 * Starting kernel log daemon...                  [ OK ]
 * Running local boot scripts (/etc/rc.local) [ OK ]
Ubuntu 8.04.1 vmbase xvc0
vmbase login: root
Password:
Linux vmbase 2.6.24-22-xen #1 SMP Mon Nov 24 21:30:37 UTC 2008 i686
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
root@vmbase:~#

- Verificando en el Dom0 que el domU este iniciado:

# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1893 2 r----- 1701.6
vmbase 8 128 1 -b---- 10.3

Si desea instalar la DomU utilizando volumens LVM debe de utilizar este comando:

# xen-create-image --fs=ext3 --size=4GB --swap=256Mb --lvm=VGData01 \
--hostname=ushldap --dhcp --install-method=debootstrap --dist=hardy \
--mirror=file://media/cdrom/ --passwd

General Information
--------------------
Hostname       :  ushldap
Distribution   :  hardy
Partitions     :  swap            256Mb (swap)
                 /               4GB   (ext3)
Image type     :  full
Memory size    :  128Mb
Kernel path    :  /boot/vmlinuz-2.6.24-22-xen
Initrd path    :  /boot/initrd.img-2.6.24-22-xen

Networking Information
----------------------
IP Address     : DHCP [MAC: 00:16:3E:D4:D7:DF]


Creating swap on /dev/VGData01/ushldap-swap
Done

Creating ext3 filesystem on /dev/VGData01/ushldap-disk
Done
Installation method: debootstrap
Done
Running hooks
Done
No role scripts were specified.  Skipping

Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done
Logfile produced at:
        /var/log/xen-tools/ushldap.log

Con el comando anterior se creo una maquina virtual y automaticamente creará los volumens logicos ushldap-swap y ushldap-disk en el Volume Group VGData01.

Comentarios

Conectar o create una cuenta de usuario para comentar.

Este es mi blog personal en Compugraf, el objetivo es que sirva como una bitácora con experiencias, tips, noticias relacionadas al software libre y GNU/Linux. Me pueden contactar en:

E-mail: jmedina[aRR0Ba]e-compugraf.com

IM (MSN/Gtalk): jmedina[aRR0Ba]e-compugraf.com

Mis Galerias

Lun Mar Mié Jue Vie Sáb Dom
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30