Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2012-08-27 00:42:12
Size: 17243
Comment:
Revision 4 as of 2012-08-27 00:49:29
Size: 17551
Comment:
Deletions are marked like this. Additions are marked like this.
Line 59: Line 59:
'''NOTA:''' Esto no es más necesitado desde la versión Wheezy. '''NOTA:''' Esto no es necesario desde la versión Wheezy.

== Comprobando qué tipo de virtualización que soporta nuestro host ==

En el caso de querer hacer virtualización completa debemos verificar si nuestro CPU soporta esta tecnología, para verificarlo hacemos el siguiente comando.

{{{
egrep '(vmx|svm)' /proc/cpuinfo
}}}

VMX para Intel y SVM para AMD

Translation(s): ?English

(!) ?/Discussion


Resumen Xen

Xen es un hypervisor de código abierto (GPL) de tipo-1 o Baremetal, el cual hace posible correr muchas instancias de un sistema operativo o inclusive diferentes sistemas operativos en paralelo dentro de una sola maquina (o host).

Algunas de las características claves de Xen son:

  • Pequeño consumo de RAM e interfaz (alrededor de 1MB en tamaño). Esto se debe a que Xen utiliza un microkernel diseñado para ser usado en poca cantidad de memoria RAM e interfaz limitada para los guest (invitados), esto a su vez lo hace mas robusto y seguro que otros Hipervisores.
  • Sistema operativo agnóstico: La mayoría de las instalaciones corren con Linux como un conjunto del sistema principal (a.k.a "domain 0" o "dominio 0"). Pero un número de otros sistemas operativos pueden ser usados en su lugar, incluyendo NetBSD y ?OpenSolaris.

  • Controlador aislado: Xen tiene la capacidad de alojar el controlador principal de un sistema para ejecutarlo en una maquina virtual. Si el controlador falla o su funcionamiento se ve comprometido, la maquina virtual (MV) contiene un controlador que puede ser reiniciado sin afectar el resto del sistema.
  • Paravirtualización: los invitados (guest) completamente paravirtualizados han sido optimizados para correr en una máquina virtual. Esto permite a los invitados ejecutarse mucho más rápido que con una extensión real de hardware (HVM siglas en inglés). Adicionalmente Xen puede correr en hardware que no soporta extensión real de hardware.

Lee el Xen Overview (inglés) en el Wiki de Xen para más información.

Tipos de invitados (Guest)

Xen soporta ejecución con dos diferentes tipos de invitados: Paravirtualización (PV) y completa o Virtulización con Asistencia de Hardware (HVM). Ambos tipos de invitados pueden ser usados al mismo tiempo en un mismo sistema Xen. También es posible usar técnicas usadas para Paravirtualización en un invitado HVM: esencialmente creando una continuidad entre PV y HVM. Este enfoque es llamado PV en HVM. De nuevo invito a que lea el Xen Overview en el Wiki de Xen para más información.

Dominio 0 (Domain 0)

Xen tiene un dominio especial llamado dominio 0 (Domain 0 en inglés) el cual contiene controladores de hardware así como también tiene un conjunto de herramientas para el control de las Maquinas Virtuales (MV). El Dominio 0 a menudo se le llama el "dom0".

Instalación del Domain 0 (Host)

Instalación inicial del Domain 0

Antes de instalar Xen deberás instalar Debian en la maquina principal (host). Esta instalación será de forma básica para el Domain 0.

La instalación de Debian puede ser hecha de una manera normal usando el DebianInstaller. Lee Debian Release Notes para más información de como instalar Debian.

En orden de instalar Xen se requiere ya sea un 32-bit PC (i386) o 64-bit PC (amd64) para instalarlo en Debian

En general tu puedes instalar el Domain 0 Debian como cualquier otra instalación. Como sea el Wiki de Xen tiene algunas consideraciones Host OS Installation Considerations(inglés) que tal vez te interesen. Lo importante considerar la tabla de particiones de la maquina principal que sí tendrá un impacto en la configuración del disco de los invitados (Guest).

Si tiene un sistema Debian instalado entonces continúe con la siguiente sección.

Instalando los paquetes de Xen

El software Xen y debootstrap en Squeeze (Debian 6.0) son mucho mas nuevos que en la versión Lenny. Debido a eso trabajar con Xen se ha vuelto mucho mas fácil.

La configuración descrita aquí está probada para maquinas virtuales en Debian Squeeze y Ubuntu Maverick pero también sirve para otras más.

Primero instalar el hipervisor, Kernel Xen y las herramientas de Xen.

apt-get install xen-linux-system-arquitectura xen-utils-4.0 bridge-utils xen-tools

Donde Arquitectura dependerá de la arquitectura que hayas instalado.

Para tener soporte Xen HVM en Squeeze el modelo de dispositivo qemu nos proveerá la emulación necesaria para la infraestructura de un invitado (guest) con HVM, esto también es requerido.

