Virsh is a command line executable to control existing virtual machines. It includes a number of commands to help manage KVM(kernel-based virtual machine) instances. It allows for easy command line management often remotely of virtual machines through SSH access.
To enter the command shell over ssh just type the following:
From there you can type the help command to view all of the possible commands. We will cover some of the more common commands for managing virtual machines. Virsh commands can also be executed directly from the command line as opposed to starting the virsh enviroment by prefixing each command with virsh.
View all of the virtual machines on this system
# virsh list --all
and you will see a similar output:
Id Name State ---------------------------------------------------- 5 centos7-1 running 84 centos7-2 running 85 centos7-3 running
Start a virtual machine
# virsh start server-name
Replace server-name with the virtual machine you are attempting to start
Stopping a virtual machine
Shutdown a virtual machine:
# virsh shutdown server-name
This will attempt to gracefully stop a virtual machine and power it off.
Power off a virtual machine
# virsh destroy server-name
This will immediately power off a virtual machine. This is the equivalent to removing the power cord on a running physical server.
Reboot a virtual machine
# virsh reboot server-name
Auto start configuration for virtual machines
To have a virtual machine start every time a server reboots type the following:
# virsh autostart server-name
To prevent a virtual machine from starting every time a server reboots type the following
# virsh autostart --disable server-name
Attach a console to a virtual machine
To view the console output of a virtual machine type the following
# virsh console server-name
There are many more things virsh can do, this is just the basics to get you through power management of a virtual machine on the command line. If you have not already, please check out multi-part series on setting up KVM: