1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
[% topdir = "../.." -%]
[% PROCESS globals -%]
[% WRAPPER page
title = "List virtual machines using the command line"
h1 = "List virtual machines using the command line"
section = "learning"
%]
<p>
Open a Terminal window.
</p>
<p>
On Fedora and Debian you will need to become root. Type
the following command and, when prompted, your root password:
</p>
<pre>
su
</pre>
<p>
Then you can list all the virtual machines:
</p>
<pre>
virsh list --all
</pre>
<p>
On Ubuntu, you should use <code>sudo</code> to run the command
as root instead:
</p>
<pre>
sudo virsh list --all
</pre>
[% WRAPPER h2 h2="virsh list output explained" anchor="virsh-list-output" %]
<p>
When you run the command you should see a listing like this:
</p>
<pre>
Id Name State
----------------------------------
3 FedoraRawhide running
- Debian shut off
</pre>
<p>
The three columns are:
</p>
<ul>
<li> <code>Id</code>: A unique number given to running virtual machines.
</li>
<li> <code>Name</code>: The name of the VM, which you specified when
it was created.
</li>
<li> <code>State</code>: The state which is <q>shut off</q> for
VMs that are switched off, and various other states for
running and paused VMs.
</li>
</ul>
<p>
Other virt tools commands can use either the <code>Id</code> or the
<code>Name</code> to refer to the virtual machine. For example
these two commands are equivalent ways to show the console:
</p>
<pre>
virt-viewer 3
virt-viewer FedoraRawhide
</pre>
[% END %]
[% WRAPPER h2 h2="virsh list troubleshooting" anchor="virsh-list-troubleshooting" %]
<p>
If <code>virsh list</code> displays an error, then try
searching for the error or <a href="[% topdir %]/contact/">contacting us</a>.
For QEMU, KVM, and remote connections, ensure that the
<code>libvirtd</code> service is running.
</p>
<p>
Many errors are obvious from the error message, for example:
</p>
<pre>
error: no connection driver available for xen:///
error: failed to connect to the hypervisor
</pre>
<p>
would mean that the Xen hypervisor is not running on the
local machine.
</p>
<p>
If <code>virsh list --all</code> runs but displays nothing, it
could mean:
</p>
<ul>
<li> You haven't installed any guests. </li>
<li> You forgot the <code>--all</code> flag. </li>
<li> (For QEMU and KVM) Guests are running but were not started up
by libvirt. For example you might have started them by running
the <code>qemu</code> command directly. </li>
</ul>
[% END %]
[% WRAPPER h2 h2="virsh flags" anchor="virsh-flags" %]
<p>
The <code>--all</code> flag lists all virtual machines, which
includes ones which are currently running and ones which are
switched off. If you omit this flag then only running virtual
machines are shown.
</p>
<p>
Another useful flag is <code>-c</code> which can be used to
select the hypervisor. This can be used if you are running
two hypervisors on one machine (eg. Xen and QEMU guests),
or if you are not root and want to connect to the system
hypervisor, or to connect to a remote server running libvirtd.
</p>
<p>
Use the <code>-r</code> flag to connect read-only to the hypervisor.
This is useful to perform operations while not requiring the
root password.
</p>
<p>
For example, if you are not root and want to list QEMU and KVM guests
without needing the root password you could do:
</p>
<pre>
virsh -r -c qemu:///system list --all
</pre>
<p>
<a href="http://libvirt.org/remote.html">This libvirt documentation
describes remote connections</a> in detail.
</p>
[% END %]
[% END -%]
|