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