User Tools

Site Tools


public:kvm:access:local_libvirt

Local libvirt access

Overview

The command line tool of choice for accessing the libvirt process is virsh. The command virsh help shows all defined sub-commands. The sub-commands are organized in the following command groups:

root@kvm55:~# virsh help |grep 'help keyword'
 Domain Management (help keyword 'domain'):
 Domain Monitoring (help keyword 'monitor'):
 Host and Hypervisor (help keyword 'host'):
 Interface (help keyword 'interface'):
 Network Filter (help keyword 'filter'):
 Networking (help keyword 'network'):
 Node Device (help keyword 'nodedev'):
 Secret (help keyword 'secret'):
 Snapshot (help keyword 'snapshot'):
 Storage Pool (help keyword 'pool'):
 Storage Volume (help keyword 'volume'):
 Virsh itself (help keyword 'virsh'):

With the help of the keywords detailed help to commands of command groups can be derived:

root@kvm55:~# virsh help secret
 Secret (help keyword 'secret'):
    secret-define            define or modify a secret from an XML file
    secret-dumpxml           secret attributes in XML
    secret-get-value         Output a secret value
    secret-list              list secrets
    secret-set-value         set a secret value
    secret-undefine          undefine a secret

The help content for a single sub-command can be displayed with the command virsh help <sub-command>:

root@kvm55:~# virsh help define
  NAME
    define - define (but don't start) a domain from an XML file

  SYNOPSIS
    define <file>

  DESCRIPTION
    Define a domain.

  OPTIONS
    [--file] <string>  file containing an XML domain description

Command overview

The most important virsh sub-commands for everyday use are summarized in the following table.

No. command use
1 virsh list display host names of active virtual hosts
2 virsh list –all display host names of all defined (active and not active) virtual hosts
3 virsh start <vhost> start a virtual host
4 virsh shutdown <vhost> shut down a running virtual host
5 virsh reboot <vhost> reboot a running virtual host
6 virsh destroy <vhost> shut off a running virtual host abruptly
7 virsh suspend <vhost> stop a running virtual host
8 virsh resume <vhost> continue running a stopped virtual host
9 virsh save <vhost> <file> save the memory of a virtual host into a file and stop the virtual host afterwards
10 virsh restore <file> restore the memory of a virtual host from a file and continue running the virtual host
11 virsh dumpxml <vhost> output the virtual host definition in XML format
12 virsh define <file> read the virtual host definition from a XML file
13 virsh undefine <hostname> remove the virtual host definition from system

Annotations to some commands

commands 7.) und 8.) virsh suspend/resume

When using these commands the clock of the virtual host is updated after execution of virsh resume.

commands 9.) und 10.) virsh save/restore

When using these commands the clock of the virtual host is not updated after execution of virsh restore. The clock of the vhost has to be updated by one of the following methods:

  • ntpdate: sudden time change – can lead to problems with applications
  • ntp service: slow time change - can take a rather long time

The command combination virsh save/restore is best suited in order to stop all vhosts on a KVM host, reboot the KVM host and restart all vhosts again

command 11.) virsh dumpxml

Reconfiguring a running vhost from the command line with virsh commands only changes the vhost configuration in the memory of the KVM host. After a restart of the vhost the configuration is still valid that was valid before the reconfiguration and that was stored on the hard disk.
In order to store configuration changes done from the command line persistently, the host definition file has to be updated. The file is stored in the folder '/etc/libvirt/qemu' and normally uses the file name '<vhostname>.xml'. The file update for the vhost 'vhostname' can be done like so:

root@kvm55:~# cd /etc/libvirt/qemu
root@kvm55:~# virsh dumpxml vhostname --inactive >vhostname.xml

It is safe to update the file while the vhost is running, because the file is only read at vhost start-up.

command 12.) virsh define

When in contradiction to command 11.) the xml configuration file of a running vhost in folder '/etc/libvirt/qemu' is changed, the current settings of a running vhost in memory are not changed. When the changes should not only be valid after a shutdown/reboot, the changed vhost definition has to be read into the memory of the KVM host. This is done by the command virsh define:

root@kvm55:~# cd /etc/libvirt/qemu
root@kvm55:~# virsh define vhostname vhostname.xml

It is save to execute the command while the affected vhost is running. Some configuration changes are not possible while the vhost is running and therefore are not carried out. These changes become only valid after a shutdown/reboot. Changes of a xml file with the following execution of virsh define behave identical here with respect to vhost configuration changes by the VMM GUI.

previous chapter | contents | next chapter

public/kvm/access/local_libvirt.txt · Last modified: 2018/06/08 16:42 by wiki.tk