apt-get install xen-qemu-dm-4.0

NOTA: Esto no es necesario desde la versión Wheezy.

Comprobando qué tipo de virtualización que soporta nuestro host

En el caso de querer hacer virtualización completa debemos verificar si nuestro CPU soporta esta tecnología, para verificarlo hacemos el siguiente comando.

egrep '(vmx|svm)' /proc/cpuinfo

VMX para Intel y SVM para AMD

Iniciando desde Xen de manera nativa

Debian Squeeze usa Grub 2 por omisión éste lista los kernel ordinarios de primero y después lista el hipervisor Xen con su kernel.

Se puede cambiar esto dandole a Grub la preferencia de iniciar por el Kernel Xen cambiando la prioridad del grub en el script de configuración (20_linux_xen) haciendo que sea más alta que la configuración estándar de Linux (10_linux). Esto es mas fácil hacerlo usando dpkg-divert:

dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen

Para deshacer el cambio:

dpkg-divert --rename --remove /etc/grub.d/20_linux_xen

Después de cualquier modificación en la configuración del grub se debe aplicar los cambios ejecutando:

update-grub

Configurar la red

En orden de dar acceso de la red a los invitados es necesario configurar la red del dominio 0 (domain 0) apropiadamente. La configuración más común es usar el software Bridge.

Es recomendable que manejes tu propio puente de red (bridge) usando el Debian network bridge (inglés). En el Wiki de Xen Host Configuration/Networking (inglés) también puedes conseguir información útil. Xen brinda scripts de redes que no siempre son seguros y serán removidos de versiones posteriores. Ellos están deshabilitados por omisión en los paquetes de Debian.

Other configuration tweaks

Configure Boot Parameters

You may also want to pass some boot parameters to Xen when starting up in normal or recovery mode. Add these variables to /etc/default/grub to achieve this:

# Xen boot parameters for all Xen boots
GRUB_CMDLINE_XEN="something"
# Xen boot parameters for non-recovery Xen boots (in addition to GRUB_CMDLINE_XEN)
GRUB_CMDLINE_XEN_DEFAULT="something else"

Remember to apply the change to the grub configuration by running update-grub!

More information on the available hypervisor command line options can be found in the upstream documentation.

Configure Domain 0 Memory

By default on a Xen system the majority of the hosts memory is assigned to dom0 on boot and dom0's size is dynamically modified ("ballooned") automatically in order to accomodate new guests which are started.

However on a system which is dedicated to running Xen guests it is better to instead give dom0 some static amount of RAM and to disable ballooning.

The following examples use 1024M.

In order to do this you must first add the dom0_mem option to your hypervisor command line. This is done by editing /etc/default/grub and adding

# Xen boot parameters for all Xen boots
GRUB_CMDLINE_XEN="dom0_mem=1024M"

Remember to apply the change to the grub configuration by running update-grub!

Then edit /etc/xen/xend-config.sxp to configure the toolstack to match by changing the following settings:

(dom0-min-mem 1024)
(enable-dom0-ballooning no)

At this point you should reboot so that these changes take effect.

Configure guest behaviour on host reboot

By default, when Xen dom0 shuts down or reboots, it tries to save (i.e. hibernate) the state of the domUs. Sometimes there are problems with that - it could fail because of a lack of disk space in /var, or because of random software bugs. Because it is also clean to just have the VMs shutdown upon host shutdown, if you want you can make sure they get shut down normally by setting these parameters in /etc/default/xendomains:

XENDOMAINS_RESTORE=false
XENDOMAINS_SAVE=""

Enable Serial Console

To get output from GRUB, the Xen hypervisor, the kernel and getty (login prompt) via both VGA and serial console to work, here's an example of the right settings on squeeze:

Edit /etc/default/grub and add:

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1"
GRUB_TERMINAL="console serial"
GRUB_TIMEOUT=5
GRUB_CMDLINE_XEN="com1=9600,8n1 console=com1,vga"
GRUB_CMDLINE_LINUX="console=tty0 console=hvc0"

Here's what I used to configure the serial console (for a Supermicro X8STi-F motherboard with IPMI and SOL):

GRUB_CMDLINE_XEN="loglvl=all guest_loglvl=all com1=115200,8n1,0x3e8,5 console=com1,vga"
GRUB_CMDLINE_LINUX="console=hvc0 earlyprintk=xen"

In /etc/inittab you need at least these lines:

1:2345:respawn:/sbin/getty 38400 hvc0
2:23:respawn:/sbin/getty 38400 tty1
# NO getty on ttyS0!

This way, tty1 will show up at the VGA output, and the hvc0 will show up at the serial console.

To keep both Xen and dom0 kernel output on the same tty, just omit the "vga"-related settings from the above setup.

If you need to debug Xen and see a crash dump of the kernel, you can do it using IPMITool if your server has SOL:

ipmitool -I lanplus -H server-ip-address -U your-username sol activate | tee my-log-file.txt

