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