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