Installation as a DomU (guest)

Using xen-tools

xen-tools is a set of scripts which can easily create fully configured Xen guest domains.

Once you have installed dom0 you can install xen-tools on your host with:

apt-get install xen-tools

Then you can create virtual machines with this command:

xen-create-image --hostname <hostname> --ip <ip> --vcpus 2 --pygrub --dist <lenny|squeeze|maverick|whatever>

To configure xen-tools, you can edit /etc/xen-tools/xen-tools.conf which contains default values that the xen-create-image script will use. The xen-create-image(8) manual page contains information on the available options.

Possible problems and bugs

  • If your domU kernel happens to miss support for the xvda* disk devices (the xen-blkfront driver), use the --scsi option that makes the VM use normal SCSI HD names like sda*. You can also set scsi=1 in /etc/xen-tools/xen-tools.conf to make this the default.

  • When using xen-tools with --role on Squeeze be aware of #588783: 'Should mount /dev/pts when creating image'. This is fixed in Wheezy.

Using Debian Installer

The Xen wiki page Debian Guest Instalation Using DebianInstaller contains instructions on how to install Xen DomU from Lenny onwards using ?Debian Installer.

Upgrading/transition

See also: Debian Release Notes

Upgrading a server to Squeeze that uses both Lenny Dom0 and DomU's is fairly straightforward. There are a few catches that one needs to be aware of however: Reference

  • Dom0 Issues

    • The Xen packages will not upgrade themselves. They must be manually removed and the latest Xen packages must be installed from the Debian Squeeze repository through apt.
    • xen.independent_wallclock sysctl setting is not available for newer squeeze kernels supporting pvops. If you have relied on it, you would have to run ntpd in dom0 and domUs. source

  • DomU Issues

    • A Squeeze DomU will not be able to boot on the Xen-3.2 package supplied by Lenny because this older version will not support grub2. A Lenny DomU can be upgraded to Squeeze while running on a Lenny Dom0 but it will not be able to be booted until the Dom0 has been upgraded to the Xen-4.0 packages.
    • The entries added to chain load grub1 to grub2 will not allow pygrub to find the correct partition. Before rebooting a freshly upgraded Squeeze DomU, make sure to rename or remove /boot/grub/menu.lst. This will force pygrub to look for the /boot/grub/grub.cfg file which will be in the correct format.
    • A qcow image created with qcow-create and the BACKING_FILENAME option on Lenny will not be able to boot on Squeeze because the ability to use qcow images as backing files has been removed in Xen versions after 3.2. Also, if you try to boot such an image on Squeeze, Xen will silently convert the qcow images L1 table to big endian (you'll find "Converting image to big endian L1 table" in the logfiles), effectively rendering the image unusable on both Squeeze and Lenny!

Note on kernel version compatibility

The new 2.6.32 kernel images have paravirt_ops-based Xen dom0 and domU support.

When you create an image for a modern Debian or Ubuntu domU machine, it will include a kernel that has pv_ops domU support, it will therefore not use a Xen kernel, but the "stock" one, as it is capable of running on Xen's hypervisor.

Possible problems and bugs

Older Releases

Xen Installation on Debian 5.0 ( Lenny )

Xen Installation on Debian 4.0 ( Etch )

The page ?DebianInstaller/Xen contains instructions on how to install Xen Dom0 and Etch DomU with DebianInstaller.

Package maintenance

Debian's Xen packages are maintained by the pkg-xen project. (developers' mailing list)

The Debian Developer's Package Overview page lists source packages that are maintained by the team.

Common Errors

dom0 automatic reboots

  • {i} Note: if Xen is crashing and reboot automatically, you may want to use noreboot xen option, to prevent it from rebooting automatically.

Edit /etc/default/grub and add the "noreboot" option to GRUB_CMDLINE_XEN, for example:

GRUB_CMDLINE_XEN="noreboot"

Error "Device ... (vif) could not be connected"

You need to configure some basic networking between dom0 and domU.

The recommended way to do this is to configure bridging in /etc/networking/interfaces. See BridgeNetworkConnections and/or the Xen wiki page Host Configuration/Networking for details.

  • {i} Note: The use of the 'network-script' option in /etc/xen/xend-config.sxp is no longer recommended.

'clocksource/0: Time went backwards'

If a domU crashes or freezes while uttering the famous lasts words 'clocksource/0: Time went backwards' see ?Xen/Clocksource.

PV drivers on HVM guest

It may be possible to build the PV drivers for use on HVM guests. These drivers are called unmodified_drivers and are part of the xen-unstable.hg repository. You can fetch the repository using mercurial thus:

  •   hg clone http://xenbits.xen.org/xen-unstable.hg

The drivers reside under xen-unstable.hg/unmodified_drivers/linux-2.6. The README in this directory gives compilation instructions.

A somewhat dated, detailed set of instructions for building these drivers can be found here:

http://wp.colliertech.org/cj/?p=653

Resources