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