Top 10 Basic virsh commands for KVM Hypervisor management

The virtual shell or  virsh program is the main interface for managing virsh guest domains. This program can be used to list, create, pause, and shutdown domains.

1. Display information about the hypervisor

virsh nodeinfo

Sample output:
tux@ubuntuserver:~$ virsh nodeinfo
CPU model: x86_64
CPU(s): 40
CPU frequency: 1199 MHz
CPU socket(s): 1
Core(s) per socket: 10
Thread(s) per core: 2
NUMA cell(s): 2
Memory size: 263945968 KiB

2. List all domains

virsh list –all

Sample output: (with –all options, it will display also those shut off domains)

tux@ubuntuserver:~$ virsh list –all
Id   Name    State
4   eve-ng     running
–    redhat    shut off
–    debian   shut off

3.  Display domain information

virsh dominfo [domain id/name]

Sample Output:

tux@ubuntuserver:~$ virsh dominfo eve-ng
Id: 4
Name: eve-ng
UUID: afac7793-29f9-4754-84f3-42157e41934b
OS Type: hvm
State: running
CPU(s): 16
CPU time: 64353519.3s
Max memory: 67108864 KiB
Used memory: 67108864 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
Security label: libvirt-afac7793-29f9-4754-84f3-42157e41934b (enforcing)

4.  Output domain/guest XML configuration

virsh dumpxml [domain id/name]

Sample output:
tux@ubuntuserver:~$ virsh dumpxml 4
<domain type=’kvm’ id=’4′>
<memory unit=’KiB’>67108864</memory>
<currentMemory unit=’KiB’>67108864</currentMemory>
<vcpu placement=’static’>16</vcpu>
<type arch=’x86_64′ machine=’pc-i440fx-trusty’>hvm</type>
<boot dev=’hd’/>
<source file=’/home/tux/images/eve-ng.qcow2’/>
<interface type=’bridge’>
<mac address=’11:24:30:56:38:28’/>
<source bridge=’br0’/>
<target dev=’vnet0’/>
<model type=’rtl8139’/>

5.  Edit guest/domain configuration file (can  be done while running or offline)

virsh edit [domain id/name]

6.  Shutdown a guest/domain

virsh shutdown [domain id/name]

Sample Output:

tux@ubuntuserver:~$ virsh list
Id Name State
4   eve-ng   running
10 server1 running

tux@ubuntuserver:~$ virsh shutdown 10
Domain 10 is being shutdown

7. Start a guest/domain

virsh start [domain id/name]

Sample Output:

tux@ubuntuserver:~/$ virsh start eve-ng
Domain eve-ng started

8. Suspend a guest/domain ( when in a suspended state, it still consumes system RAM but disk and network I/O will not occur). State will be “paused”.

virsh suspend [domain id/name]

Sample Output:

tux@ubuntuserver:~$ virsh list
Id Name State
4 eve-ng  running
11 server1 running

tux@ubuntuserver:~$ virsh suspend server1
Domain server1 suspended

tux@ubuntuserver:~$ virsh list
Id Name State
4 eve-ng running
11 server1 paused

9. Resume a guest/domain (to resume from the “suspend” command)

virsh resume [domain id/name]

Sample Output:

tux@ubuntuserver:~$ virsh resume server1
Domain server1 resumed

10.  Connect the virtual serial console for the guest.

virsh console [domain id/name]

About the author

Free Linux Tutorials

View all posts

Leave a Reply