Linux Harbour

Technology News of Linux & Open Source


How to manage KVM Virtual Machine

virsh is the administration tool of KVM virtual machine, for examples, starting up or shutting down VM operation, control and modify the virtual machine, etc. virsh can be used as an interactive command shell or direct execution with its sub-commands.

List KVM Virtual Machine and their names

‘virsh list’ lists the running KVM virtual machine. With the option –all, all virtual machines will be listed including stopped VMs. VM names (aka domName) can be checked out from the result.

$ virsh list
$ virsh list –all

Query KVM Virtual Machine information

‘virsh dominfo’ shows the information of a specific KVM virtual machine. ‘virsh dumpxml’ exports the detailed configuration of a specific KVM virtual machine in XML data format.

$ virsh dominfo mylinuxvm
$ virsh dumpxml mylinuxvm

Starting and Stopping KVM Virtual Machine

Virtual machine with a known name can be started, stopped, rebooted, destroyed with virsh sub-commands, the following example is assumpted for the virtual machine name ‘mylinuxvm’.

$ virsh start mylinuxvm
$ virsh reboot mylinuxvm
$ virsh shutdown mylinuxvm
$ virsh destroy mylinuxvm

Manage KVM Virtual Machine

For system administration, ‘virsh console’ can be used to connect with Virtual Machine as console if the serial console is available on the Virtual Machine.

$ virsh console mylinuxvm

Setup serial console on Ubuntu 16.04 virtual machine

$ sudo systemctl enable [email protected]
$ sudo systemctl start [email protected]

Setup serial console on Ubuntu 14.04 virtual machine

First, modify the parameter GRUB_CMDLINE_LINUX_DEFAULT in the file /etc/default/grub, and then execute ‘update-grub’.

GRUB_CMDLINE_LINUX_DEFAULT=”console=ttyS0,38400n8 console=tty0″

Next, copy the file /etc/init/tty1.conf to ttyS0.conf, edit the last command to “exec /sbin/getty -8 38400 ttyS0”.

$ cp /etc/init/tty1.conf /etc/init/ttyS0.conf
$ nano /etc/init/ttyS0.conf

Removing KVM virtual machine

If a specific KVM virtual machine is no longer in use, ‘virsh undefine’ can be used to remove this KVM virtual machine, for an example if the domName of VM is mylinuxvm:

$ virsh undefine mylinuxvm





Sammy Fung

Sammy is the founder of the Linux Harbour.