#
mv /etc/grub.d/20_linux_xen /etc/grub.d/09_linux_xen
#
update-grub
xen-create-image
, che automatizza gran parte del compito. L'unico parametro obbligatorio è --hostname
, che dà un nome al domU; altre opzioni sono importanti, ma possono essere memorizzate nel file di configurazione /etc/xen-tools/xen-tools.conf
e la loro mancanza dalla riga di comando non genera un errore. Perciò è importante controllare i contenuti di questo file prima di creare delle immagini oppure, in alternativa, usare parametri aggiuntivi nell'esecuzione di xen-create-image
. I parametri importanti includono:
--memory
, per specificare la quantità di RAM dedicata al sistema appena creato;
--size
e --swap
, per definire la dimensione dei «dischi virtuali» disponibili al domU;
--debootstrap
, to cause the new system to be installed with debootstrap
; in that case, the --dist
option will also most often be used (with a distribution name such as wheezy).
--dhcp
dichiara che la configurazione di rete del domU deve essere ottenuta tramite DHCP mentre --ip
permette di definire un indirizzo IP statico.
--dir
, è di creare un file sul dom0 per ogni dispositivo da rendere disponibile al domU. Per i sistemi che usano LVM, l'alternativa è usare l'opzione --lvm
, seguita dal nome di un gruppo di volume; quindi xen-create-image
creerà un nuovo volume logico dentro quel gruppo e questo volume logico sarà reso disponibile al domU come disco fisso.
#
xen-create-image --hostname testxen --dhcp --dir /srv/testxen --size=2G --dist=wheezy --role=udev
[...] General Information -------------------- Hostname : testxen Distribution : wheezy Mirror : http://ftp.debian.org/debian/ Partitions : swap 128Mb (swap) / 2G (ext3) Image type : sparse Memory size : 128Mb Kernel path : /boot/vmlinuz-3.2.0-4-686-pae Initrd path : /boot/initrd.img-3.2.0-4-686-pae [...] Logfile produced at: /var/log/xen-tools/testxen.log Installation Summary --------------------- Hostname : testxen Distribution : wheezy IP-Address(es) : dynamic RSA Fingerprint : 0a:6e:71:98:95:46:64:ec:80:37:63:18:73:04:dd:2b Root Password : 48su67EW
vif*
, veth*
, peth*
e xenbr0
. L'ipervisore Xen le dispone in qualunque configurazione sia stata definita, sotto il controllo degli strumenti nello spazio utente. Poiché le modalità NAT e routing si adattano solo a casi particolari, qui si descriverà solo il modello di bridge.
xend
daemon is configured to integrate virtual network interfaces into any pre-existing network bridge (with xenbr0
taking precedence if several such bridges exist). We must therefore set up a bridge in /etc/network/interfaces
(which requires installing the bridge-utils package, which is why the xen-utils-4.1 package recommends it) to replace the existing eth0 entry:
auto xenbr0 iface xenbr0 inet dhcp bridge_ports eth0 bridge_maxwait 0
xm
. Questo comando permette diverse manipolazioni sui domini, fra cui elencarli, avviarli e fermarli.
#
xm list
Name ID Mem VCPUs State Time(s) Domain-0 0 463 1 r----- 9.8 #
xm create testxen.cfg
Using config file "/etc/xen/testxen.cfg". Started domain testxen (id=1) #
xm list
Name ID Mem VCPUs State Time(s) Domain-0 0 366 1 r----- 11.4 testxen 1 128 1 -b---- 1.1
testxen
usa memoria fisica presa dalla RAM che altrimenti sarebbe disponibile per il dom0, non memoria simulata. Pertanto bisogna fare attenzione, quando si assembla un server che deve ospitare istanze di Xen, a fornire RAM fisica secondo le necessità.
hvc0
, con il comando xm console
:
#
xm console testxen
[...] Debian GNU/Linux 7.0 testxen hvc0 testxen login:
xm pause
e xm unpause
. Notare che, sebbene un domU in pausa non usi affatto il processore, la memoria ad esso allocata è ancora in uso. Può essere interessante considerare i comandi xm save
e xm restore
: salvare un domU libera le risorse precedentemente usate da questo domU, compresa la RAM. Al ripristino (o all'uscita dalla pausa, se è per quello) un domU non si accorge di alcunché al di là del passare del tempo. Se un domU era in esecuzione quando il dom0 viene spento, gli script nel pacchetto salvano automaticamente il domU e lo ripristinano all'avvio successivo. Questo ovviamente comporterà i consueti inconvenienti che si riscontrano quando si iberna un computer portatile, per esempio; in particolare, se il domU viene sospeso per troppo tempo, le connessioni di rete possono scadere. Notare inoltre che a tutt'oggi Xen è incompatibile con gran parte della gestione energetica ACPI, il che impedisce di sospendere il sistema host (dom0).
shutdown
) o dal dom0, con xm shutdown
o xm reboot
.
init
process, and the resulting set looks very much like a virtual machine. The official name for such a setup is a “container” (hence the LXC moniker: LinuX Containers), but a rather important difference with “real” virtual machines such as provided by Xen or KVM is that there's no second kernel; the container uses the very same kernel as the host system. This has both pros and cons: advantages include excellent performance due to the total lack of overhead, and the fact that the kernel has a global vision of all the processes running on the system, so the scheduling can be more efficient than it would be if two independent kernels were to schedule different task sets. Chief among the inconveniences is the impossibility to run a different kernel in a container (whether a different Linux version or a different operating system altogether).
/sys/fs/cgroup
. Pertanto /etc/fstab
deve contenere la seguente voce:
# /etc/fstab: static file system information. [...] cgroup /sys/fs/cgroup cgroup defaults 0 0
/sys/fs/cgroup
sarà allora montato automaticamente all'avvio; se non si prevede un riavvio immediato, il file system deve essere montato manualmente con mount /sys/fs/cgroup
.
/etc/network/interfaces
, spostare la configurazione dell'interfaccia fisica (per esempio eth0
) su un'interfaccia bridge (di solito br0
) e configurare il link fra essi. Per esempio, se il file di configurazione dell'interfaccia di rete contiene voci come le seguenti:
auto eth0 iface eth0 inet dhcp
#auto eth0 #iface eth0 inet dhcp auto br0 iface br0 inet dhcp bridge-ports eth0
eth0
fisica oltre alle interfacce definite per i contenitori.
/etc/network/interfaces
allora diventa:
# Interface eth0 is unchanged auto eth0 iface eth0 inet dhcp # Virtual interface auto tap0 iface tap0 inet manual vde2-switch -t tap0 # Bridge for containers auto br0 iface br0 inet static bridge-ports tap0 address 10.0.0.1 netmask 255.255.255.0
br0
.
root@mirwiz:~#
lxc-create -n testlxc -t debian
Note: Usually the template option is called with a configuration file option too, mostly to configure the network. For more information look at lxc.conf (5) debootstrap is /usr/sbin/debootstrap Checking cache download in /var/cache/lxc/debian/rootfs-wheezy-amd64 ... Downloading debian minimal ... I: Retrieving Release I: Retrieving Release.gpg [...] Root password is 'root', please change ! 'debian' template installed 'testlxc' created root@mirwiz:~#
/var/cache/lxc
e poi spostato nella sua directory di destinazione. Ciò permette di creare contenitori identici molto più rapidamente, visto che a questo punto basta copiarli.
--arch
option to specify the architecture of the system to be installed and a --release
option if you want to install something else than the current stable release of Debian. You can also set the MIRROR
environment variable to point to a local Debian mirror.
/var/lib/lxc/testlxc/config
) and add a few lxc.network.*
entries:
lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.hwaddr = 4a:49:43:49:79:20
br0
sull'host; e che il suo indirizzo MAC sarà quello specificato. Se l'ultima voce fosse assente o disabilitata, verrà generato un indirizzo MAC casuale.
lxc.utsname = testlxc
root@mirwiz:~#
lxc-start --daemon --name=testlxc
root@mirwiz:~#
lxc-console -n testlxc
Debian GNU/Linux 7 testlxc tty1 testlxc login:
root
Password: Linux testlxc 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@testlxc:~#
ps auxwf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 10644 824 ? Ss 09:38 0:00 init [3] root 1232 0.0 0.2 9956 2392 ? Ss 09:39 0:00 dhclient -v -pf /run/dhclient.eth0.pid root 1379 0.0 0.1 49848 1208 ? Ss 09:39 0:00 /usr/sbin/sshd root 1409 0.0 0.0 14572 892 console Ss+ 09:39 0:00 /sbin/getty 38400 console root 1410 0.0 0.1 52368 1688 tty1 Ss 09:39 0:00 /bin/login -- root 1414 0.0 0.1 17876 1848 tty1 S 09:42 0:00 \_ -bash root 1418 0.0 0.1 15300 1096 tty1 R+ 09:42 0:00 \_ ps auxf root 1411 0.0 0.0 14572 892 tty2 Ss+ 09:39 0:00 /sbin/getty 38400 tty2 linux root 1412 0.0 0.0 14572 888 tty3 Ss+ 09:39 0:00 /sbin/getty 38400 tty3 linux root 1413 0.0 0.0 14572 884 tty4 Ss+ 09:39 0:00 /sbin/getty 38400 tty4 linux root@testlxc:~#
/var/lib/lxc/testlxc/rootfs
). We can exit the console with Control+a q.
--daemon
option of lxc-start
. We can interrupt the container with a command such as lxc-kill --name=testlxc
.
/etc/default/lxc
, is relatively straightforward; note that the container configuration files need to be stored in /etc/lxc/auto/
; many users may prefer symbolic links, such as can be created with ln -s /var/lib/lxc/testlxc/config /etc/lxc/auto/testlxc.config
.
qemu-*
commands: it is still about KVM.
/proc/cpuinfo
.
virtual-manager
is a graphical interface that uses libvirt to create and manage virtual machines.
apt-get install qemu-kvm libvirt-bin virtinst virt-manager virt-viewer
. libvirt-bin fornisce il demone libvirtd
, che permette di gestire (potenzialmente da remoto) le macchine virtuali che girano sull'host e fa partire le VM richieste all'avvio dell'host. Inoltre, questo pacchetto fornisce lo strumento a riga di comando virsh
, che permette di controllare le macchine gestite da libvirtd
.
virt-install
, che permette di creare macchine virtuali da riga di comando. Infine, virt-viewer permette di accedere alla console grafica di una VM.
eth0
e un bridge br0
e che la prima sia connessa al secondo.
/var/lib/libvirt/images/
).
root@mirwiz:~#
mkdir /srv/kvm
root@mirwiz:~#
virsh pool-create-as srv-kvm dir --target /srv/kvm
Pool srv-kvm created root@mirwiz:~#
virt-install
. Questo comando registra la macchina virtuale e i suoi parametri in libvirtd, quindi la avvia cosicché la sua installazione può procedere.
#
virt-install --connect qemu:///system
--virt-type kvm
--name testkvm
--ram 1024
--disk /srv/kvm/testkvm.qcow,format=qcow2,size=10
--cdrom /srv/isos/debian-7.2.0-amd64-netinst.iso
--network bridge=br0
--vnc
--os-type linux
--os-variant debianwheezy
Starting install... Allocating 'testkvm.qcow' | 10 GB 00:00 Creating domain... | 0 B 00:00 Cannot open display: Run 'virt-viewer --help' to see a full list of available command line options. Domain installation still in progress. You can reconnect to the console to complete the installation process.
L'opzione --connect specifica l'«ipervisore» da usare. La sua forma è quella di un URL contenente un sistema di virtualizzazione (xen:// , qemu:// , lxc:// , openvz:// , vbox:// e così via) e la macchina che deve ospitare la VM (questo può essere lasciato vuoto nel caso dell'host locale). Inoltre e nel caso di QEMU/KVM ciascun utente può gestire macchine virtuali che funzionano con permessi ristretti e il percorso nell'URL permette di differenziare le macchine «di sistema» (/system ) dalle altre (/session ).
| |
Poiché KVM è gestito allo stesso modo di QEMU, --virt-type kvm permette di specificare l'uso di KVM anche se l'URL sembra quello di QEMU.
| |
L'opzione --name definisce un nome (unico) per la macchina virtuale.
| |
L'opzione --ram permette di specificare la quantità di RAM (in MB) da allocare per la macchina virtuale.
| |
--disk specifica la posizione del file immagine che deve rappresentare il disco fisso della macchina virtuale; quel file è creato, se non presente, con una dimensione (in GB) specificata dal parametro size . Il parametro format permette di scegliere fra vari modi di memorizzare il file immagine. Il formato predefinito (raw ) è un singolo file che combacia esattamente con la dimensione e i contenuti del disco. Qui la scelta è di prendere un formato più avanzato, specifico di QEMU e che permette di iniziare con un file piccolo che cresce solo quando la macchina virtuale comincia effettivamente ad usare spazio.
| |
L'opzione --cdrom è usata per indicare dove trovare il disco ottico da usare per l'installazione. Il percorso può essere un percorso locale di un file ISO, un URL dove reperire il file o il device di un lettore CD-ROM fisico (es. /dev/cdrom ).
| |
--network specifica come la scheda di rete virtuale si integra nella configurazione di rete dell'host. Il comportamento predefinito (che in questo esempio è esplicitamente forzato) è di integrarla in un qualunque bridge di rete preesistente. Se non esiste un tale bridge, la macchina virtuale raggiungerà la rete fisica solo tramite NAT, quindi riceve un indirizzo in un intervallo di una sottorete privata (192.168.122.0/24).
| |
--vnc states that the graphical console should be made available using VNC. The default behavior for the associated VNC server is to only listen on the local interface; if the VNC client is to be run on a different host, establishing the connection will require setting up an SSH tunnel (see Sezione 9.2.1.3, «Creazione di tunnel cifrati con il port forwarding»). Alternatively, the --vnclisten=0.0.0.0 can be used so that the VNC server is accessible from all interfaces; note that if you do that, you really should design your firewall accordingly.
| |
Le opzioni --os-type e --os-variant permettono di ottimizzare alcuni parametri della macchina virtuale, basandosi su alcune delle funzionalità note del sistema operativo lì menzionato.
|
virt-viewer
da qualunque ambiente grafico per aprire la console grafica (notare che la password di root dell'host remoto viene chiesta due volte perché l'operazione richiede 2 connessioni SSH):
$
virt-viewer --connect qemu+ssh://root@server/system testkvm
root@server's password: root@server's password:
libvirtd
la lista delle macchine virtuali che gestisce:
#
virsh -c qemu:///system list --all Id Name State ---------------------------------- - testkvm shut off
#
virsh -c qemu:///system start testkvm
Domain testkvm started
vncviewer
):
#
virsh -c qemu:///system vncdisplay testkvm
:0
virsh
includono:
reboot
per riavviare una macchina virtuale;
shutdown
per provocare uno spegnimento pulito;
destroy
per fermarla brutalmente;
suspend
per metterla in pausa;
resume
per farla uscire dalla pausa;
autostart
per abilitare (o disabilitare, con l'opzione --disable
) l'avvio automatico della macchina virtuale all'avvio dell'host;
undefine
per rimuovere ogni traccia della macchina virtuale da libvirtd
.
debootstrap
, as described above. But if the virtual machine is to be installed with an RPM-based system (such as Fedora, CentOS or Scientific Linux), the setup will need to be done using the yum
utility (available in the package of the same name).
yum.conf
file containing the necessary parameters, including the path to the source RPM repositories, the path to the plugin configuration, and the destination folder. For this example, we will assume that the environment will be stored in /var/tmp/yum-bootstrap
. The file /var/tmp/yum-bootstrap/yum.conf
file should look like this:
[main] reposdir=/var/tmp/yum-bootstrap/repos.d pluginconfpath=/var/tmp/yum-bootstrap/pluginconf.d cachedir=/var/cache/yum installroot=/path/to/destination/domU/install exclude=$exclude keepcache=1 #debuglevel=4 #errorlevel=4 pkgpolicy=newest distroverpkg=centos-release tolerant=1 exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 metadata_expire=1800
/var/tmp/yum-bootstrap/repos.d
directory should contain the descriptions of the RPM source repositories, just as in /etc/yum.repos.d
in an already installed RPM-based system. Here is an example for a CentOS 6 installation:
[base] name=CentOS-6 - Base #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 [updates] name=CentOS-6 - Updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 [extras] name=CentOS-6 - Extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 [centosplus] name=CentOS-6 - Plus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
pluginconf.d/installonlyn.conf
file should contain the following:
[main] enabled=1 tokeep=5
rpm
databases are correctly initialized, with a command such as rpm --rebuilddb
. An installation of CentOS 6 is then a matter of the following:
yum -c /var/tmp/yum-bootstrap/yum.conf -y install coreutils basesystem centos-release yum-basearchonly initscripts