xref: /freebsd/sbin/bectl/bectl.8 (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\"
16.\"     @(#)be.1
17.\"
18.\" $FreeBSD$
19.\"
20.Dd June 28, 2023
21.Dt BECTL 8
22.Os
23.Sh NAME
24.Nm bectl
25.Nd Utility to manage boot environments on ZFS
26.Sh SYNOPSIS
27.Nm
28.Op Fl h\&?
29.Nm
30.Op Fl r Ar beroot
31.Cm activate
32.Op Fl t | Fl T
33.Ar beName
34.Nm
35.Op Fl r Ar beroot
36.Cm check
37.Nm
38.Op Fl r Ar beroot
39.Cm create
40.Op Fl r
41.Op Fl e Brq Ar nonActiveBe | Ar beName Ns Cm @ Ns Ar snapshot
42.Ar newBeName
43.Nm
44.Op Fl r Ar beroot
45.Cm create
46.Op Fl r
47.Ar beName@snapshot
48.Nm
49.Op Fl r Ar beroot
50.Cm destroy
51.Op Fl \&Fo
52.Ar beName Ns Op Cm @ Ns Ar snapshot
53.Nm
54.Op Fl r Ar beroot
55.Cm export
56.Ar sourceBe
57.Nm
58.Op Fl r Ar beroot
59.Cm import
60.Ar targetBe
61.Nm
62.Op Fl r Ar beroot
63.Cm jail
64.Op Fl bU
65.Oo Bro Fl o Ar key Ns Cm = Ns Ar value | Fl u Ar key Brc Oc Ns ...
66.Ar beName
67.Op Ar utility Op Ar argument ...
68.Nm
69.Op Fl r Ar beroot
70.Cm list
71.Op Fl aDHs
72.Op Fl c Ar property
73.Op Fl C Ar property
74.Oo Bro Fl c Ar property | Fl C Ar property Brc Oc
75.Nm
76.Op Fl r Ar beroot
77.Cm mount
78.Ar beName
79.Op Ar mountpoint
80.Nm
81.Op Fl r Ar beroot
82.Cm rename
83.Ar origBeName
84.Ar newBeName
85.Nm
86.Op Fl r Ar beroot
87.Brq Cm ujail | unjail
88.Brq Ar jailId | jailName | beName
89.Nm
90.Op Fl r Ar beroot
91.Brq Cm umount | unmount
92.Op Fl f
93.Ar beName
94.Sh DESCRIPTION
95The
96.Nm
97command is used to setup and interact with ZFS boot environments, which are
98bootable clones of datasets.
99.Pp
100A boot environment allows the system to be upgraded, while preserving the
101pre-upgrade system environment.
102.Pp
103.Nm
104itself accepts an
105.Fl r
106flag specified before the command to indicate the
107.Ar beroot
108that should be used as the boot environment root, or the dataset whose children
109are all boot environments.
110Normally this information is derived from the bootfs property of the pool that
111is mounted at
112.Pa / ,
113but it is useful when the system has not been booted into a ZFS root or a
114different pool should be operated on.
115For instance, booting into the recovery media and manually importing a pool from
116one of the system's resident disks will require the
117.Fl r
118flag to work.
119.Pp
120.Ss Supported Subcommands and Flags
121.Bl -tag -width activate
122.It Xo
123.Fl h |
124.Fl \&?
125Print usage information.
126.It Xo
127.Cm activate
128.Op Fl t | Fl T
129.Ar beName
130.Xc
131Activate the given
132.Ar beName
133as the default boot filesystem.
134If the
135.Fl t
136flag is given, this takes effect only for the next boot.
137Flag
138.Fl T
139removes temporary boot once configuration.
140Without temporary configuration, the next boot will use zfs dataset specified
141in boot pool
142.Ar bootfs
143property.
144.It Xo
145.Cm check
146.Xc
147Performs a silent sanity check on the current system.
148If boot environments are supported and used,
149.Nm
150will exit with a status code of 0.
151Any other status code is not currently defined and may, in the future, grow
152special meaning for different degrees of sanity check failures.
153.It Xo
154.Cm create
155.Op Fl r
156.Op Fl e Brq Ar nonActiveBe | Ar beName Ns Cm @ Ns Ar snapshot
157.Ar newBeName
158.Xc
159Create a new boot environment named
160.Ar newBeName .
161.Pp
162If the
163.Fl r
164flag is given, a recursive boot environment will be made.
165See
166.Sx Boot Environment Structures
167for a discussion on different layouts.
168.Pp
169If the
170.Fl e
171flag is specified, the new environment will be cloned from the given
172.Ar nonActiveBe
173or
174.Ar beName Ns Cm @ Ns Ar snapshot .
175Otherwise, the new environment will be created from the currently booted
176environment.
177.Pp
178If
179.Nm
180is creating from another boot environment, a snapshot of that boot environment
181will be created to clone from.
182.It Xo
183.Cm create
184.Op Fl r
185.Ar beName@snapshot
186.Xc
187Create a snapshot of the boot environment named
188.Ar beName .
189.Pp
190If the
191.Fl r
192flag is given, a recursive snapshot of the boot environment will be created.
193A snapshot is created for each descendant dataset of the boot environment.
194See
195.Sx Boot Environment Structures
196for a discussion on different layouts.
197.Pp
198No new boot environment is created with this subcommand.
199.It Xo
200.Cm destroy
201.Op Fl \&Fo
202.Ar beName Ns Op Cm @ Ns Ar snapshot
203.Xc
204Destroy the given
205.Ar beName
206boot environment or
207.Ar beName Ns Cm @ Ns Ar snapshot
208snapshot without confirmation, unlike in
209.Xr beadm 1 .
210Specifying
211.Fl F
212will automatically unmount without confirmation.
213.Pp
214By default,
215.Nm
216will warn that it is not destroying the origin of
217.Ar beName .
218The
219.Fl o
220flag may be specified to destroy the origin as well.
221.It Cm export Ar sourceBe
222Export
223.Ar sourceBe
224to
225.Xr stdout 4 .
226.Xr stdout 4
227must be piped or redirected to a file.
228.It Cm import Ar targetBe
229Import
230.Ar targetBe
231from
232.Xr stdin 4 .
233.It Xo
234.Cm jail
235.Op Fl bU
236.Oo Bro Fl o Ar key Ns Cm = Ns Ar value | Fl u Ar key Brc Oc Ns ...
237.Ar beName
238.Op Ar utility Op Ar argument ...
239.Xc
240Create a jail of the given boot environment.
241Multiple
242.Fl o
243and
244.Fl u
245arguments may be specified.
246.Fl o
247will set a jail parameter, and
248.Fl u
249will unset a jail parameter.
250.Pp
251By default, jails are created in interactive mode and
252.Pa /bin/sh
253is
254executed within the jail.
255If
256.Ar utility
257is specified, it will be executed instead of
258.Pa /bin/sh .
259The jail will be destroyed and the boot environment unmounted when the command
260finishes executing, unless the
261.Fl U
262argument is specified.
263.Pp
264The
265.Fl b
266argument enables batch mode, thereby disabling interactive mode.
267The
268.Fl U
269argument will be ignored in batch mode.
270.Pp
271The
272.Va name ,
273.Va host.hostname ,
274and
275.Va path
276must be set, the default values are specified below.
277.Pp
278All
279.Ar key Ns Cm = Ns Ar value
280pairs are interpreted as jail parameters as described in
281.Xr jail 8 .
282The following default parameters are provided:
283.Bl -column "allow.mount.devfs" ""
284.It Va allow.mount Ta Cm true
285.It Va allow.mount.devfs Ta Cm true
286.It Va enforce_statfs Ta Cm 1
287.It Va name Ta Set to jail ID.
288.It Va host.hostname Ta Va bootenv
289.It Va path Ta Set to a path in Pa /tmp
290generated by
291.Xr libbe 3 .
292.El
293.Pp
294All default parameters may be overwritten.
295.It Xo
296.Cm list
297.Op Fl aDHs
298.Oo Bro Fl c Ar property | Fl C Ar property Brc Oc
299.Xc
300.Pp
301Display all boot environments.
302The
303.Em Active
304field indicates whether the boot environment is active now
305.Pq Em \&N ;
306active on reboot
307.Pq Em \&R ;
308is used on next boot once
309.Pq Em \&T ;
310or combination of
311.Pq Em \&NRT .
312.Bl -tag -width indent
313.It Fl a
314Display all datasets.
315.It Fl D
316Display the full space usage for each boot environment, assuming all
317other boot environments were destroyed.
318.It Fl H
319Used for scripting.
320Do not print headers and separate fields by a single tab instead of
321arbitrary white space.
322.It Fl s
323Display all snapshots as well.
324.It Fl c Ar property
325Sort boot environments by the given ZFS dataset property.
326The following properties are supported:
327.Pp
328.Bl -tag -width 4n -offset indent -compact
329.It name (the default)
330.It creation
331.It origin
332.It used
333.It usedbydataset
334.It usedbyrefreservation
335.It usedbysnapshots
336.El
337.Pp
338Short forms usedds, usedrefreserv and usedsnap are also supported.
339.It Fl C Ar property
340Same as the
341.Fl c
342option, but displays in descending order.
343.El
344.Pp
345The
346.Fl D
347option is ignored when either the
348.Fl s
349or
350.Fl a
351option is used.
352.It Cm mount Ar beName Op Ar mountpoint
353Mount the given boot environment.
354.Pp
355If a nonexistent
356.Ar mountpoint
357is given:
358.Nm
359will make the directory, including intermediate directories as required.
360.Pp
361If no
362.Ar mountpoint
363is given:
364.Nm
365will make a directory such as
366.Pa be_mount.c6Sf
367in
368.Pa /tmp .
369Randomness in the last four characters of the directory name will prevent
370mount point conflicts.
371Unmount of an environment, followed by mount of the same environment
372without giving a
373.Ar mountpoint ,
374will result in a different randomly-named mountpoint.
375.It Cm rename Ar origBeName newBeName
376Rename the given
377.Ar origBeName
378to the given
379.Ar newBeName .
380The boot environment will not be unmounted in order for this rename to occur.
381.It Cm ujail Brq Ar jailId | jailName | beName
382.It Cm unjail Brq Ar jailId | jailName | beName
383Destroy the jail created from the given boot environment.
384.It Xo
385.Cm umount
386.Op Fl f
387.Ar beName
388.Xc
389.It Xo
390.Cm unmount
391.Op Fl f
392.Ar beName
393.Xc
394Unmount the given boot environment, if it is mounted.
395Specifying
396.Fl f
397will force the unmount if busy.
398.Pp
399Unmount will not remove the mount point.
400.El
401.Pp
402.Ss Boot Environment Structures
403The traditional
404.Fx
405boot environment layout, as created by the Auto ZFS option to
406.Xr bsdinstall 8 ,
407is a
408.Dq shallow
409boot environment structure, where boot environment datasets do not have any
410directly subordinate datasets.
411Instead, they're organized off in
412.Pa zroot/ROOT ,
413and they rely on datasets elsewhere in the pool having
414.Dv canmount
415set to
416.Dv off .
417For instance, a simplified pool may be laid out as such:
418.Bd -literal -offset indent
419% zfs list -o name,canmount,mountpoint
420NAME			CANMOUNT	MOUNTPOINT
421zroot
422zroot/ROOT		noauto		none
423zroot/ROOT/default	noauto		none
424zroot/home		on		/home
425zroot/usr		off		/usr
426zroot/usr/src		on		/usr/src
427zroot/var		off		/var
428.Ed
429.Pp
430In that example,
431.Pa zroot/usr
432has
433.Dv canmount
434set to
435.Dv off ,
436thus files in
437.Pa /usr
438typically fall into the boot environment because this dataset is not mounted.
439.Pa zroot/usr/src
440is mounted, thus files in
441.Pa /usr/src
442are not in the boot environment.
443.Pp
444The other style of boot environments in use, frequently called
445.Dq deep boot environments ,
446organizes some or all of the boot environment as subordinate to the boot
447environment dataset.
448For example:
449.Bd -literal -offset indent
450% zfs list -o name,canmount,mountpoint
451NAME				CANMOUNT	MOUNTPOINT
452zroot
453zroot/ROOT			noauto		none
454zroot/ROOT/default		noauto		none
455zroot/ROOT/default/usr		noauto		/usr
456zroot/ROOT/default/usr/local	noauto		/usr/local
457zroot/var			on		/var
458.Ed
459.Pp
460Note that the subordinate datasets now have
461.Dv canmount
462set to
463.Dv noauto .
464These are more obviously a part of the boot environment, as indicated by their
465positioning in the layout.
466These subordinate datasets will be mounted by the
467.Dv zfsbe
468.Xr rc 8
469script at boot time.
470In this example,
471.Pa /var
472is excluded from the boot environment.
473.Pp
474.Nm
475subcommands that have their own
476.Fl r
477operate on this second,
478.Dq deep
479style of boot environment, when the
480.Fl r
481flag is set.
482A future version of
483.Nm
484may default to handling both styles and deprecate the various
485.Fl r
486flags.
487\" .Sh EXAMPLES
488\" .Bl -bullet
489\" .It
490\" To fill in with jail upgrade example when behavior is firm.
491\" .El
492.Sh SEE ALSO
493.Xr libbe 3 ,
494.Xr zfsprops 7 ,
495.Xr beinstall.sh 8 ,
496.Xr jail 8 ,
497.Xr zfs 8 ,
498.Xr zpool 8
499.Sh HISTORY
500.Nm
501is based on
502.Xr beadm 1
503and was implemented as a project for the 2017 Summer of Code, along with
504.Xr libbe 3 .
505.Sh AUTHORS
506.Nm
507was written by
508.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in .
509.Pp
510.Xr beadm 1
511was written and is maintained by
512.An Slawomir Wojciech Wojtczak (vermaden) Aq Mt vermaden@interia.pl .
513.Pp
514.An Bryan Drewery (bdrewery) Aq Mt bryan@shatow.net
515wrote the original
516.Xr beadm 1
517manual page that this one is derived from.
518