xref: /freebsd/sbin/bectl/bectl.8 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
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 June 28, 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.Pp
118.Ss Supported Subcommands and Flags
119.Bl -tag -width activate
120.It Xo
121.Fl h |
122.Fl \&?
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.Pp
400.Ss Boot Environment Structures
401The traditional
402.Fx
403boot environment layout, as created by the Auto ZFS option to
404.Xr bsdinstall 8 ,
405is a
406.Dq shallow
407boot environment structure, where boot environment datasets do not have any
408directly subordinate datasets.
409Instead, they're organized off in
410.Pa zroot/ROOT ,
411and they rely on datasets elsewhere in the pool having
412.Dv canmount
413set to
414.Dv off .
415For instance, a simplified pool may be laid out as such:
416.Bd -literal -offset indent
417% zfs list -o name,canmount,mountpoint
418NAME			CANMOUNT	MOUNTPOINT
419zroot
420zroot/ROOT		noauto		none
421zroot/ROOT/default	noauto		none
422zroot/home		on		/home
423zroot/usr		off		/usr
424zroot/usr/src		on		/usr/src
425zroot/var		off		/var
426.Ed
427.Pp
428In that example,
429.Pa zroot/usr
430has
431.Dv canmount
432set to
433.Dv off ,
434thus files in
435.Pa /usr
436typically fall into the boot environment because this dataset is not mounted.
437.Pa zroot/usr/src
438is mounted, thus files in
439.Pa /usr/src
440are not in the boot environment.
441.Pp
442The other style of boot environments in use, frequently called
443.Dq deep boot environments ,
444organizes some or all of the boot environment as subordinate to the boot
445environment dataset.
446For example:
447.Bd -literal -offset indent
448% zfs list -o name,canmount,mountpoint
449NAME				CANMOUNT	MOUNTPOINT
450zroot
451zroot/ROOT			noauto		none
452zroot/ROOT/default		noauto		none
453zroot/ROOT/default/usr		noauto		/usr
454zroot/ROOT/default/usr/local	noauto		/usr/local
455zroot/var			on		/var
456.Ed
457.Pp
458Note that the subordinate datasets now have
459.Dv canmount
460set to
461.Dv noauto .
462These are more obviously a part of the boot environment, as indicated by their
463positioning in the layout.
464These subordinate datasets will be mounted by the
465.Dv zfsbe
466.Xr rc 8
467script at boot time.
468In this example,
469.Pa /var
470is excluded from the boot environment.
471.Pp
472.Nm
473subcommands that have their own
474.Fl r
475operate on this second,
476.Dq deep
477style of boot environment, when the
478.Fl r
479flag is set.
480A future version of
481.Nm
482may default to handling both styles and deprecate the various
483.Fl r
484flags.
485\" .Sh EXAMPLES
486\" .Bl -bullet
487\" .It
488\" To fill in with jail upgrade example when behavior is firm.
489\" .El
490.Sh SEE ALSO
491.Xr libbe 3 ,
492.Xr zfsprops 7 ,
493.Xr beinstall.sh 8 ,
494.Xr jail 8 ,
495.Xr zfs 8 ,
496.Xr zpool 8
497.Sh HISTORY
498.Nm
499is based on
500.Xr beadm 1
501and was implemented as a project for the 2017 Summer of Code, along with
502.Xr libbe 3 .
503.Sh AUTHORS
504.Nm
505was written by
506.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in .
507.Pp
508.Xr beadm 1
509was written and is maintained by
510.An Slawomir Wojciech Wojtczak (vermaden) Aq Mt vermaden@interia.pl .
511.Pp
512.An Bryan Drewery (bdrewery) Aq Mt bryan@shatow.net
513wrote the original
514.Xr beadm 1
515manual page that this one is derived from.
516