xref: /freebsd/sbin/bectl/bectl.8 (revision 328110da2661a8841f12000b99fea27ceacdd5b2)
1.\"
2.\" Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd June 13, 2025
7.Dt BECTL 8
8.Os
9.Sh NAME
10.Nm bectl
11.Nd manage ZFS boot environments
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
83utility manages bootable ZFS clones called boot environments.
84Boot envionments allow system changes to be tested safely,
85as they are selectable directly from the boot
86.Xr loader 8 .
87This utility can
88.Cm create ,
89.Cm list ,
90.Cm mount ,
91or
92.Cm jail
93boot environments.
94Once the changes have been tested, the boot environment can be
95.Cm unmount Ns ed ,
96.Cm activate Ns d ,
97.Cm rename Ns d ,
98and
99.Cm destroy Ns ed .
100.Ss Supported Subcommands and Flags
101.Bl -tag -width indent
102.It Fl h
103Print usage information and exit.
104.It Fl r Ar beroot Sy Ar subcommand
105Specify a parent dataset for the boot environment to use for
106.Ar subcommand
107for operation on manually imported pools or unusual layouts.
108.It Xo
109.Cm activate
110.Op Fl t | Fl T
111.Ar beName
112.Xc
113Activate the given
114.Ar beName
115as the default boot filesystem.
116If the
117.Fl t
118flag is given, this takes effect only for the next boot.
119Flag
120.Fl T
121removes temporary boot once configuration.
122Without temporary configuration,
123the next boot will use zfs dataset specified in boot pool
124.Ar bootfs
125property.
126.It Xo
127.Cm check
128.Xc
129Perform a check to see if the current system can use boot environments.
130If boot environments are supported and used,
131.Nm
132will exit with a status code of 0.
133Any other status code is not currently defined and may, in the future,
134grow special meaning for different degrees of sanity check failures.
135.It Xo
136.Cm create
137.Op Fl r
138.Op Fl e Brq Ar nonActiveBe | Ar beName Ns Cm @ Ns Ar snapshot
139.Ar newBeName
140.Xc
141Create a new boot environment named
142.Ar newBeName .
143.Pp
144If the
145.Fl r
146flag is given, a recursive boot environment will be made.
147See
148.Sx Boot Environment Structures
149for a discussion on different layouts.
150.Pp
151If the
152.Fl e
153flag is specified, the new environment will be cloned from the given
154.Ar nonActiveBe
155or
156.Ar beName Ns Cm @ Ns Ar snapshot .
157Otherwise, the new environment will be created from the currently booted
158environment.
159.Pp
160If
161.Nm
162is creating from another boot environment,
163a snapshot of that boot environment will be created to clone from.
164.It Xo
165.Cm create
166.Op Fl r
167.Ar beName@snapshot
168.Xc
169Create a snapshot of the boot environment named
170.Ar beName .
171.Pp
172If the
173.Fl r
174flag is given,
175a recursive snapshot of the boot environment will be created.
176A snapshot is created for each descendant dataset
177of the boot environment.
178See
179.Sx Boot Environment Structures
180for a discussion on different layouts.
181.Pp
182No new boot environment is created with this subcommand.
183.It Xo
184.Cm destroy
185.Op Fl \&Fo
186.Ar beName Ns Op Cm @ Ns Ar snapshot
187.Xc
188Destroy the given
189.Ar beName
190boot environment or
191.Ar beName Ns Cm @ Ns Ar snapshot
192snapshot without confirmation, unlike in
193.Xr beadm 8 .
194Specifying
195.Fl F
196will automatically unmount without confirmation.
197.Pp
198By default,
199.Nm
200will warn that it is not destroying the origin of
201.Ar beName .
202The
203.Fl o
204flag may be specified to destroy the origin as well.
205.It Cm export Ar sourceBe
206Export
207.Ar sourceBe
208to
209.Xr stdout 4 .
210.Xr stdout 4
211must be piped or redirected to a file.
212.It Cm import Ar targetBe
213Import
214.Ar targetBe
215from
216.Xr stdin 4 .
217.It Xo
218.Cm jail
219.Op Fl bU
220.Oo Bro Fl o Ar key Ns Cm = Ns Ar value | Fl u Ar key Brc Oc Ns ...
221.Ar beName
222.Op Ar utility Op Ar argument ...
223.Xc
224Create a jail of the given boot environment.
225Multiple
226.Fl o
227and
228.Fl u
229arguments may be specified.
230.Fl o
231will set a jail parameter, and
232.Fl u
233will unset a jail parameter.
234.Pp
235By default, jails are created in interactive mode and
236.Pa /bin/sh
237is
238executed within the jail.
239If
240.Ar utility
241is specified, it will be executed instead of
242.Pa /bin/sh .
243The jail will be destroyed and the boot environment unmounted
244when the command finishes executing, unless the
245.Fl U
246argument is specified.
247.Pp
248The
249.Fl b
250argument enables batch mode, thereby disabling interactive mode.
251The
252.Fl U
253argument will be ignored in batch mode.
254.Pp
255The
256.Va name ,
257.Va host.hostname ,
258and
259.Va path
260must be set, the default values are specified below.
261.Pp
262All
263.Ar key Ns Cm = Ns Ar value
264pairs are interpreted as jail parameters as described in
265.Xr jail 8 .
266The following default parameters are provided:
267.Bl -column "allow.mount.devfs" ""
268.It Va allow.mount Ta Cm true
269.It Va allow.mount.devfs Ta Cm true
270.It Va enforce_statfs Ta Cm 1
271.It Va name Ta set to jail ID
272.It Va host.hostname Ta Va bootenv
273.It Va path Ta set to a path in Pa /tmp
274generated by
275.Xr libbe 3
276.El
277.Pp
278All default parameters may be overwritten.
279.It Xo
280.Cm list
281.Op Fl aDHs
282.Oo Bro Fl c Ar property | Fl C Ar property Brc Oc
283.Xc
284.Pp
285Display all boot environments.
286The
287.Em Active
288field indicates whether the boot environment is active now
289.Pq Em \&N ;
290active on reboot
291.Pq Em \&R ;
292is used on next boot once
293.Pq Em \&T ;
294or combination of
295.Pq Em \&NRT .
296.Bl -tag -width indent
297.It Fl a
298Display all datasets.
299.It Fl D
300Display the full space usage for each boot environment,
301assuming all other boot environments were destroyed.
302.It Fl H
303Used for scripting.
304Do not print headers and separate fields by a single tab instead of
305arbitrary white space.
306.It Fl s
307Display all snapshots as well.
308.It Fl c Ar property
309Sort boot environments by the given ZFS dataset property.
310The following properties are supported:
311.Pp
312.Bl -tag -width 4n -offset indent -compact
313.It name (the default)
314.It creation
315.It origin
316.It used
317.It usedbydataset
318.It usedbyrefreservation
319.It usedbysnapshots
320.El
321.Pp
322Short forms usedds, usedrefreserv and usedsnap are also supported.
323.It Fl C Ar property
324Same as the
325.Fl c
326option, but displays in descending order.
327.El
328.Pp
329The
330.Fl D
331option is ignored when either the
332.Fl s
333or
334.Fl a
335option is used.
336.It Cm mount Ar beName Op Ar mountpoint
337Mount the given boot environment.
338.Pp
339If a nonexistent
340.Ar mountpoint
341is given:
342.Nm
343will make the directory, including intermediate directories as required.
344.Pp
345If no
346.Ar mountpoint
347is given:
348.Nm
349will make a directory such as
350.Pa be_mount.c6Sf
351in
352.Pa /tmp .
353Randomness in the last four characters of the directory name
354will prevent mount point conflicts.
355Unmount of an environment, followed by mount of the same environment
356without giving a
357.Ar mountpoint ,
358will result in a different randomly-named mountpoint.
359.It Cm rename Ar origBeName newBeName
360Rename the given
361.Ar origBeName
362to the given
363.Ar newBeName .
364The boot environment will not be unmounted for this rename to occur.
365.It Cm ujail Brq Ar jailId | jailName | beName
366.It Cm unjail Brq Ar jailId | jailName | beName
367Destroy the jail created from the given boot environment.
368.It Xo
369.Cm umount
370.Op Fl f
371.Ar beName
372.Xc
373.It Xo
374.Cm unmount
375.Op Fl f
376.Ar beName
377.Xc
378Unmount the given boot environment, if it is mounted.
379Specifying
380.Fl f
381will force the unmount if busy.
382.Pp
383Unmount will not remove the mount point.
384.El
385.Ss Boot Environment Structures
386The traditional
387.Fx
388boot environment layout, as created by the Auto ZFS option to
389.Xr bsdinstall 8 ,
390is a
391.Dq shallow
392boot environment structure, where boot environment datasets
393do not have any directly subordinate datasets.
394Instead, they're organized off in
395.Pa zroot/ROOT ,
396and they rely on datasets elsewhere in the pool having
397.Dv canmount
398set to
399.Dv off .
400For instance, a simplified pool may be laid out as such:
401.Bd -literal -offset indent
402% zfs list -o name,canmount,mountpoint
403NAME			CANMOUNT	MOUNTPOINT
404zroot
405zroot/ROOT		noauto		none
406zroot/ROOT/default	noauto		none
407zroot/home		on		/home
408zroot/usr		off		/usr
409zroot/usr/src		on		/usr/src
410zroot/var		off		/var
411.Ed
412.Pp
413In that example,
414.Pa zroot/usr
415has
416.Dv canmount
417set to
418.Dv off ,
419thus files in
420.Pa /usr
421typically fall into the boot environment
422because 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,
449as indicated by their positioning 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
472Create a boot environment, named with today's date,
473containing snapshots of the root dataset and of all child datasets:
474.Pp
475.Dl bectl create -r `date +%Y%m%d`
476.Pp
477Mount a previous boot environment,
478.Ar yesterdaysbe ,
479to
480.Pa /mnt :
481.Pp
482.Dl bectl mount yesterdaysbe /mnt
483.\" To fill in with jail upgrade example when behavior is firm.
484.Sh SEE ALSO
485.Xr libbe 3 ,
486.Xr zfsprops 7 ,
487.Xr beinstall.sh 8 ,
488.Xr jail 8 ,
489.Xr loader 8 ,
490.Xr zfs 8 ,
491.Xr zpool 8
492.Sh HISTORY
493.Nm
494and
495.Xr libbe 3
496were written by
497.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in
498as a 2017 Google Summer of Code project, with
499.An Allan Jude (allanjude) Aq Mt allanjude@freebsd.org
500as mentor.
501.Pp
502.Nm
503and this manual page were derived from
504.Xr beadm 8 .
505.Sh AUTHORS
506.An Slawomir Wojciech Wojtczak (vermaden) Aq Mt vermaden@interia.pl
507is the creator and maintainer of
508.Xr beadm 8 .
509.An Bryan Drewery (bdrewery) Aq Mt bryan@shatow.net
510contributed child dataset fixes, and wrote the
511.Xr beadm 8
512manual page.
513.Pp
514Most later changes to
515.Nm ,
516and to this page, were written by
517.An Kyle Evans (kevans) Aq Mt kevans@freebsd.org .
518