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/GestioneOspiti"
Differenze tra le versioni 1 e 17 (in 16 versioni)
Versione 1 del 22/03/2010 22.15.45
Dimensione: 7604
Autore: FabioMarconi
Commento:
Versione 17 del 04/04/2010 14.40.32
Dimensione: 8247
Autore: FabioMarconi
Commento:
Le cancellazioni sono segnalate in questo modo. Le aggiunte sono segnalate in questo modo.
Linea 1: Linea 1:
#title KVM Guest Management
<<Include(KVM/Header)>>
||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents(3)>>||

= Manage your virtual machines =

== From the shell ==

You can manage your VMs from the shell using [[http://linux.die.net/man/1/virsh|virsh]]. You can get a list of the available commands if you type "help". Type "help command" to get additional infos for a particular command.

=== Define your new VM ===

Before you can manage your new VM with virsh, you must define it:
#format wiki
#language it
[[Indice(depth=2)]]
[[Informazioni(forum="http://forum.ubuntu-it.org/index.php/topic,371617.0.html")]]
[[BR]]
 KVM/Gestione



= Gestione delle macchine virtuali =

== Gestione da terminale ==

Per la gestione delle macchine virtuali da terminale usare [http://help.ubuntu-it.org/9.10/ubuntu/serverguide/it/libvirt.html virsh]. Per ottenere l'elenco dei comandi utilizzabili digitare "help". Per informazioni aggiuntive su uno specifico comando, digitare "help commando".

=== Definizione della nuova MV ===

Prima di poterla gestire con virsh, è necessario definirla:
Linea 27: Linea 32:
Note that to list newvm, you must use 'list --inactive' or 'list --all', since list without any options will only list currently running machines.

=== List your VMs ===

Virsh allows you to list the virtual machines available on the current host:
Nota: per elencare la nuova MV, si deve usare 'list --inactive' oppure 'list --all', dato che list senza opzioni elenca solo le macchine attualmente in esecuzione.

=== Come elencare le MV ===

Virsh consente di elencare le macchine virtuali presenti sul host:
Linea 69: Linea 74:
=== Define, undefine, start, shutdown, destroy VMs ===

The VMs you see with list --all are VMs that have been "defined" from an XML file. Every VM is configured via a XML file in /etc/libvirt/qemu. If you want to remove a VM from the list of VMs, you need to undefine it:
=== Definire, indefinire, avviare, spegnere, distruggere MV ===

Le MV visualizzate con list --all sono VMs che sono state "definite" da un file XML. Ogni MV è configurata tramite un file XML in /etc/libvirt/qemu. Per rimuovere una MV dall'elenco delle MV occorre indefinirla:
Linea 84: Linea 89:
To be able to undefine a virtual machine, it needs to be shutdown first: Per indefinire una macchina virtuale bisogna innanzitutto spegnerla:
Linea 91: Linea 96:
This command asks for a nice shutdown (like running shutdown in command line) - but you can also use "destroy", the more brutal way of shutting down a VM, equivalent of taking the power cable off: Questo comando avvia lo spegnimento dolce della MV (simile all'esecuzione dello shutdown da linea di comando) - ma è anche possibile usare "destroy", il modo più brutale di spegnere una MV, equivalente ad una interruzione dell'alimentazione sul sistema:
Linea 98: Linea 103:
If you have made a change to the XML configuration file, you need to tell KVM to reload it before restarting the VM: se vengono eseguiti cambiamente al file di confiurazione XML, è necessario che KVM lo ricarichi prima di riavviare la MV:
Linea 105: Linea 110:
Then, to restart the VM: Quindi per riavviare la MV:
Linea 112: Linea 117:
=== Suspend and resume a Virtual Machine ===

Virsh allows you to easily suspend and resume a virtual machine.
=== Sospensione e ripristino di una macchina virtuale ===

Virsh consente di sospendere e riavviare facilmente una macchina virtuale.
Linea 124: Linea 129:
= Editing the attributes of a Virtual Machine =

libvirt stores it's configuration as xml in '/etc/libvirt/qemu'. The xml is easy to understand, and is similar to VMware *.vmx files. While it is possible to edit these files in place and restart libvirt-bin for the changes to take affect, the recommended method for modifying the attributes of a virtual machine is via virsh (or virt-manager, if it supports changing the hardware you want to change). The concept is simple:

 1. export (aka 'dump') the xml of the virtual machine you want to edit
 1. edit the xml
 1. import (aka 'define') the xml

For example, to edit the machine named 'foo' (you can get a list of your machines with 'virsh list --all'), do:{{{
= Modifica degli attributi di una macchina virtuale =

libvirt memorizza la sua configurazione come .xml in '/etc/libvirt/qemu'. Il file .xml è facilmente comprensibile, ed è simile ai file *.vmx di VMware. Quindi è possibile editare questi file sul posto e riavviare libvirt perchè i cambiamenti abbiano effetto. Il metodo raccomandato per la modifica degli attributi di una macchina virtuale è tramite virsh (oppure virt-manager, semprechè supporti i cambiamenti hardware che volete effettuare). Il concetto è semplice:

 1. Esportare il file xml della MV da editare (aka 'dump')
 1. editare il file xml
 1. Importare il file xml (aka 'define')

Per esempio, per editare la macchina chiamata 'foo' (per avere l'elenco delle macchine usare 'virsh list --all'), eseguire:{{{
Linea 134: Linea 139:
(edit /tmp/foo.xml as needed) (editare /tmp/foo.xml come necessario)
Linea 138: Linea 143:
== Adding CPUs ==
KVM allows you to create SMP guests. To allocate two CPUs to a VM, dump the xml as above, then edit your xml to have:{{{
== Aggiunta di CPU ==
KVM permette di creare ospiti SMP. Per allocare due CPU in una MV, fare il dump del file xml come sopra, quindi editarlo per avere:{{{
Linea 147: Linea 152:
Now define the VM as above.

== Adding Memory ==
To change the memory allocation in a VM, dump the xml as above, then edit your xml to have:{{{
Definire la MV come sopra.

== Aggiunta di memoria ==
Per cambiare l'alolocazione di memoria in una MV, fare il dump del file xml come sopra, quindi editarlo per avere:{{{
Linea 159: Linea 164:
Now define the VM as above. Keep in mind that the memory allocation is in kilobytes, so to allocate 512MB of memory, use 512 * 1024, or 524288.

== Changing the Network Card Model ==
kvm and qemu currently default to using the rtl8139 NIC. Supported NICs in Ubuntu 8.04 LTS are i82551, i82557b, i82559er, ne2k_pci, pcnet, rtl8139, e1000, and virtio. To use an alternate NIC, dump the xml as above, then edit your xml to have:{{{
Definire la MV come sopra. tenere a mente che l'allocazione di memoria è in kilobytes, quindi per allocare 512MB di memoria, usare 512 * 1024, oppure 524288.

== Cambiare il modello di scheda di rete ==
kvm e qemu attualmente ed in maniera prestabilita usano il NIC rtl8139. I NIC supportati in Ubuntu 8.04 LTS sono i82551, i82557b, i82559er, ne2k_pci, pcnet, rtl8139, e1000, e virtio. Per usare un NIC alternativo, fare il dump del file xml come sopra, quindi editarlo per avere:{{{
Linea 173: Linea 178:
Now define the VM as above.

== Adding USB Device Pass-through ==
=== Limitations ===
 * USB protocol 1.1 only
 * Device must be plugged in before KVM starts
 * Apparmor modifications needed

=== Apparmor Modification ===
In order for a software program to access the usb device correctly the apparmor must be changed. Edit '''/etc/apparmor.d/abstractions/libvirt-qemu''' and uncomment some lines.:
Ridefinire la MV come sopra.

== Aggiunta di dispositivi USB passanti ==
=== Limitazioni ===
 * Solamente il protocollo USB 1.1
 * Il dispositivo deve essere collegato prima dell'avvio di KVM
 * È necessari modificare Apparmor

=== Modifica di Apparmor ===
Per consentire ad un programma software di accedere ad un dispositivo usb correttamente è necessario modificare Apparmor. Per fare ciò editare '''/etc/apparmor.d/abstractions/libvirt-qemu''' e decommentare alcune linee:
Linea 192: Linea 197:
After making the changes apparmor must be restarted.: Dopo le variazioni apparmor deve essere riavviato:
Linea 197: Linea 202:
=== Adding USB devices ===
First find the usb Vendor ID and Product ID.:
=== Aggiunta di dispositivi USB ===
Innanzitutto cercare, relativamente all'USB il codice del costruttore (Vendor ID) e del prodotto (Product ID):
Linea 210: Linea 215:
In the event that the '''Broadcom Corp. Bluetooth Controller''' wans to be selected the vendor and product ids are '''0a5c''' and '''2110''' respectively. These can be entered into the xml profile. This can be done through virsh through the '''edit <domain>''' command.: Se per esempio bisogna aggiungere '''Broadcom Corp. Bluetooth Controller''' i codici identificativi (ID) del costruttore e del prodotto sono rispettivamente '''0a5c''' e '''2110'''. Questi valori vanno inseriti nel profilo xml. Ciò può essere fatto tramite virsh con il comando '''edit <domain>''':
Linea 227: Linea 232:
== Get new IDs ==

To get a new mac address to paste into your xml file, use this command:
== Ottenere nuovi ID ==

Per avere nuovi indirizzi macchina da copiare nel file xml, usare questo comando:
Linea 233: Linea 238:
To get a new uuid for your xml file, use: uuidgen

<<Include(KVM/Header)>>
Per ottenere un nuovo uuid per il file xml, usare: uuidgen

= Ulteriori risorse =
 *[https://help.ubuntu.com/community/KVM/Managing Documento originale]
##traduzione pagina del 20.02.2010
Linea 237: Linea 245:
----
CategoryHomepage
CategoryHomepage CategoryInTraduzione

Indice(depth=2) Informazioni(forum="http://forum.ubuntu-it.org/index.php/topic,371617.0.html") BR

  • KVM/Gestione

Gestione delle macchine virtuali

Gestione da terminale

Per la gestione delle macchine virtuali da terminale usare [http://help.ubuntu-it.org/9.10/ubuntu/serverguide/it/libvirt.html virsh]. Per ottenere l'elenco dei comandi utilizzabili digitare "help". Per informazioni aggiuntive su uno specifico comando, digitare "help commando".

Definizione della nuova MV

Prima di poterla gestire con virsh, è necessario definirla:

$ virsh --connect qemu:///system
Connecting to uri: qemu:///system
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # define /etc/libvirt/qemu/newvm.xml
Domain newvm defined from /etc/libvirt/qemu/newvm.xml

Nota: per elencare la nuova MV, si deve usare 'list --inactive' oppure 'list --all', dato che list senza opzioni elenca solo le macchine attualmente in esecuzione.

Come elencare le MV

Virsh consente di elencare le macchine virtuali presenti sul host:

yhamon@paris:/etc/libvirt/qemu$ virsh --connect qemu:///system
Connecting to uri: qemu:///system
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # help list
  NAME
    list - list domains

  SYNOPSIS
    list [--inactive | --all]

  DESCRIPTION
    Returns list of domains.

  OPTIONS
    --inactive       list inactive domains
    --all            list inactive & active domains

virsh # list
 Id Name                 State
----------------------------------
 15 mirror               running
 16 vm2                  running

virsh # list --all
 Id Name                 State
----------------------------------
 15 mirror               running
 16 vm2                  running
  - test5                shut off

Definire, indefinire, avviare, spegnere, distruggere MV

Le MV visualizzate con list --all sono VMs che sono state "definite" da un file XML. Ogni MV è configurata tramite un file XML in /etc/libvirt/qemu. Per rimuovere una MV dall'elenco delle MV occorre indefinirla:

virsh # undefine test5   # WARNING: undefine will delete your XML file!
Domain test5 has been undefined

virsh # list --all
 Id Name                 State
----------------------------------
 15 mirror               running
 16 vm2                  running

Per indefinire una macchina virtuale bisogna innanzitutto spegnerla:

virsh # shutdown mirror
Domain mirror is being shutdown

Questo comando avvia lo spegnimento dolce della MV (simile all'esecuzione dello shutdown da linea di comando) - ma è anche possibile usare "destroy", il modo più brutale di spegnere una MV, equivalente ad una interruzione dell'alimentazione sul sistema:

virsh # destroy mirror
Domain mirror destroyed

se vengono eseguiti cambiamente al file di confiurazione XML, è necessario che KVM lo ricarichi prima di riavviare la MV:

virsh # define /etc/libvirt/qemu/mirror.xml
Domain mirror defined from /etc/libvirt/qemu/mirror.xml

Quindi per riavviare la MV:

virsh # start mirror
Domain mirror started

Sospensione e ripristino di una macchina virtuale

Virsh consente di sospendere e riavviare facilmente una macchina virtuale.

virsh # suspend mirror
Domain mirror suspended

virsh # resume mirror
Domain mirror resumed

Modifica degli attributi di una macchina virtuale

libvirt memorizza la sua configurazione come .xml in '/etc/libvirt/qemu'. Il file .xml è facilmente comprensibile, ed è simile ai file *.vmx di VMware. Quindi è possibile editare questi file sul posto e riavviare libvirt perchè i cambiamenti abbiano effetto. Il metodo raccomandato per la modifica degli attributi di una macchina virtuale è tramite virsh (oppure virt-manager, semprechè supporti i cambiamenti hardware che volete effettuare). Il concetto è semplice:

  1. Esportare il file xml della MV da editare (aka 'dump')
  2. editare il file xml
  3. Importare il file xml (aka 'define')

Per esempio, per editare la macchina chiamata 'foo' (per avere l'elenco delle macchine usare 'virsh list --all'), eseguire:

$ virsh dumpxml foo > /tmp/foo.xml
(editare /tmp/foo.xml come necessario)
$ virsh define /tmp/foo.xml

Aggiunta di CPU

KVM permette di creare ospiti SMP. Per allocare due CPU in una MV, fare il dump del file xml come sopra, quindi editarlo per avere:

<domain type='kvm'>
  ...
  <vcpu>2</vcpu>
  ...
</domain>

Definire la MV come sopra.

Aggiunta di memoria

Per cambiare l'alolocazione di memoria in una MV, fare il dump del file xml come sopra, quindi editarlo per avere:

<domain type='kvm'>
  ...
  <memory>262144</memory>
  <currentMemory>262144</currentMemory>
  ...
</domain>

Definire la MV come sopra. tenere a mente che l'allocazione di memoria è in kilobytes, quindi per allocare 512MB di memoria, usare 512 * 1024, oppure 524288.

Cambiare il modello di scheda di rete

kvm e qemu attualmente ed in maniera prestabilita usano il NIC rtl8139. I NIC supportati in Ubuntu 8.04 LTS sono i82551, i82557b, i82559er, ne2k_pci, pcnet, rtl8139, e1000, e virtio. Per usare un NIC alternativo, fare il dump del file xml come sopra, quindi editarlo per avere:

<domain type='kvm'>
  ...
    <interface type='network'>
      ...
      <model type='e1000'/>
    </interface>
  ...
</domain>

Ridefinire la MV come sopra.

Aggiunta di dispositivi USB passanti

Limitazioni

  • Solamente il protocollo USB 1.1
  • Il dispositivo deve essere collegato prima dell'avvio di KVM
  • È necessari modificare Apparmor

Modifica di Apparmor

Per consentire ad un programma software di accedere ad un dispositivo usb correttamente è necessario modificare Apparmor. Per fare ciò editare /etc/apparmor.d/abstractions/libvirt-qemu e decommentare alcune linee:

# WARNING: uncommenting these gives the guest direct access to host hardware.
# This is required for USB pass through but is a security risk. You have been
# warned.
/sys/bus/usb/devices/ r,
/sys/devices/*/*/usb[0-9]*/** r,
/dev/bus/usb/*/[0-9]* rw,

Dopo le variazioni apparmor deve essere riavviato:

$ sudo /etc/init.d/apparmor restart

Aggiunta di dispositivi USB

Innanzitutto cercare, relativamente all'USB il codice del costruttore (Vendor ID) e del prodotto (Product ID):

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 012: ID 0a5c:2110 Broadcom Corp. Bluetooth Controller
Bus 005 Device 003: ID 0483:2016 SGS Thomson Microelectronics Fingerprint Reader
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Se per esempio bisogna aggiungere Broadcom Corp. Bluetooth Controller i codici identificativi (ID) del costruttore e del prodotto sono rispettivamente 0a5c e 2110. Questi valori vanno inseriti nel profilo xml. Ciò può essere fatto tramite virsh con il comando edit <domain>:

<domain type='kvm'>
  <name>windowsxp</name>
  <devices>
    <hostdev mode='subsystem' type='usb'>
      <source>
        <vendor id='0x0a5c'/>
        <product id='0x2110'/>
      </source>
    </hostdev>
  </devices>
</domain>

Ottenere nuovi ID

Per avere nuovi indirizzi macchina da copiare nel file xml, usare questo comando:

MACADDR="52:54:$(dd if=/dev/urandom count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4/')"; echo $MACADDR

Per ottenere un nuovo uuid per il file xml, usare: uuidgen

Ulteriori risorse


CategoryHomepage CategoryInTraduzione