xref: /openbsd/usr.sbin/vmctl/vmctl.8 (revision 771fbea0)
1.\"	$OpenBSD: vmctl.8,v 1.73 2021/03/01 14:27:44 kn Exp $
2.\"
3.\" Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: March 1 2021 $
18.Dt VMCTL 8
19.Os
20.Sh NAME
21.Nm vmctl
22.Nd control the virtual machine daemon
23.Sh SYNOPSIS
24.Nm
25.Op Fl v
26.Ar command
27.Op Ar arg ...
28.Sh DESCRIPTION
29The
30.Nm
31utility is used to control the virtual machine monitor (VMM) subsystem.
32A VMM manages virtual machines (VMs) on a host.
33The VMM subsystem is responsible for creating, destroying, and executing
34VMs.
35.Pp
36The
37.Fl v
38option enables verbose mode.
39Within the commands,
40the
41.Ar size
42argument can be specified with a human-readable scale,
43using the format described in
44.Xr scan_scaled 3 .
45The
46.Ar id
47argument can be either a numeric, non-zero identifier or alternatively
48the name of a virtual machine.
49.Pp
50The
51.Ar name
52argument can only consist of alphanumeric characters, as well as '.', '-',
53and '_',
54and must start with a letter.
55.Pp
56The
57.Ar disk
58argument is used by commands that take a path to a disk image file.
59It may be prefixed with a format prefix
60.Pf ( raw : Ns Ar disk
61or
62.Pf qcow2 : Ns Ar disk )
63.Sm on
64in order to specify the disk image format.
65If left unspecified, the format defaults to
66.Sq raw
67if it cannot be derived automatically.
68.Pp
69The commands are as follows:
70.Bl -tag -width Ds
71.It Cm console Ar id
72Using
73.Xr cu 1
74connect to the console of the VM with the specified
75.Ar id .
76.It Cm create Oo Fl b Ar base | Fl i Ar disk Oc Oo Fl s Ar size Oc Ar disk
77Create a VM disk image file with the specified
78.Ar disk
79path.
80.Bl -tag -width "-i input"
81.It Fl b Ar base
82For
83.Sq qcow2 ,
84a
85.Ar base
86image may be specified.
87The base image is not modified and the derived image contains only the
88changes written by the VM.
89.It Fl i Ar disk
90Copy and convert the input
91.Ar disk
92to the newly created disk.
93This option conflicts with
94.Fl b Ar base .
95.It Fl s Ar size
96Specify the
97.Ar size
98of the new disk image, rounded to megabytes.
99If the
100.Fl b
101option is specified, the size must match the size of the
102.Ar base
103image.
104For the
105.Fl i
106option, the size cannot be smaller than the input disk size.
107The size can be omitted with the
108.Fl b
109and
110.Fl i
111options and will be obtained from the base or input image respectively.
112.El
113.It Cm load Ar filename
114Load additional configuration from the specified file.
115.It Cm log brief | verbose
116Disable or enable verbose debug logging.
117.It Cm pause Ar id
118Pause a VM with the specified
119.Ar id .
120.It Cm receive Ar name
121Receive a VM from standard input and start it with the specified
122.Ar name .
123.It Cm reload
124Remove all stopped VMs and reload the configuration from the default
125configuration file.
126.It Cm reset Op Cm all | switches | vms
127Reset the running state,
128reset
129.Cm switches ,
130or reset and terminate all
131.Cm vms .
132.It Cm send Ar id
133Send a VM with the specified
134.Ar id
135to standard output and terminate it.
136The VM is paused during send processing.
137Data sent to standard output contains the VM parameters and its memory,
138not the disk image.
139.Pp
140In order to move a VM from one host to another, disk files must be
141synced between the send and the receive processes and must be located
142under the same path.
143.It Cm show Op Ar id
144An alias for the
145.Cm status
146command.
147.It Xo Cm start
148.Op Fl cL
149.Bk -words
150.Op Fl B Ar device
151.Op Fl b Ar path
152.Op Fl d Ar disk
153.Op Fl i Ar count
154.Op Fl m Ar size
155.Op Fl n Ar switch
156.Op Fl r Ar path
157.Op Fl t Ar name
158.Ar id | name
159.Ek
160.Xc
161Start a new VM
162.Ar name
163with the specified parameters.
164An existing VM may be started by referencing its
165.Ar id .
166.Bl -tag -width "-I parent"
167.It Fl B Ar device
168Force system to boot from the specified device for this boot.
169.Ar device
170can be set to:
171.Pp
172.Bl -tag -width "cdrom" -compact
173.It Ar cdrom
174Boot the CD-ROM image.
175.It Ar disk
176Boot from disk.
177.It Ar net
178Perform a PXE boot using the first network interface.
179.El
180.Pp
181Currently
182.Ar net
183is only supported when booting a kernel using the
184.Fl b
185flag while
186.Ar disk
187and
188.Ar cdrom
189only work with VMs booted using BIOS.
190.It Fl b Ar path
191Boot the VM with the specified
192.Ox
193kernel or custom BIOS image.
194If not specified, the default is to boot using the BIOS image in
195.Pa /etc/firmware/vmm-bios .
196.It Fl c
197Automatically connect to the VM console.
198.It Fl d Ar disk
199Use a disk image at the specified
200.Ar disk
201path (may be specified multiple times to add multiple disk images).
202.It Fl i Ar count
203Number of network interfaces to add to the VM.
204.It Fl L
205Add a local network interface.
206.Xr vmd 8
207will auto-generate an IPv4 subnet for the interface,
208configure a gateway address on the VM host side,
209and run a simple DHCP/BOOTP server for the VM.
210See
211.Sx LOCAL INTERFACES
212below for more information on how addresses are calculated and assigned when
213using the
214.Fl L
215option.
216.It Fl m Ar size
217Memory
218.Ar size
219of the VM, rounded to megabytes.
220The default is 512M.
221.It Fl n Ar switch
222Add a network interface that is attached to the specified virtual
223.Ar switch .
224See the SWITCH CONFIGURATION section in
225.Xr vm.conf 5
226for more information.
227.It Fl r Ar path
228ISO image file for virtual CD-ROM.
229This image file will be available in the
230selected VM as a SCSI CD-ROM device attached to a virtio SCSI adapter
231(e.g.\&
232.Xr vioscsi 4 ) .
233.It Fl t Ar name
234Use an existing VM with the specified
235.Ar name
236as a template to create a new VM instance.
237The instance will inherit settings from the parent VM,
238except for exclusive options such as disk, interface lladdr, and
239interface names.
240.El
241.It Cm status Op Ar id
242List VMs running on the host, optionally listing just the selected VM
243.Ar id .
244.It Cm stop Oo Fl fw Oc Oo Fl a | Ar id Oc
245Stop (terminate) a VM defined by the specified VM
246.Ar id
247or all running VMs
248.Pq Fl a .
249By default,
250a graceful shutdown will be attempted if the VM supports the
251.Xr vmmci 4
252device.
253.Pp
254The following options can be specified when stopping a VM:
255.Bl -tag -width "-w"
256.It Fl f
257Forcefully stop the VM without attempting a graceful shutdown.
258.It Fl w
259Wait until the VM has been terminated.
260.El
261.It Cm unpause Ar id
262Unpause (resume from a paused state) a VM with the specified
263.Ar id .
264.It Cm wait Ar id
265Wait until the specified VM has stopped.
266.El
267.Pp
268If the
269.Fl i ,
270.Fl L ,
271or
272.Fl n
273options are specified during VM startup, a corresponding number
274of host-side
275.Xr tap 4
276interfaces will be allocated and mapped to the
277.Xr vio 4
278interfaces inside the guest VM.
279This tap/vio interface mapping
280allows guest network traffic to be manipulated by the host.
281Any valid host-side interface configuration may be performed on these
282tap interfaces, such as bridging (via
283.Xr veb 4 ) ,
284or using
285.Xr pf 4
286nat-to rules to create private or host-side NATed networks, as desired.
287For each
288.Xr tap 4
289network interface on the host,
290.Xr vmd 8
291will set the interface's description to allow easy identification of
292the corresponding VM by ID, interface number, and name:
293.Bd -literal -offset indent
294# ifconfig tap0
295tap0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
296	lladdr fe:e1:ba:d8:50:d1
297	description: vm1-if0-myvm
298	index 15 priority 0 llprio 3
299	groups: tap
300	status: active
301.Ed
302.Sh LOCAL INTERFACES
303Local interfaces can be used to easily configure VM networking without
304needing to manually assign network addresses.
305A local interface is added
306to a VM using the -L option to the 'vmctl start' command and results in the
307addition of a
308.Xr vio 4
309interface inside the VM and a corresponding
310.Xr tap 4
311interface on the host.
312When using local interfaces,
313.Xr vmd 8
314will provide DHCP services to the guest VM and offer addresses selected
315from the 100.64.0.0/10 IPv4 range.
316From within the 100.64.0.0/10
317range,
318.Xr vmd 8
319allocates a pair of addresses for the guest-side
320.Xr vio 4
321and host-side
322.Xr tap 4
323interfaces as follows:
324.Pp
325For the first local interface:
326.Bl -bullet -compact
327.It
328The host (tapX) address is assigned 100.64.n.2,
329where 'n' is the numeric VM ID visible in the 'vmctl status' command
330.It
331The guest (vio0) address is assigned 100.64.n.3
332.El
333.Pp
334For the second and subsequent local interface(s):
335.Bl -bullet -compact
336.It
337The second local interface uses 100.64.n.4 and 100.64.n.5 for the
338host (tapX) and guest (vio1) interfaces, respectively.
339.It
340Subsequent local interfaces are numbered similarly, continuing with 100.64.n.6
341and 100.64.n.7, etc
342.El
343.Pp
344Multiple -L options can be provided to the 'vmctl start' command, if more than
345one interface is desired.
346Local interfaces are assigned to the VM before
347any other interfaces specified with the -i option (thus, local interfaces,
348if requested, are numbered starting at vio0 inside the guest VM).
349.Pp
350If NAT is desired, the
351.Va net.inet.ip.forwarding
352.Xr sysctl 8
353must also be set to 1.
354.Pp
355When using local interfaces, the DHCP configuration offered to the guest VM
356specifies the address of the corresponding host
357.Xr tap 4
358interface as both the default route and the (sole) nameserver.
359Guest VM traffic can optionally be NATed through the host
360with an entry in the host machine's
361.Pa /etc/pf.conf
362similar to the following:
363.Bd -literal -offset indent
364pass out on egress from 100.64.0.0/10 to any nat-to (egress)
365.Ed
366.Pp
367If desired, DNS queries originating from guest VMs can be redirected to a
368different DNS server with an entry in the host machine's
369.Pa /etc/pf.conf
370similar to the following:
371.Bd -literal -offset indent
372pass in proto { udp tcp } from 100.64.0.0/10 to any port domain \e
373      rdr-to $dns_server port domain
374.Ed
375.Sh FILES
376.Bl -tag -width "/etc/var/run/vmd.sockXX" -compact
377.It Pa /etc/vm.conf
378Default configuration file.
379.It Pa /var/run/vmd.sock
380.Ux Ns -domain
381socket used for communication with
382.Xr vmd 8 .
383.El
384.Sh EXIT STATUS
385.Ex -std vmctl
386.Nm
387may fail due to one of the following reasons:
388.Pp
389.Bl -bullet -compact
390.It
391The VMM subsystem could not be enabled or disabled as requested.
392.It
393A requested VM-based operation could not be completed.
394.El
395.Sh EXAMPLES
396Create a 4.5 Gigabyte disk image, disk.img:
397.Bd -literal -offset indent
398$ vmctl create -s 4.5G disk.img
399.Ed
400.Pp
401Convert a disk image from the
402.Sq raw
403format to
404.Sq qcow2 :
405.Bd -literal -offset indent
406$ vmctl create -i disk.img disk.qcow2
407.Ed
408.Pp
409Create a new VM with 1GB memory, one network interface, one disk image
410('disk.img') and boot from kernel '/bsd':
411.Bd -literal -offset indent
412# vmctl start -m 1G -i 1 -b /bsd -d disk.img "myvm"
413.Ed
414.Pp
415Start a new VM instance with the name 'myvm' from a pre-configured
416VM 'openbsd.4G':
417.Bd -literal -offset indent
418# vmctl start -t "openbsd.4G" -d mydisk.img "myvm"
419.Ed
420.Pp
421Terminate VM number 1:
422.Bd -literal -offset indent
423# vmctl stop 1
424.Ed
425.Sh SEE ALSO
426.Xr pf 4 ,
427.Xr tap 4 ,
428.Xr veb 4 ,
429.Xr vio 4 ,
430.Xr vmm 4 ,
431.Xr vm.conf 5 ,
432.Xr rc.conf 8 ,
433.Xr sysctl 8 ,
434.Xr vmd 8
435.Sh HISTORY
436The
437.Nm
438command first appeared in
439.Ox 5.9 .
440.Sh AUTHORS
441.An -nosplit
442.An Mike Larkin Aq Mt mlarkin@openbsd.org
443and
444.An Reyk Floeter Aq Mt reyk@openbsd.org .
445