Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati
  • Differenze per "Virtualizzazione/Kvm/CreazioneOspiti"
Differenze tra le versioni 10 e 11
Versione 10 del 24/03/2010 21.41.47
Dimensione: 12598
Autore: FabioMarconi
Commento:
Versione 11 del 24/03/2010 22.07.54
Dimensione: 12614
Autore: FabioMarconi
Commento: Continuazione della traduzione :)
Le cancellazioni sono segnalate in questo modo. Le aggiunte sono segnalate in questo modo.
Linea 113: Linea 113:
{{http://waste.mandragor.org/windows-kvm.png}} [http://waste.mandragor.org/windows-kvm.png]
Linea 176: Linea 176:
=== Example Ubuntu install ===
You can perform the following to install Ubuntu Hardy:{{{
=== Esempio di installazione di Ubuntu ===
Per installare Ubuntu Hardy eseguire il comando:
{{{
Linea 181: Linea 182:
The '--network' option sets up the machine to use the default libvirt network. You can see available libvirt networks with:{{{ L'opzione '--network' imposta la machina all'uso della rete libvirt predefinita. Per un elenco delle reti libvirt usare il comando:
{{{

BR Indice(depth=2 align=right)

Creazione di macchine virtuali

Una volta installato KVM, è possibile procedere alla creazione della VM. Ciò può essere fatto usando:

Ubuntu-vm-builder: un mezzo veloce e potente per creare VMs Ubuntu JEOS

[http://doc.ubuntu.com/ubuntu/serverguide/C/ubuntu-vm-builder.html Ubuntu-vm-builder] è probabilmente il miglior strumento per la creazione di VMs che eseguono Ubuntu JEOS 8.04, dato che l'installazione avviene interamente tramite script (molto veloce).

Questo strumento è pacchettizzato, e si trova nel repository universe:

sudo apt-get install ubuntu-vm-builder

Nota: a partire dalla 8.10 (intrepid): il pacchetto viene chiamato python-vm-builder, il comando vmbuilder ed è possibile trovare un [https://help.ubuntu.com/community/JeOSVMBuilder dettagliato tutorial sul wiki].*******Tradurre

Utilizzo elementare

Questo è un esempio elementare di come utilizzarlo:

sudo ubuntu-vm-builder kvm hardy

Ciò creerà una Ubuntu Hardy, con tutte le opzione impostate in modo predefinito.

Oppure è possibile usare questo URL in uno strumento per script java per generare la lunga serie di parametri disponibili per ubuntu-vm-builder:

Nota: se si preferisce usare Virsh per la gestione della macchina virtuale, come descritto più avanti, bisogna aggiungere questo parametro:

--libvirt qemu:///system

Sfortunatamente lo script java non contiene una opzione per farlo automaticamente.

Nota: utilizzando il parametro --libvirt, il file XML non viene archiviato localmente ma viene iniettato in libvirt. Utilizzare virsh -c qemu:///system oppure virt-manager -c qemu:///system per avviare la macchina o modificarne la configurazione.

Esempio più complesso

In seguito è riportato un esempio più complesso:

ubuntu-vm-builder kvm hardy \
                  --domain newvm \
                  --dest newvm \
                  --arch i386 \
                  --hostname hostnameformyvm \
                  --mem 256 \
                  --user john \
                  --pass doe \
                  --ip 192.168.0.12 \
                  --mask 255.255.255.0 \
                  --net 192.168.0.0 \
                  --bcast 192.168.0.255 \
                  --gw 192.168.0.1 \
                  --dns 192.168.0.1 \
                  --mirror http://archive.localubuntumirror.net/ubuntu \
                  --components main,universe \
                  --addpkg vim openssh-server \
                  --libvirt qemu:///system ;

Ciò creerà una nuova Ubuntu Hardy VM chiamata "newvm", l' hostname sarà impostato a "hostnameformyvm", la rete sarà configurata con un indirizzo IP statico ed il gateway all'indirizzo 192.168.0.1. il parametro --mirror richiederà allo script lo scaricamentodei pacchetti da un mirror locale di ubuntu piuttosto che dal server centrale (ciò diminuirà di molto il tempo necesario alla creazione della VM). L'argomento components abiliterà i repository main e universe predefiniti sulla VM, --addpkg vim installerà vim, ed infine l'ultimo argomento aggiungerà automaticamente la VM appena creata a KVM.

L'aggiunta di 'openssh-server' a --addpkg, consentirà di eseguire una sessione ssh sulla nuova macchina una volta avviata (Assicurarsi che i dispositivi di connessione siano funzionino correttamente).

Nota: Il manuale non fornisce spiegazioni dettagliate sull'utilizzo dell'opzione --exec, usata per lanciare uno script durante il processo dicostruzione della VM. Quindi se si specifica l'opzione --exec è necessario fornire l'indirizzo completo dallo script. In mancanza di ciò il programma d'installazione restituirà un errore relativo all'impossibilità di recuperare lo script.

Avviso bug: Sembra che il pacchetto 'linux-package' non venga trovato durante la costruzione della VM fino a che non viene aggiunta l'opzione 'restricted' nell'argomento component di ubuntu-vm-builder. se non specificato si otterrà un SO non funzionante che si avvierà solamente da grub., Quest linea risolve il problema:

--components 'main,universe,restricted'

Presumendo che ciò sia un bug di ubuntu-vm-builder.

Intallazione su un dispositivo a blocchi grezzo

Ubuntu-vm-builder non consente la creazione di VM su un dispositivo a blocchi grezzo (come ad esempio una partizione indipendente, oppure una condivisione iSCSI). È possibile usare ubuntu-vm-builder per creare l'immagine qcow2 e quindi spostare la VM sul dispositivo a blocchi con qemu-img; se /dev/sdb è il disco sul quale trasferire la macchina virtuale:

sudo qemu-img convert root.qcow2 -O raw /dev/sdb

Editare il file definizione XML per la VM in /etc/libvirt/qemu/, ed impostare il file sorgente per esere:

<source file='/dev/sdb'/>

Ridefinire la VM ed avviarla; così facendo funzionerà da /dev/sdb.

Ubuntu-vm-builder è uno strumento potentissimo - per avere un più dettagliato elenco delle sue capacità, utilizzare ubuntu-vm-builder --help.

Creazione di una VMs in grado di eseguire altri sistemi operativi: virt-install

Virt-install è redicalmente differente nel modo in cui funziona. Invece di creare automagicamente una nuova VM, consente di avviare un immagine iso, e quindi di installare qualsiasi sistema operativo. Per l'elenco dei sistemi operativi supportati, consultare la [http://www.linux-kvm.org/page/Guest_Support_Status pagina web ufficiale di KVM].

Di seguito viene descritto come installare Windows XPA. Durante la fase d'installazione, avverranno alcuni piccoli problemi, ma verrà spiegato come aggirarli.

Esempio di installazione di Windows

[http://waste.mandragor.org/windows-kvm.png]

NB: La seguente descrizione è relativa a windows XP sotto KVM-62 (Predefinito in Hardy durante la stesura di questo testo). In questa versione è impossibile l'esecuzione di windows 2000 server in modalità accelerata, per cui occorre usare KVM-72 adattato per Hardy fornito da Soren nel suo PPA: https://launchpad.net/~soren/+archive.

Copiare la ISO del sistema da installare nella vostra directory funzionante:of the system you want to install to your working directory:

yhamon@paris:~$ ls *.iso
ubuntu-8.04-server-i386.iso  windowsxpsp2.iso

oppure creare una ISO da cd/dvd:

dd if=/dev/dvd of=dvd.iso

Installare virt-install:

sudo apt-get install python-virtinst

Eseguire virt-install. SU Ubuntu Hardy, con KVM-62, l'installazione di windows XP non funziona se accelerata (cioè, usando --accelerate), Quindi bigsogna installare senza questo argomento e sosituire qemu con kvm nel file definizione XML (in /etc/libvirt/qemu) dopo il primo riavvio.

sudo virt-install --connect qemu:///system -n xpsp2 -r 512 -f windows.qcow2 -s 12 -c windowsxpsp2.iso --vnc --noautoconsole --os-type windows --os-variant winxp

Note per 8.10 (Intrepid): per far si che il precedente comando funzioni, aggiungere l'opzione --hvm per avere l'ospite completamente virtualizzato.

Questo avvierà una nuova VM dalla ISO. Connettere alla nuova VM usando virt-viewer:

virt-viewer -c qemu:///system xpsp2

Oppure se KVM è in funzione su di un altro server:

virt-viewer -c qemu+ssh://ip/system xpsp2

È quindi possibile avviare l'installazione. Un'altro problema è che dopo il primo riavvio, nel processo di installazione, il programma di installazione di windows, riferirà che non è più possibile trovare il disco d'installazione. Quindi nel file definizione XML della VM aggiungere le seguenti linee alla lista dei dispositivi:

<domain type='kvm'>
  [...]
  <devices>
    [...]
    <disk type='file' device='cdrom'>
      <source file='//home/yhamon/windowsxpsp2.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
    </disk>
  </devices>
</domain>

Ridefinire la VM in virsh (sudo virsh define /etc/libvirt/qemu/xpsp2.xml) e riavviare la VM.

Un altro problema con la combinazione virt-install - Wndowsin combination with Windows è che il disco immagine creato è corrotto. inizialmente l'installazione sembra funzionare, ma dopo il primo riavvio si fermerà riportando il messaggio 'A read error occured'. Ciò può essere agevolmente risolto creando un nuovo disco immagine (prima dell'installazione):

qemu-img create -f qcow2 disk0.qcow2 12G

Sovrascrive il file qcow2 creato da virt-install con questo nuovo file, riavviare la VM.

Esempio di installazione di Ubuntu

Per installare Ubuntu Hardy eseguire il comando:

sudo virt-install --connect qemu:///system -n hardy -r 512 -f hardy.qcow2 -s 12 -c hardy-server-amd64.iso --vnc --noautoconsole --os-type linux --os-variant ubuntuHardy --accelerate --network=network:default

L'opzione '--network' imposta la machina all'uso della rete libvirt predefinita. Per un elenco delle reti libvirt usare il comando:

virsh net-list --all

Other Operating Systems

Other Operating Systems can be installed using the same method as above. See 'man virt-install' for more information on different options for your virtual machine and supported OS types and OS variants.

Warning: this method fails with Fedora LiveCD installations and possibly others; see the bug here: https://bugs.launchpad.net/ubuntu/+source/kvm/+bug/220463

Cloning a virtual machine

You can clone an existing virtual machine using the virt-clone tool. This duplicates the disk image and sets up the virtual machine domain configuration.

If you wish to clone a virtual machine named srchost to a new machine newhost, ensure that the virtual machine srchost is not running and execute the following command.

$ virt-clone --connect=qemu:///system -o srchost -n newhost -f /path/to/newhost.qcow2

Create a virtual machine from pre-existing image

Assuming:

  • Virt-manager is being used to manage virtual machines.
  • You wish to add a pre-existing image to virt-manager.

Use case:

Using qcow2 with overlays, you can experiment heavily with your virtual machines without having to perform complete reinstalls if you manage to corrupt them. A side effect of this method in comparison to cloning, is that less disk space is used.

Procedure:

1. Create the hard drive image with qcow2 format:

$ qemu-img create -f qcow2 <image name>.qcow2

2. Install the virtual machine using virt-manager:

Instead of allowing virt-manager to create a new drive image, simply direct it to use the image you created in the previous step.

3. Create the overlay:

$ qemu-img create -f qcow2 -b <image name>.qcow2 <image name>.ovl

4. Create virtual image XML descriptor.

Read first:

$ man virt-image
$ man 5 virt-image

Copy the XML file created in step 2 above:

$ cp ~/.libvirt/qemu/<vm name>.xml overlay.xml

Then using your favorite editor, open and edit the copied XML file:

$ <editor> overlay.xml

Create the virtual image XML descriptor based on the virt-image(5) manpage. I simply commented out the original text, and used it as a guide when creating the new descriptor.

5. Create the new virtual machine from the image descriptor:

$ virt-image --vnc overlay.xml

6. Run and test the new virtual machine based on the overlay.

Open the new virtual machine in virt-manager and test to your hearts content. If you 'break' the virtual machine, simply destroy and delete it. Then recreate the overlay image and recreate the overlay virtual machine as described above. You can commit the overlay changes to the base image if desired, see the qemu-img manpage for details.

See also

The system specific adjustment recommended in the FAQ.

apt-cacher-ng for mirroring. You can reduce setup time to 3-4 minutes using ubuntu-vm-builder on a reasonable machine.



CategoryHomepage CategoryInTraduzione