Using virsh (command line)

By default, virsh will connect as a normal user to his|her own set of guests on the local machine or, when run as root, to the guests owned by root (known as the system hypervisor).

As we typically share management of servers, we would normally install guests in the system hypervisor.

To access guests in the system hypervisor from a normal user, you need to call virsh with the --connect option.

virsh --connect qemu:///system  ......

To access guests in the system hypervisor on a remote machine, use the following

virsh --connect qemu+ssh://<remoteserver>/system .....

The following assume you are running as root, connecting to the system hypervisor on the local machine.

Starting a guest (and connect to serial console)
virsh start <guest> --console

Connect to guest's serial console
virsh console <guest>

Clean shutdown
virsh shutdown <guest>

Kill a guest
virsh destroy <guest>

Modify boot order to network,hd
kvmtool setbootorder --name <guest> --bootorder network,hd

Deleting a guest
kvmtool delete --name <guest>
Note that the guest's disk image will not be deleted: add -purge if you want to delete the disk image.

Note that kvmtool defaults to the system hypervisor regardless of whether it is called as a normal user or root. It also accepts the shortcut --host as a way of accessing the system hypervisor on a remote host.

There is also a tool rvirsh {hostname}_{virsh command} which will run a virsh command on the remote KVM server {hostname}. This means that you don't need to remember the clunky QEMU url above.

-- AlastairScobie - 28 Oct 2011

Topic revision: r5 - 13 Mar 2012 - 15:51:05 - AlastairScobie
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
This Wiki uses Cookies