128f16a0fSKyle Evans.\" 24d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 3b179da01SKyle Evans.\" 428f16a0fSKyle Evans.\" Copyright (c) 2017 Kyle Kneitinger 57c2cc9b2SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 628f16a0fSKyle Evans.\" 728f16a0fSKyle Evans.\" Redistribution and use in source and binary forms, with or without 828f16a0fSKyle Evans.\" modification, are permitted provided that the following conditions 928f16a0fSKyle Evans.\" are met: 1028f16a0fSKyle Evans.\" 1. Redistributions of source code must retain the above copyright 1128f16a0fSKyle Evans.\" notice, this list of conditions and the following disclaimer. 1228f16a0fSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 1328f16a0fSKyle Evans.\" notice, this list of conditions and the following disclaimer in the 1428f16a0fSKyle Evans.\" documentation and/or other materials provided with the distribution. 1528f16a0fSKyle Evans.\" 1628f16a0fSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1728f16a0fSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1828f16a0fSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1928f16a0fSKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2028f16a0fSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2128f16a0fSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2228f16a0fSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2328f16a0fSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2428f16a0fSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2528f16a0fSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2628f16a0fSKyle Evans.\" SUCH DAMAGE. 2728f16a0fSKyle Evans.\" 28*2e020c84SPat Maddox.Dd February 4, 2026 2928f16a0fSKyle Evans.Dt LIBBE 3 3028f16a0fSKyle Evans.Os 3128f16a0fSKyle Evans.Sh NAME 3228f16a0fSKyle Evans.Nm libbe 3384e61219SKyle Evans.Nd library for creating, destroying and modifying ZFS boot environments 3484e61219SKyle Evans.Sh LIBRARY 357c2cc9b2SKyle Evans.Lb libbe 3628f16a0fSKyle Evans.Sh SYNOPSIS 3728f16a0fSKyle Evans.In be.h 387c2cc9b2SKyle Evans.Ft "libbe_handle_t *hdl" Ns 39cc624025SKyle Evans.Fn libbe_init "const char *be_root" 4028f16a0fSKyle Evans.Pp 417c2cc9b2SKyle Evans.Ft void 427c2cc9b2SKyle Evans.Fn libbe_close "libbe_handle_t *hdl" 4328f16a0fSKyle Evans.Pp 447c2cc9b2SKyle Evans.Ft const char * Ns 457c2cc9b2SKyle Evans.Fn be_active_name "libbe_handle_t *hdl" 467c2cc9b2SKyle Evans.Pp 477c2cc9b2SKyle Evans.Ft const char * Ns 487c2cc9b2SKyle Evans.Fn be_active_path "libbe_handle_t *hdl" 497c2cc9b2SKyle Evans.Pp 507c2cc9b2SKyle Evans.Ft const char * Ns 517c2cc9b2SKyle Evans.Fn be_nextboot_name "libbe_handle_t *hdl" 527c2cc9b2SKyle Evans.Pp 537c2cc9b2SKyle Evans.Ft const char * Ns 547c2cc9b2SKyle Evans.Fn be_nextboot_path "libbe_handle_t *hdl" 557c2cc9b2SKyle Evans.Pp 567c2cc9b2SKyle Evans.Ft const char * Ns 577c2cc9b2SKyle Evans.Fn be_root_path "libbe_handle_t *hdl" 587c2cc9b2SKyle Evans.Pp 59513bd2fcSKyle Evans.Ft int Ns 60513bd2fcSKyle Evans.Fn be_snapshot "libbe_handle_t *hdl" "const char *be_name" "const char *snap_name" "bool recursive" "char *result" 61513bd2fcSKyle Evans.Pp 62455d8009SKyle Evans.Ft bool Ns 63455d8009SKyle Evans.Fn be_is_auto_snapshot_name "libbe_handle_t *hdl" "const char *snap" 64455d8009SKyle Evans.Pp 657c2cc9b2SKyle Evans.Ft int 667c2cc9b2SKyle Evans.Fn be_create "libbe_handle_t *hdl" "const char *be_name" 677c2cc9b2SKyle Evans.Pp 687c2cc9b2SKyle Evans.Ft int 69fa30d9edSKyle Evans.Fn be_create_depth "libbe_handle_t *hdl" "const char *be_name" "const char *snap" "int depth" 70fa30d9edSKyle Evans.Pp 71fa30d9edSKyle Evans.Ft int 72*2e020c84SPat Maddox.Fn be_create_empty "libbe_handle_t *hdl" "const char *be_name" 73*2e020c84SPat Maddox.Pp 74*2e020c84SPat Maddox.Ft int 757c2cc9b2SKyle Evans.Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin" 767c2cc9b2SKyle Evans.Pp 777c2cc9b2SKyle Evans.Ft int 787c2cc9b2SKyle Evans.Fn be_create_from_existing_snap "libbe_handle_t *hdl" "const char *be_name" "const char *snap" 797c2cc9b2SKyle Evans.Pp 807c2cc9b2SKyle Evans.Ft int 817c2cc9b2SKyle Evans.Fn be_rename "libbe_handle_t *hdl" "const char *be_old" "const char *be_new" 827c2cc9b2SKyle Evans.Pp 837c2cc9b2SKyle Evans.Ft int 847c2cc9b2SKyle Evans.Fn be_activate "libbe_handle_t *hdl" "const char *be_name" "bool temporary" 85e307eb94SToomas Soome.Pp 86e307eb94SToomas Soome.Ft int 87e307eb94SToomas Soome.Fn be_deactivate "libbe_handle_t *hdl" "const char *be_name" "bool temporary" 88e307eb94SToomas Soome.Pp 897c2cc9b2SKyle Evans.Ft int 907c2cc9b2SKyle Evans.Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options" 917c2cc9b2SKyle Evans.Pp 927c2cc9b2SKyle Evans.Ft void 937c2cc9b2SKyle Evans.Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz" 947c2cc9b2SKyle Evans.Pp 957c2cc9b2SKyle Evans.\" TODO: Write up of mount options 967c2cc9b2SKyle Evans.\" typedef enum { 977c2cc9b2SKyle Evans.\" BE_MNT_FORCE = 1 << 0, 987c2cc9b2SKyle Evans.\" BE_MNT_DEEP = 1 << 1, 997c2cc9b2SKyle Evans.\" } be_mount_opt_t 1007c2cc9b2SKyle Evans.Ft int 1015773e924SKyle Evans.Fn be_mount "libbe_handle_t *hdl" "const char *be_name" "const char *mntpoint" "int flags" "char *result" 1027c2cc9b2SKyle Evans.Pp 1037c2cc9b2SKyle Evans.Ft int 1047c2cc9b2SKyle Evans.Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details" 1057c2cc9b2SKyle Evans.Pp 1067c2cc9b2SKyle Evans.Ft int 1075773e924SKyle Evans.Fn be_unmount "libbe_handle_t *hdl" "const char *be_name" "int flags" 1087c2cc9b2SKyle Evans.Pp 1097c2cc9b2SKyle Evans.Ft int 1107c2cc9b2SKyle Evans.Fn libbe_errno "libbe_handle_t *hdl" 1117c2cc9b2SKyle Evans.Pp 1127c2cc9b2SKyle Evans.Ft const char * Ns 1137c2cc9b2SKyle Evans.Fn libbe_error_description "libbe_handle_t *hdl" 1147c2cc9b2SKyle Evans.Pp 1157c2cc9b2SKyle Evans.Ft void 1167c2cc9b2SKyle Evans.Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint" 1177c2cc9b2SKyle Evans.Pp 1187c2cc9b2SKyle Evans.Ft int 1197c2cc9b2SKyle Evans.Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result" 1207c2cc9b2SKyle Evans.Pp 1217c2cc9b2SKyle Evans.Ft int 1227c2cc9b2SKyle Evans.Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name" 1237c2cc9b2SKyle Evans.Pp 1247c2cc9b2SKyle Evans.Ft int 1257c2cc9b2SKyle Evans.Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap" 1267c2cc9b2SKyle Evans.Pp 127162ec569SKyle Evans.Ft int 1285773e924SKyle Evans.Fn be_exists "libbe_handle_t *hdl" "const char *be_name" 1297c2cc9b2SKyle Evans.Pp 1307c2cc9b2SKyle Evans.Ft int 1317c2cc9b2SKyle Evans.Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd" 1327c2cc9b2SKyle Evans.Pp 1337c2cc9b2SKyle Evans.Ft int 1347c2cc9b2SKyle Evans.Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd" 1357c2cc9b2SKyle Evans.Pp 1367c2cc9b2SKyle Evans.Ft int 1377c2cc9b2SKyle Evans.Fn be_prop_list_alloc "nvlist_t **prop_list" 1387c2cc9b2SKyle Evans.Pp 1397c2cc9b2SKyle Evans.Ft int 1407c2cc9b2SKyle Evans.Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list" 1417c2cc9b2SKyle Evans.Pp 1427c2cc9b2SKyle Evans.Ft int 1437c2cc9b2SKyle Evans.Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props" 1447c2cc9b2SKyle Evans.Pp 1457c2cc9b2SKyle Evans.Ft int 1467c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list" 1477c2cc9b2SKyle Evans.Pp 1487c2cc9b2SKyle Evans.Ft void 1497c2cc9b2SKyle Evans.Fn be_prop_list_free "nvlist_t *prop_list" 1502a879296SRob Norris.Pp 1512a879296SRob Norris.Ft int 1522a879296SRob Norris.Fn be_log_history "libbe_handle_t *hdl" "const char *message" 15328f16a0fSKyle Evans.Sh DESCRIPTION 15428f16a0fSKyle Evans.Nm 15528f16a0fSKyle Evansinterfaces with libzfs to provide a set of functions for various operations 156f446c948SCheng-Yuan Wuregarding ZFS boot environments, including "deep" boot environments in which 157f446c948SCheng-Yuan Wua boot environment has child datasets. 15828f16a0fSKyle Evans.Pp 15928f16a0fSKyle EvansA context structure is passed to each function, allowing for a small amount 16028f16a0fSKyle Evansof state to be retained, such as errors from previous operations. 1617c2cc9b2SKyle Evans.Nm 1627c2cc9b2SKyle Evansmay be configured to print the corresponding error message to 1637c2cc9b2SKyle Evans.Dv stderr 1647c2cc9b2SKyle Evanswhen an error is encountered with 1657c2cc9b2SKyle Evans.Fn libbe_print_on_error . 16628f16a0fSKyle Evans.Pp 1677c2cc9b2SKyle EvansAll functions returning an 1687c2cc9b2SKyle Evans.Vt int 1697c2cc9b2SKyle Evansreturn 0 on success, or a 1707c2cc9b2SKyle Evans.Nm 1717c2cc9b2SKyle Evanserrno otherwise as described in 1727c2cc9b2SKyle Evans.Sx DIAGNOSTICS . 17328f16a0fSKyle Evans.Pp 1747c2cc9b2SKyle EvansThe 1757c2cc9b2SKyle Evans.Fn libbe_init 176cc624025SKyle Evansfunction takes an optional BE root and initializes 1777c2cc9b2SKyle Evans.Nm , 1787c2cc9b2SKyle Evansreturning a 1797c2cc9b2SKyle Evans.Vt "libbe_handle_t *" 1807c2cc9b2SKyle Evanson success, or 1817c2cc9b2SKyle Evans.Dv NULL 1827c2cc9b2SKyle Evanson error. 183cc624025SKyle EvansIf a BE root is supplied, 184cc624025SKyle Evans.Nm 185cc624025SKyle Evanswill only operate out of that pool and BE root. 1867c2cc9b2SKyle EvansAn error may occur if: 187ad99fea9SDag-Erling Smørgrav.Bl -bullet 188ad99fea9SDag-Erling Smørgrav.It 189ad99fea9SDag-Erling Smørgrav.Pa /boot 190ad99fea9SDag-Erling Smørgravand 191ad99fea9SDag-Erling Smørgrav.Pa / 192ad99fea9SDag-Erling Smørgravare not on the same filesystem and device, 193ad99fea9SDag-Erling Smørgrav.It 194ad99fea9SDag-Erling Smørgravlibzfs fails to initialize, 195ad99fea9SDag-Erling Smørgrav.It 196ad99fea9SDag-Erling SmørgravThe system has not been properly booted with a ZFS boot 1977c2cc9b2SKyle Evansenvironment, 198ad99fea9SDag-Erling Smørgrav.It 199ad99fea9SDag-Erling Smørgrav.Nm 2007c2cc9b2SKyle Evansfails to open the zpool the active boot environment resides on, or 201ad99fea9SDag-Erling Smørgrav.It 202ad99fea9SDag-Erling Smørgrav.Nm 2037c2cc9b2SKyle Evansfails to locate the boot environment that is currently mounted. 2047c2cc9b2SKyle Evans.El 20528f16a0fSKyle Evans.Pp 2067c2cc9b2SKyle EvansThe 2077c2cc9b2SKyle Evans.Fn libbe_close 2087c2cc9b2SKyle Evansfunction frees all resources previously acquired in 2097c2cc9b2SKyle Evans.Fn libbe_init , 2107c2cc9b2SKyle Evansinvalidating the handle in the process. 21128f16a0fSKyle Evans.Pp 2127c2cc9b2SKyle EvansThe 2137c2cc9b2SKyle Evans.Fn be_active_name 214cc624025SKyle Evansfunction returns the name of the currently booted boot environment. 215cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe 216cc624025SKyle Evansis operating on! 21784e61219SKyle Evans.Pp 2187c2cc9b2SKyle EvansThe 2197c2cc9b2SKyle Evans.Fn be_active_path 2207c2cc9b2SKyle Evansfunction returns the full path of the currently booted boot environment. 221cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe 222cc624025SKyle Evansis operating on! 22384e61219SKyle Evans.Pp 2247c2cc9b2SKyle EvansThe 2257c2cc9b2SKyle Evans.Fn be_nextboot_name 2267c2cc9b2SKyle Evansfunction returns the name of the boot environment that will be active on reboot. 22728f16a0fSKyle Evans.Pp 2287c2cc9b2SKyle EvansThe 2297c2cc9b2SKyle Evans.Fn be_nextboot_path 2307c2cc9b2SKyle Evansfunction returns the full path of the boot environment that will be 2317c2cc9b2SKyle Evansactive on reboot. 23228f16a0fSKyle Evans.Pp 2337c2cc9b2SKyle EvansThe 2347c2cc9b2SKyle Evans.Fn be_root_path 2357c2cc9b2SKyle Evansfunction returns the boot environment root path. 23628f16a0fSKyle Evans.Pp 2377c2cc9b2SKyle EvansThe 238513bd2fcSKyle Evans.Fn be_snapshot 239513bd2fcSKyle Evansfunction creates a snapshot of 240513bd2fcSKyle Evans.Fa be_name 241513bd2fcSKyle Evansnamed 242513bd2fcSKyle Evans.Fa snap_name . 243ad99fea9SDag-Erling SmørgravA value of 244513bd2fcSKyle Evans.Dv NULL 245513bd2fcSKyle Evansmay be used, indicating that 246513bd2fcSKyle Evans.Fn be_snaphot 247513bd2fcSKyle Evansshould derive the snapshot name from the current date and time. 248513bd2fcSKyle EvansIf 249513bd2fcSKyle Evans.Fa recursive 250513bd2fcSKyle Evansis set, then 251513bd2fcSKyle Evans.Fn be_snapshot 252513bd2fcSKyle Evanswill recursively snapshot the dataset. 253513bd2fcSKyle EvansIf 254513bd2fcSKyle Evans.Fa result 255513bd2fcSKyle Evansis not 256513bd2fcSKyle Evans.Dv NULL , 257513bd2fcSKyle Evansthen it will be populated with the final 258513bd2fcSKyle Evans.Dq Fa be_name Ns @ Ns Fa snap_name . 259513bd2fcSKyle Evans.Pp 260513bd2fcSKyle EvansThe 261455d8009SKyle Evans.Fn be_is_auto_snapshot_name 262455d8009SKyle Evansfunction is used to determine if the given snapshot name matches the format that 263455d8009SKyle Evansthe 264455d8009SKyle Evans.Fn be_snapshot 265455d8009SKyle Evansfunction will use by default if it is not given a snapshot name to use. 266455d8009SKyle EvansIt returns 267455d8009SKyle Evans.Dv true 268455d8009SKyle Evansif the name matches the format, and 269455d8009SKyle Evans.Dv false 270455d8009SKyle Evansif it does not. 271455d8009SKyle Evans.Pp 272455d8009SKyle EvansThe 2737c2cc9b2SKyle Evans.Fn be_create 2747c2cc9b2SKyle Evansfunction creates a boot environment with the given name. 275fa30d9edSKyle EvansThe new boot environment will be created from a recursive snapshot of the 276fa30d9edSKyle Evanscurrently booted boot environment. 277fa30d9edSKyle Evans.Pp 278fa30d9edSKyle EvansThe 279fa30d9edSKyle Evans.Fn be_create_depth 280fa30d9edSKyle Evansfunction creates a boot environment with the given name from an existing 281fa30d9edSKyle Evanssnapshot. 282fa30d9edSKyle EvansThe depth parameter specifies the depth of recursion that will be cloned from 283fa30d9edSKyle Evansthe existing snapshot. 284fa30d9edSKyle EvansA depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot 285fa30d9edSKyle Evansenvironment). 28628f16a0fSKyle Evans.Pp 2877c2cc9b2SKyle EvansThe 288*2e020c84SPat Maddox.Fn be_create_empty 289*2e020c84SPat Maddoxfunction creates an empty boot environment with the given name. 290*2e020c84SPat Maddox.Pp 291*2e020c84SPat MaddoxThe 2927c2cc9b2SKyle Evans.Fn be_create_from_existing 2937c2cc9b2SKyle Evansfunction creates a boot environment with the given name from the name of an 2947c2cc9b2SKyle Evansexisting boot environment. 295fa30d9edSKyle EvansA recursive snapshot will be made of the origin boot environment, and the new 296fa30d9edSKyle Evansboot environment will be created from that. 29728f16a0fSKyle Evans.Pp 2987c2cc9b2SKyle EvansThe 2997c2cc9b2SKyle Evans.Fn be_create_from_existing_snap 300fa30d9edSKyle Evansfunction creates a recursive boot environment with the given name from an 301fa30d9edSKyle Evansexisting snapshot. 30228f16a0fSKyle Evans.Pp 3037c2cc9b2SKyle EvansThe 3047c2cc9b2SKyle Evans.Fn be_rename 3058369ba42SKyle Evansfunction renames a boot environment without unmounting it, as if renamed with 3068369ba42SKyle Evansthe 3078369ba42SKyle Evans.Fl u 3088369ba42SKyle Evansargument were passed to 3098369ba42SKyle Evans.Nm zfs 3108369ba42SKyle Evans.Cm rename 3119b1662e6SKyle Evans.Pp 3127c2cc9b2SKyle EvansThe 3137c2cc9b2SKyle Evans.Fn be_activate 3147c2cc9b2SKyle Evansfunction makes a boot environment active on the next boot. 3157c2cc9b2SKyle EvansIf the 3167c2cc9b2SKyle Evans.Fa temporary 3177c2cc9b2SKyle Evansflag is set, then it will be active for the next boot only, as done by 3187c2cc9b2SKyle Evans.Xr zfsbootcfg 8 . 319e307eb94SToomas Soome.Pp 320e307eb94SToomas SoomeThe 321e307eb94SToomas Soome.Fn be_deactivate 322e307eb94SToomas Soomefunction deactivates a boot environment. 323e307eb94SToomas SoomeIf the 324e307eb94SToomas Soome.Fa temporary 325e307eb94SToomas Soomeflag is set, then it will cause removal of boot once configuration, set by 326e307eb94SToomas Soome.Fn be_activate 327e307eb94SToomas Soomefunction or by 328e307eb94SToomas Soome.Xr zfsbootcfg 8 . 329e307eb94SToomas SoomeIf the 330e307eb94SToomas Soome.Fa temporary 331e307eb94SToomas Soomeflag is not set, 332e307eb94SToomas Soome.Fn be_deactivate 333e307eb94SToomas Soomefunction will set zfs 334e307eb94SToomas Soome.Dv canmount 335e307eb94SToomas Soomeproperty to 336e307eb94SToomas Soome.Dv noauto . 33728f16a0fSKyle Evans.Pp 3387c2cc9b2SKyle EvansThe 3397c2cc9b2SKyle Evans.Fn be_destroy 3407c2cc9b2SKyle Evansfunction will recursively destroy the given boot environment. 3417c2cc9b2SKyle EvansIt will not destroy a mounted boot environment unless the 3427c2cc9b2SKyle Evans.Dv BE_DESTROY_FORCE 3437c2cc9b2SKyle Evansoption is set in 3447c2cc9b2SKyle Evans.Fa options . 345446ae812SKyle EvansIf the 346446ae812SKyle Evans.Dv BE_DESTROY_ORIGIN 347446ae812SKyle Evansoption is set in 348446ae812SKyle Evans.Fa options , 349446ae812SKyle Evansthe 350446ae812SKyle Evans.Fn be_destroy 351446ae812SKyle Evansfunction will destroy the origin snapshot to this boot environment as well. 352843e39ceSKyle Evans.Pp 3537c2cc9b2SKyle EvansThe 3547c2cc9b2SKyle Evans.Fn be_nicenum 3557c2cc9b2SKyle Evansfunction will format 3567c2cc9b2SKyle Evans.Fa name 3577c2cc9b2SKyle Evansin a traditional ZFS humanized format, similar to 3587c2cc9b2SKyle Evans.Xr humanize_number 3 . 3597c2cc9b2SKyle EvansThis function effectively proxies 3607c2cc9b2SKyle Evans.Fn zfs_nicenum 3617c2cc9b2SKyle Evansfrom libzfs. 36228f16a0fSKyle Evans.Pp 3637c2cc9b2SKyle EvansThe 3647c2cc9b2SKyle Evans.Fn be_mount 3657c2cc9b2SKyle Evansfunction will mount the given boot environment. 3667c2cc9b2SKyle EvansIf 3677c2cc9b2SKyle Evans.Fa mountpoint 3687c2cc9b2SKyle Evansis 3697c2cc9b2SKyle Evans.Dv NULL , 3707c2cc9b2SKyle Evansa mount point will be generated in 3712f11393fSKyle Evans.Ev TMPDIR 3722f11393fSKyle Evansor, if 3732f11393fSKyle Evans.Ev TMPDIR 3742f11393fSKyle Evansis not set, 3757c2cc9b2SKyle Evans.Pa /tmp 3767c2cc9b2SKyle Evansusing 3777c2cc9b2SKyle Evans.Xr mkdtemp 3 . 3787c2cc9b2SKyle EvansIf 3797c2cc9b2SKyle Evans.Fa result 3807c2cc9b2SKyle Evansis not 3817c2cc9b2SKyle Evans.Dv NULL , 382a8e44f4dSKyle Evansit should be large enough to accommodate 383a8e44f4dSKyle Evans.Dv BE_MAXPATHLEN 384a8e44f4dSKyle Evansincluding the null terminator. 3857c2cc9b2SKyle Evansthe final mount point will be copied into it. 3867c2cc9b2SKyle EvansSetting the 3877c2cc9b2SKyle Evans.Dv BE_MNT_FORCE 3887c2cc9b2SKyle Evansflag will pass 3897c2cc9b2SKyle Evans.Dv MNT_FORCE 3907c2cc9b2SKyle Evansto the underlying 3917c2cc9b2SKyle Evans.Xr mount 2 3927c2cc9b2SKyle Evanscall. 39328f16a0fSKyle Evans.Pp 3947c2cc9b2SKyle EvansThe 3957c2cc9b2SKyle Evans.Fn be_mounted_at 3967c2cc9b2SKyle Evansfunction will check if there is a boot environment mounted at the given 3977c2cc9b2SKyle Evans.Fa path . 3987c2cc9b2SKyle EvansIf 3997c2cc9b2SKyle Evans.Fa details 4007c2cc9b2SKyle Evansis not 4017c2cc9b2SKyle Evans.Dv NULL , 4027c2cc9b2SKyle Evansit will be populated with a list of the mounted dataset's properties. 4037c2cc9b2SKyle EvansThis list of properties matches the properties collected by 4047c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 40528f16a0fSKyle Evans.Pp 4067c2cc9b2SKyle EvansThe 4077c2cc9b2SKyle Evans.Fn be_unmount 4087c2cc9b2SKyle Evansfunction will unmount the given boot environment. 409d6fbae08SKyle EvansIf the mount point looks like it was created by 410d6fbae08SKyle Evans.Fn be_mount , 411d6fbae08SKyle Evansthen 412d6fbae08SKyle Evans.Fn be_unmount 413d6fbae08SKyle Evanswill attempt to 414d6fbae08SKyle Evans.Xr rmdir 2 415d6fbae08SKyle Evansthe mountpoint after a successful unmount. 4167c2cc9b2SKyle EvansSetting the 4177c2cc9b2SKyle Evans.Dv BE_MNT_FORCE 4187c2cc9b2SKyle Evansflag will pass 4197c2cc9b2SKyle Evans.Dv MNT_FORCE 4207c2cc9b2SKyle Evansto the underlying 4217c2cc9b2SKyle Evans.Xr mount 2 4227c2cc9b2SKyle Evanscall. 42328f16a0fSKyle Evans.Pp 4247c2cc9b2SKyle EvansThe 4257c2cc9b2SKyle Evans.Fn libbe_errno 4267c2cc9b2SKyle Evansfunction returns the 4277c2cc9b2SKyle Evans.Nm 4287c2cc9b2SKyle Evanserrno. 42928f16a0fSKyle Evans.Pp 4307c2cc9b2SKyle EvansThe 4317c2cc9b2SKyle Evans.Fn libbe_error_description 4327c2cc9b2SKyle Evansfunction returns a string description of the currently set 4337c2cc9b2SKyle Evans.Nm 4347c2cc9b2SKyle Evanserrno. 43528f16a0fSKyle Evans.Pp 4367c2cc9b2SKyle EvansThe 4377c2cc9b2SKyle Evans.Fn libbe_print_on_error 4387c2cc9b2SKyle Evansfunction will change whether or not 4397c2cc9b2SKyle Evans.Nm 4407c2cc9b2SKyle Evansprints the description of any encountered error to 4417c2cc9b2SKyle Evans.Dv stderr , 4427c2cc9b2SKyle Evansbased on 4437c2cc9b2SKyle Evans.Fa doprint . 44428f16a0fSKyle Evans.Pp 4457c2cc9b2SKyle EvansThe 4467c2cc9b2SKyle Evans.Fn be_root_concat 4477c2cc9b2SKyle Evansfunction will concatenate the boot environment root and the given boot 4487c2cc9b2SKyle Evansenvironment name into 4497c2cc9b2SKyle Evans.Fa result . 45028f16a0fSKyle Evans.Pp 4517c2cc9b2SKyle EvansThe 4527c2cc9b2SKyle Evans.Fn be_validate_name 4535b7803a9SKyle Evansfunction will validate the given boot environment name for both length 4545b7803a9SKyle Evansrestrictions as well as valid character restrictions. 4555b7803a9SKyle EvansThis function does not set the internal library error state. 45628f16a0fSKyle Evans.Pp 4577c2cc9b2SKyle EvansThe 4587c2cc9b2SKyle Evans.Fn be_validate_snap 4597c2cc9b2SKyle Evansfunction will validate the given snapshot name. 4607c2cc9b2SKyle EvansThe snapshot must have a valid name, exist, and have a mountpoint of 4617c2cc9b2SKyle Evans.Pa / . 4627c2cc9b2SKyle EvansThis function does not set the internal library error state. 46328f16a0fSKyle Evans.Pp 4647c2cc9b2SKyle EvansThe 4657c2cc9b2SKyle Evans.Fn be_exists 4667c2cc9b2SKyle Evansfunction will check whether the given boot environment exists and has a 4677c2cc9b2SKyle Evansmountpoint of 4687c2cc9b2SKyle Evans.Pa / . 469162ec569SKyle EvansThis function does not set the internal library error state, but will return 470162ec569SKyle Evansthe appropriate error. 471734e362fSKyle Evans.Pp 4727c2cc9b2SKyle EvansThe 4737c2cc9b2SKyle Evans.Fn be_export 4747c2cc9b2SKyle Evansfunction will export the given boot environment to the file specified by 4757c2cc9b2SKyle Evans.Fa fd . 4767c2cc9b2SKyle EvansA snapshot will be created of the boot environment prior to export. 477734e362fSKyle Evans.Pp 4787c2cc9b2SKyle EvansThe 4797c2cc9b2SKyle Evans.Fn be_import 4807c2cc9b2SKyle Evansfunction will import the boot environment in the file specified by 4817c2cc9b2SKyle Evans.Fa fd , 4827c2cc9b2SKyle Evansand give it the name 4837c2cc9b2SKyle Evans.Fa be_name . 4844146029bSKyle Evans.Pp 4857c2cc9b2SKyle EvansThe 4867c2cc9b2SKyle Evans.Fn be_prop_list_alloc 4877c2cc9b2SKyle Evansfunction allocates a property list suitable for passing to 4887c2cc9b2SKyle Evans.Fn be_get_bootenv_props , 4897c2cc9b2SKyle Evans.Fn be_get_dataset_props , 4907c2cc9b2SKyle Evansor 4917c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots . 4927c2cc9b2SKyle EvansIt should be freed later by 4937c2cc9b2SKyle Evans.Fa be_prop_list_free . 49496c5db58SKyle Evans.Pp 4957c2cc9b2SKyle EvansThe 4967c2cc9b2SKyle Evans.Fn be_get_bootenv_props 4977c2cc9b2SKyle Evansfunction will populate 4987c2cc9b2SKyle Evans.Fa be_list 4997c2cc9b2SKyle Evanswith 5007c2cc9b2SKyle Evans.Vt nvpair_t 5017c2cc9b2SKyle Evansof boot environment names paired with an 5027c2cc9b2SKyle Evans.Vt nvlist_t 5037c2cc9b2SKyle Evansof their properties. 5047c2cc9b2SKyle EvansThe following properties are currently collected as appropriate: 5057c2cc9b2SKyle Evans.Bl -column "Returned name" 5067c2cc9b2SKyle Evans.It Sy Returned name Ta Sy Description 5077c2cc9b2SKyle Evans.It dataset Ta - 5087c2cc9b2SKyle Evans.It name Ta Boot environment name 5097c2cc9b2SKyle Evans.It mounted Ta Current mount point 5107c2cc9b2SKyle Evans.It mountpoint Ta Do mountpoint Dc property 5117c2cc9b2SKyle Evans.It origin Ta Do origin Dc property 5127c2cc9b2SKyle Evans.It creation Ta Do creation Dc property 5137c2cc9b2SKyle Evans.It active Ta Currently booted environment 5147c2cc9b2SKyle Evans.It used Ta Literal Do used Dc property 5157c2cc9b2SKyle Evans.It usedds Ta Literal Do usedds Dc property 5167c2cc9b2SKyle Evans.It usedsnap Ta Literal Do usedrefreserv Dc property 5177c2cc9b2SKyle Evans.It referenced Ta Literal Do referenced Dc property 5187c2cc9b2SKyle Evans.It nextboot Ta Active on next boot 5197c2cc9b2SKyle Evans.El 5207c2cc9b2SKyle Evans.Pp 5217c2cc9b2SKyle EvansOnly the 5227c2cc9b2SKyle Evans.Dq dataset , 5237c2cc9b2SKyle Evans.Dq name , 5247c2cc9b2SKyle Evans.Dq active , 5257c2cc9b2SKyle Evansand 5267c2cc9b2SKyle Evans.Dq nextboot 5277c2cc9b2SKyle Evansreturned values will always be present. 5287c2cc9b2SKyle EvansAll other properties may be omitted if not available. 5297c2cc9b2SKyle Evans.Pp 5307c2cc9b2SKyle EvansThe 5317c2cc9b2SKyle Evans.Fn be_get_dataset_props 5327c2cc9b2SKyle Evansfunction will get properties of the specified dataset. 5337c2cc9b2SKyle Evans.Fa props 5347c2cc9b2SKyle Evansis populated directly with a list of the properties as returned by 5357c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 5367c2cc9b2SKyle Evans.Pp 5377c2cc9b2SKyle EvansThe 5387c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots 5397c2cc9b2SKyle Evansfunction will retrieve all snapshots of the given dataset. 5407c2cc9b2SKyle Evans.Fa snap_list 5417c2cc9b2SKyle Evanswill be populated with a list of 5427c2cc9b2SKyle Evans.Vt nvpair_t 5437c2cc9b2SKyle Evansexactly as specified by 5447c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 5457c2cc9b2SKyle Evans.Pp 5467c2cc9b2SKyle EvansThe 5477c2cc9b2SKyle Evans.Fn be_prop_list_free 5487c2cc9b2SKyle Evansfunction will free the property list. 5492a879296SRob Norris.Pp 5502a879296SRob NorrisThe 5512a879296SRob Norris.Fn be_log_history 5522a879296SRob Norrisfunction will log the given 5532a879296SRob Norris.Fa message 5542a879296SRob Norristo the zpool history, which can be later retrieved using the 5552a879296SRob Norris.Xr zpool-history 8 5562a879296SRob Norriscommand. 55728f16a0fSKyle Evans.Sh DIAGNOSTICS 558cc58f749SMateusz PiotrowskiUpon error, one of the following values will be returned: 559ad99fea9SDag-Erling Smørgrav.Bl -bullet -offset indent -compact 560cc58f749SMateusz Piotrowski.It 561cc58f749SMateusz PiotrowskiBE_ERR_SUCCESS 562cc58f749SMateusz Piotrowski.It 563cc58f749SMateusz PiotrowskiBE_ERR_INVALIDNAME 564cc58f749SMateusz Piotrowski.It 565cc58f749SMateusz PiotrowskiBE_ERR_EXISTS 566cc58f749SMateusz Piotrowski.It 567cc58f749SMateusz PiotrowskiBE_ERR_NOENT 568cc58f749SMateusz Piotrowski.It 569cc58f749SMateusz PiotrowskiBE_ERR_PERMS 570cc58f749SMateusz Piotrowski.It 571cc58f749SMateusz PiotrowskiBE_ERR_DESTROYACT 572cc58f749SMateusz Piotrowski.It 573cc58f749SMateusz PiotrowskiBE_ERR_DESTROYMNT 574cc58f749SMateusz Piotrowski.It 575cc58f749SMateusz PiotrowskiBE_ERR_BADPATH 576cc58f749SMateusz Piotrowski.It 577cc58f749SMateusz PiotrowskiBE_ERR_PATHBUSY 578cc58f749SMateusz Piotrowski.It 579cc58f749SMateusz PiotrowskiBE_ERR_PATHLEN 580cc58f749SMateusz Piotrowski.It 581cc58f749SMateusz PiotrowskiBE_ERR_BADMOUNT 582cc58f749SMateusz Piotrowski.It 583cc58f749SMateusz PiotrowskiBE_ERR_NOORIGIN 584cc58f749SMateusz Piotrowski.It 585cc58f749SMateusz PiotrowskiBE_ERR_MOUNTED 586cc58f749SMateusz Piotrowski.It 587cc58f749SMateusz PiotrowskiBE_ERR_NOMOUNT 588cc58f749SMateusz Piotrowski.It 589cc58f749SMateusz PiotrowskiBE_ERR_ZFSOPEN 590cc58f749SMateusz Piotrowski.It 591cc58f749SMateusz PiotrowskiBE_ERR_ZFSCLONE 592cc58f749SMateusz Piotrowski.It 593cc58f749SMateusz PiotrowskiBE_ERR_IO 594cc58f749SMateusz Piotrowski.It 595cc58f749SMateusz PiotrowskiBE_ERR_NOPOOL 596cc58f749SMateusz Piotrowski.It 597cc58f749SMateusz PiotrowskiBE_ERR_NOMEM 598cc58f749SMateusz Piotrowski.It 59928f16a0fSKyle EvansBE_ERR_UNKNOWN 600be7dd423SKyle Evans.It 601be7dd423SKyle EvansBE_ERR_INVORIGIN 602cc58f749SMateusz Piotrowski.El 60328f16a0fSKyle Evans.Sh SEE ALSO 6042a879296SRob Norris.Xr bectl 8 , 6052a879296SRob Norris.Xr zpool-history 8 60628f16a0fSKyle Evans.Sh HISTORY 607763f5da9SGraham Perrin.Xr bectl 8 60804610d66SGraham Perrinand 609763f5da9SGraham Perrin.Nm 61004610d66SGraham Perrinwere written by 61104610d66SGraham Perrin.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in 61204610d66SGraham Perrinas a 2017 Google Summer of Code project, with 61304610d66SGraham Perrin.An Allan Jude (allanjude) Aq Mt allanjude@freebsd.org 61404610d66SGraham Perrinas mentor. 61504610d66SGraham Perrin.Sh AUTHORS 61604610d66SGraham PerrinKyle Kneitinger, mentored as above. 61704610d66SGraham Perrin.Pp 61804610d66SGraham PerrinPost-GSoC changes were written by 61904610d66SGraham Perrin.An Kyle Evans (kevans) Aq Mt kevans@freebsd.org . 620