KVM
Version vom 14. Februar 2013, 15:34 Uhr von 192.168.242.1 (Diskussion) (→Virtuelle MACAdresse vergeben)
Installation
Vorbereitung
Testen ob VT Unterstützung der CPU vorhanden ist
egrep -c '(vmx|svm)' /proc/cpuinfo
0 bedeutet keine Unterstützung 1 (oder mehr) Unterstützung vorhanden
Basis Pakete
apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils virtinst apt-get install ssh-askpass
Verifizieren der Installation
virsh -c qemu:///system list Id Name Status ----------------------------------
Installation des Virtmanagers(GUI)
apt-get install virt-manager
Installation des Linux capabilities tools
apt-get install libcap2-bin
Vergeben der CAP_NET_ADMIN Fähigkeit
setcap cap_net_admin=ei /usr/bin/qemu-system-x86_64 setcap cap_net_admin=ei /usr/bin/qemu-system-i386
Erlauben der Beerchtigung für den Adminuser
echo cap_net_admin xinux >> /etc/security/capability.conf
Netzwerk mit Bridgefunktion
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto br0 iface br0 inet static address 192.168.240.101 netmask 255.255.240.0 gateway 192.168.240.100 bridge_ports eth0 bridge_stp off bridge_fd 1 bridge_maxwait 12
Damit libvirt-bin automatisch start muss man in der Datei /etc/default/libvirt-bin die Option start_libvirtd auf "yes" setzen.
vi /etc/default/libvirt-bin start_libvirtd="yes"
Domain-Installation
virt-install --connect qemu:///system --name orion --ram 1024 --disk path=/dev/data/orion \ --cdrom /isos/ubuntu-10.04-server-amd64.iso --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0
name | Name der Domain |
disk | Diese Images werden in die Domain eingebunden. Es können mehrere Disks eingebunden werden, sowie weitere Optionen getrennt mit Leerzeichen gemacht werden. |
ram | Zu Verfügung stehender Arbeitspeicher der Domain |
os-type | linux, windows, solaris etc. |
os-variant | ubuntukarmic, winxp etc. |
hvm | Gebraucht full virtualization. |
accelerate | Benutze kvm oder KQEMU, wenn vorhanden. |
import | Die Installation ist bereits im Disk-Image enthalten. |
vnc | Aktiviert VNC-Display und öffnete einen beliebigen Port >5000, falls nicht --vncport angegeben ist. |
vncport | Setzt den Port für VNC fest. |
Handling
This command outputs the guest's XML configuration file to standard out (stdout). You can save the data by piping the output to a file. An example of piping the output to a file called guest.xml:
virsh dumpxml GuestID > guest.xml
Domain-Administration
Kommando | Bedeutung |
help | Hilfe ausgeben |
attach-device | Gerät aus einer XML-Datei anhängen |
attach-disk | Plattengerät anhängen |
attach-interface | Netzwerkschnittstelle verbinden |
autostart | Eine Domain automatisch starten |
capabilities | Fähigkeiten |
cd | change the current directory |
connect | (Wieder)verbinden mit Hypervisor |
console | Verbindung mit der Gast-Konsole |
cpu-baseline | compute baseline CPU |
cpu-compare | compare host CPU with a CPU described by an XML file |
create | Eine Domain aus einer XML-Datei erstellen |
start | Eine (zuvor definierte) inaktive Domain starten |
destroy | Domain löschen |
detach-device | Gerät von einer XML-Datei lösen |
detach-disk | Plattengerät abtrennen |
detach-interface | Netzwerkschnittstelle abhängen |
define | Definiere (aber starte keine) Domain aus einer XML-Datei |
domid | Einen Domain-Namen oder -UUID in Domain-ID konvertieren |
domuuid | Einen Domain-Namen oder -ID in Domain-UUID konvertieren |
dominfo | Domain-Informationen |
domjobinfo | domain job information |
domjobabort | abort active domain job |
domname | Eine Domain-ID oder UUID in Domain-Namen konvertieren |
domstate | Domain-Status |
domblkstat | Geräteblockstatistiken für eine Domain abrufen |
domifstat | Statistiken der Netzwerkschnittstelle für eine Domain abrufen |
dommemstat | get memory statistics for a domain |
domblkinfo | domain block device size information |
domxml-from-native | Convert native config to domain XML |
domxml-to-native | Convert domain XML to native config |
dumpxml | Domain-Informationen in XML |
edit | edit XML configuration for a domain |
find-storage-pool-sources | discover potential storage pool sources |
find-storage-pool-sources-as | find potential storage pool sources |
freecell | NUMA freier Speicher |
hostname | Hypervisor-Hostname ausgeben |
list | Domains auflisten |
migrate | Domain auf anderen Host migrieren |
migrate-setmaxdowntime | set maximum tolerable downtime |
net-autostart | Ein Netzwerk automatisch starten |
net-create | Netzwerk aus einer XML-Datei erstellen |
net-define | Definiere (aber starte kein) Netzwerk aus einer XML-Datei |
net-destroy | Netzwerk löschen |
net-dumpxml | Netzwerk-Informationen in XML |
net-edit | edit XML configuration for a network |
net-list | Netzwerke auflisten |
net-name | Eine Netzwerk-UUID in einen Netzwerk-Namen konvertieren |
net-start | Ein (zuvor definiertes) inaktives Netzwerk starten |
net-undefine | Ein inaktives Netzwerk undefinieren |
net-uuid | Einen Netzwerk-Namen in eine Netzwerk-UUID konvertieren |
iface-list | list physical host interfaces |
iface-name | convert an interface MAC address to interface name |
iface-mac | convert an interface name to interface MAC address |
iface-dumpxml | interface information in XML |
iface-define | define (but don't start) a physical host interface from an XML file |
iface-undefine | undefine a physical host interface (remove it from configuration) |
iface-edit | edit XML configuration for a physical host interface |
iface-start | start a physical host interface (enable it / "if-up") |
iface-destroy | destroy a physical host interface (disable it / "if-down") |
managedsave | managed save of a domain state |
nodeinfo | Knoteninformation |
nodedev-list | enumerate devices on this host |
nodedev-dumpxml | node device details in XML |
nodedev-dettach | dettach node device from its device driver |
nodedev-reattach | reattach node device to its device driver |
nodedev-reset | reset node device |
nodedev-create | create a device defined by an XML file on the node |
nodedev-destroy | destroy a device on the node |
nwfilter-define | define or update a network filter from an XML file |
nwfilter-undefine | undefine a network filter |
nwfilter-dumpxml | network filter information in XML |
nwfilter-list | list network filters |
nwfilter-edit | edit XML configuration for a network filter |
pool-autostart | autostart a pool |
pool-build | baue einen Pool |
pool-create | create a pool from an XML file |
pool-create-as | create a pool from a set of args |
pool-define | define (but don't start) a pool from an XML file |
pool-define-as | define a pool from a set of args |
pool-destroy | Zerstören eines Pools |
pool-delete | Pool löschen |
pool-dumpxml | Pool-Informationen in XML |
pool-edit | edit XML configuration for a storage pool |
pool-info | storage pool information |
pool-list | Poolliste |
pool-name | Konvertieren einer pool-UUID in einen Pool-Namen |
pool-refresh | Einen Pool aktualisieren |
pool-start | start a (previously defined) inactive pool |
pool-undefine | undefine an inactive pool |
pool-uuid | convert a pool name to pool UUID |
secret-define | define or modify a secret from an XML file |
secret-dumpxml | secret attributes in XML |
secret-set-value | set a secret value |
secret-get-value | Output a secret value |
secret-undefine | undefine a secret |
secret-list | list secrets |
pwd | print the current directory |
quit | Dieses interaktive Terminal beenden |
exit | Dieses interaktive Terminal beenden |
reboot | Domain neu starten |
restore | Eine Domain aus einem gespeicherten Status in einer Datei wiederherstellen |
resume | Domain fortsetzen |
save | Einen Domainstatus in einer Datei speichern |
schedinfo | Scheduler-Parameter anzeigen/setzen |
dump | Den Kern einer Domain zu Analysezwecken in eine Datei dumpen |
shutdown | Kontrolliertes Stillegen einer Domain |
setmem | Speicherzuweisung ändern |
setmaxmem | Maximale Speichergrenze ändern |
setvcpus | Anzahl der virtuellen CPUs ändern |
suspend | Eine Domain anhalten |
ttyconsole | TTY-Konsole |
undefine | Eine inaktive Domain undefinieren |
update-device | update device from an XML file |
uri | Kanonisierte URI des Hypervisors ausgeben |
vol-create | create a vol from an XML file |
vol-create-from | create a vol, using another volume as input |
vol-create-as | create a volume from a set of args |
vol-clone | clone a volume. |
vol-delete | Löschen eines Datenträgers |
vol-wipe | wipe a vol |
vol-dumpxml | vol information in XML |
vol-info | storage vol information |
vol-list | list vols |
vol-pool | returns the storage pool for a given volume key or path |
vol-path | returns the volume path for a given volume name or key |
vol-name | returns the volume name for a given volume key or path |
vol-key | returns the volume key for a given volume name or path |
vcpuinfo | Domain vcpu-Information |
vcpupin | Domain vcpu-Affinität kontrollieren |
version | Version anzeigen |
vncdisplay | VNC-Anzeige |
snapshot-create | Create a snapshot |
snapshot-current | Get the current snapshot |
snapshot-delete | Delete a domain snapshot |
snapshot-dumpxml | Dump XML for a domain snapshot |
snapshot-list | List snapshots for a domain |
snapshot-revert | Revert a domain to a snapshot |
Migration zu neuem Host
virsh migrate --live <GuestName> <DestinationURL>
Beispiel:
# virsh migrate --live galactica qemu+ssh://test2.example.com/system
Autostart
virsh atutostart <domain> virsh atutostart <domain> --disable
An/Aus
Connecten auf Hypervisor
virsh -c qemu+ssh://SERVER/system
In Konsole eingeben
Zum starten:
start VM
Zum virtuellen Stecker rausziehn:
destroy VM
Nach Installation von acpid auf VM
Normales herunterfahren:
shutdown VM
Configure a Serial Console in the Guest
Enable on the VM
cat /etc/init/ttyS0.conf
# ttyS0 - getty # # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 115200 ttyS0 xterm
Run the following command to initiate the Serial Console (or restart the VM):
sudo start ttyS0
Connect on Host to VM
console VM
00:50:56:00:31:f9
Virtuelle MACAdresse vergeben
gaius=KVM server
virsh console XXXXXXX VM: cp /etc/udev/rules./70-persistent.net(cd).rules 70-persistent.net(cd).rules.orig VM: herunterfahren... gaius: vi /etc/libvirt/qemu/XXXXXX.xml
-> MAC eintragen
gaius: virsh define XXXXXXXX gaius: virsh start XXXXXXXX
-> TESTEN
Images umwandeln
qemu-img convert {image_name}.qcow2 {image_name}.raw