Translation(s): English - Indonesian - Español

(!) ?/Discussion


Sobre o Xen

Xen é um hipervisor de código aberto (GPL) do tipo-1 ou baremetal hypervisor, que torna possível executar muitas instâncias de um mesmo S.O. (Sistema Operacional) ou de diferentes S.O. em paralelo numa única máquina hospedeira (ou HOST).

Algumas das características chaves do Xen são:

Veja em Xen Overview para mais informações.

Tipos de VM Hospedadas

Xen suporta execução com 2 diferentes tipos de hospedados (guests): Paravirtualização (PV) e Completa ou Virtulização com Assistência de Hardware (HVM). Ambos os tipos de hospedados podem ser usados ao mesmo tempo em um mesmo sistema Xen. Também é possível usar técnicas da Paravirtualização em um hospedado HVM: essencialmente criando uma continuidade entre PV e HVM. Este enfoque é chamado de PV em HVM. Novamente recomendo que seja lido em Xen Overview para mais informações.

Dom0

Xen tem um domínio especial denominado "Domínio 0" ("Domain 0" em inglês) o qual contem os "drivers" (controladores) de "hardware" e um conjunto de ferramentas de controle das máquinas virtuais (VM). O Domínio 0 é também chamado "dom0".

Instalação do Dom 0 (Host)

Instalação Inicial do Host

Antes de instalar o Xen, você deverá instalar o Debian na máquina hospedeira (host). Esta instalação será a base para Dom0.

A instalação do Debian pode ser usual conforme DebianInstaller. Veja em Debian Release Notes para mais informações da instalação do Debian.

Para instalar o Xen será necessário um PC de 32 bits (i386) ou um PC de 64 bits (amd64) para instalar no Debian. Embora seja recomendado usar um hipervisor de 64 bits, o que não significa que o dom0 também seja um 64 bits; sendo bastante comum rodar dom0 de 32 bits em um hipervisor de 64 bits - configuração "32on64" (em inglês).

Em geral, você pode instalar o dom0 igual a qualquer outra instalação Debian. O que é importante considerar é a tabela de partição da máquina que tem um impacto sobre a configuração do disco do hospedado (guest). No Wiki do Xen Host OS Installation Considerations encontramos orientações interessantes: Se seu Debian dom0 será primariamente usado para rodar VMs, a boa regra é definir a partição "/" com 4GB, uma partição de swap (se RAM<=2GB então swap=RAM, senão swap=2GB (para RAM>2GB) ). A área de swap deverá determinar a quantidade de RAM oferecida ao Dom0, ver em Configure Domain 0 Memory

Use o restante do espaço em disco para um volume físico LVM (Logical Volume Management).

Se você tem um disco, a configuração seguinte será razoável: criar 3 partições físicas:

Se você já tiver um sistema Debian instalado, avance para a próxima seção.

Instalando Pacotes Xen

First install the hypervisor, xen aware kernel and xen tools. This can be done by a metapackage:

Os programas Xen e debootstrap do Squeeze (Debian 6.0) são muito mais recente do que a versão Lenny. Por isso o trabalho com Xen se tornou muito mais fácil.

A configuração descrita aqui é testado para máquinas virtuais no Debian Squeeze e Ubuntu Maverick, mas também usado para outros mais.

Primeiro instale o hypervisor, o kernel Xen e ferramentas Xen.

apt-get install xen-linux-system

Checando se nosso hospedeiro ("host") suporta HVM

No caso de querer usar a virtualização completa você precisará verificar se o processador suporta esta tecnologia, através do comando:

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

Se suportado, o comando "egrep" exibirá VMX para processadores Intel e SVM para processadores AMD.

No Squeeze (Debian 6.0), para se ter suporte HVM no Xen, é obrigatório a instalação do pacote "QEMU device model", o qual oferece a infraestrutura de emulação necessária para um hospedado (guest) HVM. Rode o comando abaixo para instalá-lo:

apt-get install xen-qemu-dm-4.0

No Wheezy (Debian 7) e superiores, isto não é mais necessário já que o modelo de dispositivo foi embutido bo pacote Xen.

Priorizando o XEN na partida do sistema

Debian Squeeze uses Grub 2 whose default is to list normal kernels first, and only then list the Xen hypervisor and its kernels.

You can change this to cause Grub to prefer to boot Xen by changing the priority of Grub's Xen configuration script (20_linux_xen) to be higher than the standard Linux config (10_linux). This is most easily done using dpkg-divert:

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

to undo this:

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

After any update to the Grub configuration you must apply the configuration by running:

update-grub

Configurando a Rede

In order to give network access to guest domains it is necessary to configure the domain 0 network appropriately. The most common configuration is to use a software bridge.

It is recommended that you manage your own network bridge using the Debian network bridge. The Xen wiki page Host Configuration/Networking also has some useful information. The Xen supplied network scripts are not always reliable and will be removed from a later version. They are disabled by default in Debian's packages.

If you have a router that assigns ip addresses through dhcp, the following is a working example of the /etc/network/interfaces file using bridge-utils software.

#The loopback network interface
auto lo
iface lo inet loopback

iface eth0 inet manual

auto xenbr0
iface xenbr0 inet dhcp
   bridge_ports eth0

#other possibly useful options in a virtualized environment
  #bridge_stp off       # disable Spanning Tree Protocol
  #bridge_waitport 0    # no delay before a port becomes available
  #bridge_fd 0          # no forwarding delay

Outras configurações

Configure a Memória do Domínio 0

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"

at the bottom of the file.

Note : On servers with huge memory, Xen kernel crash. You must set a dom0 memory limit. Take care on Wheezy, 1024M is not enough and cause kernel crash at boot with out-of-memory message.

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 CPUS do domínio 0

There are some useful tweaks of dom0 cpu utilization.

By default all CPUs are shared among dom0 and all domU (guests). It may broke dom0 responsibility if guests consume too much CPU time. To avoid this, it is possible to grant one (or more) processor core to dom0 and also pin it to dom0.

Add following options to /etc/default/grub to allocate one cpu core to dom0:

dom0_max_vcpus=1 dom0_vcpus_pin

Make such changes in /etc/xen/xend-config.sxp:

(dom0-cpus 1)

Configure o comportamento do S.O. hospedado (guest) na inicialização do sistema

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=""

Configure os Parâmentros de Inicialização

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 Parâmetros "PCI pass-through"

This information is incomplete for Squeeze and needs to be updated for Wheezy

To enable PCI pass-through, you need to know the BDF (Bus, Device, Function) id of the device. This is obtained through the lspci command, with the output containing the BDF in the format: (BB:DD.F) at the start of the line. To hide a device from Dom0 you will need to pass these boot parameters to Xen when starting. For example if using a Dom0 with 512M of memory and two devices at 01:08.1 and 01:09.2, add these variables to /etc/default/grub to achieve this:

# Xen boot parameters for all Xen boots
GRUB_CMDLINE_XEN="dom0_mem=512M pciback.hide=(01:08.1)(01:09.2)"
# Xen boot parameters for non-recovery Xen boots (in addition to GRUB_CMDLINE_XEN)
GRUB_CMDLINE_XEN_DEFAULT="something else"

for Squeeze use "pciback.hide" (kernels < 2.6.32.10), for Wheezy (I have not tested this yet) use "xen-pciback.hide"

for Squeeze you need to pass all of the devices on the bus, eg to pass any device on the 01:DD.F bus, you have pass all of them: (01:08.1)(01:09.2)(01:09.3)etc.

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

At least in Wheezy (not tested in Squeeze) the xen-pciback module needs to be configured through modprobe.conf and added to the initramfs additionally.

Configure the xen-pciback module by adding a modprobe include file (e.g. /etc/modprobe.d/xen-pciback.conf) with the following content (given that the PCI device would be assigned to module e1000e normally):

install e1000e /sbin/modprobe xen-pciback; /sbin/modprobe --first-time --ignore-install e1000e
options xen-pciback hide=(0000:03:00.0) 

Add the xen-pciback module to initramfs by adding it to /etc/initramfs/modules and running update-initramfs -u afterwards.

Please note that pci-passthrough is broken when msi is enabled (default) in Linux kernels < 3.14. Use Linux kernel >= 3.14 in DomU/VM or set pci=nomsi for DomU/VM kernel as workaround. See the following thread for detailed information: http://thread.gmane.org/gmane.comp.emulators.xen.user/81944/focus=191437

Ativando a Console Serial

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

Instalação com um DomU (S.O. Hospedado)

Usando 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

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.

To give a different path where the domU images being saved and enable the superuser password in the initial build, we will edit the /etc/xen-tools/xen-tools.conf file and uncomment this lines:

dir = /home/xen/
passwd = 1

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 start the created VM run the command:

xm create /etc/xen/virtual_machine.cfg

To erase a VM image (even the main directory) run the command:

xen-delete-image VMs_name

Possíveis problemas e 'bugs'

Usando o Instalador do Debian

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

Modernizando(Upgrading)/transição

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

Nota sobre a compatibilidade da versão do kernel

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.

Possíveis problemas e 'bugs'

Versões antigas

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.

Manutenção de Pacote

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.

Erros Comuns

dom0 reincia automaticamente

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

GRUB_CMDLINE_XEN="noreboot"

Erro "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.

'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:

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

Referências