128f16a0fSKyle Evans.\" 2b179da01SKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3b179da01SKyle Evans.\" 428f16a0fSKyle Evans.\" Copyright (c) 2017 Kyle Kneitinger 528f16a0fSKyle Evans.\" All rights reserved. 67c2cc9b2SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 728f16a0fSKyle Evans.\" 828f16a0fSKyle Evans.\" Redistribution and use in source and binary forms, with or without 928f16a0fSKyle Evans.\" modification, are permitted provided that the following conditions 1028f16a0fSKyle Evans.\" are met: 1128f16a0fSKyle Evans.\" 1. Redistributions of source code must retain the above copyright 1228f16a0fSKyle Evans.\" notice, this list of conditions and the following disclaimer. 1328f16a0fSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 1428f16a0fSKyle Evans.\" notice, this list of conditions and the following disclaimer in the 1528f16a0fSKyle Evans.\" documentation and/or other materials provided with the distribution. 1628f16a0fSKyle Evans.\" 1728f16a0fSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1828f16a0fSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1928f16a0fSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2028f16a0fSKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2128f16a0fSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2228f16a0fSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2328f16a0fSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2428f16a0fSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2528f16a0fSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2628f16a0fSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2728f16a0fSKyle Evans.\" SUCH DAMAGE. 2828f16a0fSKyle Evans.\" 2928f16a0fSKyle Evans.\" $FreeBSD$ 3028f16a0fSKyle Evans.\" 31*be7dd423SKyle Evans.Dd February 12, 2019 3228f16a0fSKyle Evans.Dt LIBBE 3 3328f16a0fSKyle Evans.Os 3428f16a0fSKyle Evans.Sh NAME 3528f16a0fSKyle Evans.Nm libbe 3684e61219SKyle Evans.Nd library for creating, destroying and modifying ZFS boot environments 3784e61219SKyle Evans.Sh LIBRARY 387c2cc9b2SKyle Evans.Lb libbe 3928f16a0fSKyle Evans.Sh SYNOPSIS 4028f16a0fSKyle Evans.In be.h 417c2cc9b2SKyle Evans.Ft "libbe_handle_t *hdl" Ns 42cc624025SKyle Evans.Fn libbe_init "const char *be_root" 4328f16a0fSKyle Evans.Pp 447c2cc9b2SKyle Evans.Ft void 457c2cc9b2SKyle Evans.Fn libbe_close "libbe_handle_t *hdl" 4628f16a0fSKyle Evans.Pp 477c2cc9b2SKyle Evans.Ft const char * Ns 487c2cc9b2SKyle Evans.Fn be_active_name "libbe_handle_t *hdl" 497c2cc9b2SKyle Evans.Pp 507c2cc9b2SKyle Evans.Ft const char * Ns 517c2cc9b2SKyle Evans.Fn be_active_path "libbe_handle_t *hdl" 527c2cc9b2SKyle Evans.Pp 537c2cc9b2SKyle Evans.Ft const char * Ns 547c2cc9b2SKyle Evans.Fn be_nextboot_name "libbe_handle_t *hdl" 557c2cc9b2SKyle Evans.Pp 567c2cc9b2SKyle Evans.Ft const char * Ns 577c2cc9b2SKyle Evans.Fn be_nextboot_path "libbe_handle_t *hdl" 587c2cc9b2SKyle Evans.Pp 597c2cc9b2SKyle Evans.Ft const char * Ns 607c2cc9b2SKyle Evans.Fn be_root_path "libbe_handle_t *hdl" 617c2cc9b2SKyle Evans.Pp 627c2cc9b2SKyle Evans.Ft int 637c2cc9b2SKyle Evans.Fn be_create "libbe_handle_t *hdl" "const char *be_name" 647c2cc9b2SKyle Evans.Pp 657c2cc9b2SKyle Evans.Ft int 667c2cc9b2SKyle Evans.Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin" 677c2cc9b2SKyle Evans.Pp 687c2cc9b2SKyle Evans.Ft int 697c2cc9b2SKyle Evans.Fn be_create_from_existing_snap "libbe_handle_t *hdl" "const char *be_name" "const char *snap" 707c2cc9b2SKyle Evans.Pp 717c2cc9b2SKyle Evans.Ft int 727c2cc9b2SKyle Evans.Fn be_rename "libbe_handle_t *hdl" "const char *be_old" "const char *be_new" 737c2cc9b2SKyle Evans.Pp 747c2cc9b2SKyle Evans.Ft int 757c2cc9b2SKyle Evans.Fn be_activate "libbe_handle_t *hdl" "const char *be_name" "bool temporary" 767c2cc9b2SKyle Evans.Ft int 777c2cc9b2SKyle Evans.Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options" 787c2cc9b2SKyle Evans.Pp 797c2cc9b2SKyle Evans.Ft void 807c2cc9b2SKyle Evans.Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz" 817c2cc9b2SKyle Evans.Pp 827c2cc9b2SKyle Evans.\" TODO: Write up of mount options 837c2cc9b2SKyle Evans.\" typedef enum { 847c2cc9b2SKyle Evans.\" BE_MNT_FORCE = 1 << 0, 857c2cc9b2SKyle Evans.\" BE_MNT_DEEP = 1 << 1, 867c2cc9b2SKyle Evans.\" } be_mount_opt_t 877c2cc9b2SKyle Evans.Ft int 887c2cc9b2SKyle Evans.Fn be_mount "libbe_handle_t *hdl" "char *be_name" "char *mntpoint" "int flags" "char *result" 897c2cc9b2SKyle Evans.Pp 907c2cc9b2SKyle Evans.Ft int 917c2cc9b2SKyle Evans.Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details" 927c2cc9b2SKyle Evans.Pp 937c2cc9b2SKyle Evans.Ft int 947c2cc9b2SKyle Evans.Fn be_unmount "libbe_handle_t *hdl" "char *be_name" "int flags" 957c2cc9b2SKyle Evans.Pp 967c2cc9b2SKyle Evans.Ft int 977c2cc9b2SKyle Evans.Fn libbe_errno "libbe_handle_t *hdl" 987c2cc9b2SKyle Evans.Pp 997c2cc9b2SKyle Evans.Ft const char * Ns 1007c2cc9b2SKyle Evans.Fn libbe_error_description "libbe_handle_t *hdl" 1017c2cc9b2SKyle Evans.Pp 1027c2cc9b2SKyle Evans.Ft void 1037c2cc9b2SKyle Evans.Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint" 1047c2cc9b2SKyle Evans.Pp 1057c2cc9b2SKyle Evans.Ft int 1067c2cc9b2SKyle Evans.Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result" 1077c2cc9b2SKyle Evans.Pp 1087c2cc9b2SKyle Evans.Ft int 1097c2cc9b2SKyle Evans.Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name" 1107c2cc9b2SKyle Evans.Pp 1117c2cc9b2SKyle Evans.Ft int 1127c2cc9b2SKyle Evans.Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap" 1137c2cc9b2SKyle Evans.Pp 114162ec569SKyle Evans.Ft int 1157c2cc9b2SKyle Evans.Fn be_exists "libbe_handle_t *hdl" "char *be_name" 1167c2cc9b2SKyle Evans.Pp 1177c2cc9b2SKyle Evans.Ft int 1187c2cc9b2SKyle Evans.Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd" 1197c2cc9b2SKyle Evans.Pp 1207c2cc9b2SKyle Evans.Ft int 1217c2cc9b2SKyle Evans.Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd" 1227c2cc9b2SKyle Evans.Pp 1237c2cc9b2SKyle Evans.Ft int 1247c2cc9b2SKyle Evans.Fn be_prop_list_alloc "nvlist_t **prop_list" 1257c2cc9b2SKyle Evans.Pp 1267c2cc9b2SKyle Evans.Ft int 1277c2cc9b2SKyle Evans.Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list" 1287c2cc9b2SKyle Evans.Pp 1297c2cc9b2SKyle Evans.Ft int 1307c2cc9b2SKyle Evans.Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props" 1317c2cc9b2SKyle Evans.Pp 1327c2cc9b2SKyle Evans.Ft int 1337c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list" 1347c2cc9b2SKyle Evans.Pp 1357c2cc9b2SKyle Evans.Ft void 1367c2cc9b2SKyle Evans.Fn be_prop_list_free "nvlist_t *prop_list" 13728f16a0fSKyle Evans.Sh DESCRIPTION 13828f16a0fSKyle Evans.Nm 13928f16a0fSKyle Evansinterfaces with libzfs to provide a set of functions for various operations 14028f16a0fSKyle Evansregarding ZFS boot environments including "deep" boot environments in which 14128f16a0fSKyle Evansa boot environments has child datasets. 14228f16a0fSKyle Evans.Pp 14328f16a0fSKyle EvansA context structure is passed to each function, allowing for a small amount 14428f16a0fSKyle Evansof state to be retained, such as errors from previous operations. 1457c2cc9b2SKyle Evans.Nm 1467c2cc9b2SKyle Evansmay be configured to print the corresponding error message to 1477c2cc9b2SKyle Evans.Dv stderr 1487c2cc9b2SKyle Evanswhen an error is encountered with 1497c2cc9b2SKyle Evans.Fn libbe_print_on_error . 15028f16a0fSKyle Evans.Pp 1517c2cc9b2SKyle EvansAll functions returning an 1527c2cc9b2SKyle Evans.Vt int 1537c2cc9b2SKyle Evansreturn 0 on success, or a 1547c2cc9b2SKyle Evans.Nm 1557c2cc9b2SKyle Evanserrno otherwise as described in 1567c2cc9b2SKyle Evans.Sx DIAGNOSTICS . 15728f16a0fSKyle Evans.Pp 1587c2cc9b2SKyle EvansThe 1597c2cc9b2SKyle Evans.Fn libbe_init 160cc624025SKyle Evansfunction takes an optional BE root and initializes 1617c2cc9b2SKyle Evans.Nm , 1627c2cc9b2SKyle Evansreturning a 1637c2cc9b2SKyle Evans.Vt "libbe_handle_t *" 1647c2cc9b2SKyle Evanson success, or 1657c2cc9b2SKyle Evans.Dv NULL 1667c2cc9b2SKyle Evanson error. 167cc624025SKyle EvansIf a BE root is supplied, 168cc624025SKyle Evans.Nm 169cc624025SKyle Evanswill only operate out of that pool and BE root. 1707c2cc9b2SKyle EvansAn error may occur if: 1717c2cc9b2SKyle Evans.Bl -column 1727c2cc9b2SKyle Evans.It /boot and / are not on the same filesystem and device, 1737c2cc9b2SKyle Evans.It libzfs fails to initialize, 1747c2cc9b2SKyle Evans.It The system has not been properly booted with a ZFS boot 1757c2cc9b2SKyle Evansenvironment, 176d2a6bc9fSKyle Evans.It Nm 1777c2cc9b2SKyle Evansfails to open the zpool the active boot environment resides on, or 178d2a6bc9fSKyle Evans.It Nm 1797c2cc9b2SKyle Evansfails to locate the boot environment that is currently mounted. 1807c2cc9b2SKyle Evans.El 18128f16a0fSKyle Evans.Pp 1827c2cc9b2SKyle EvansThe 1837c2cc9b2SKyle Evans.Fn libbe_close 1847c2cc9b2SKyle Evansfunction frees all resources previously acquired in 1857c2cc9b2SKyle Evans.Fn libbe_init , 1867c2cc9b2SKyle Evansinvalidating the handle in the process. 18728f16a0fSKyle Evans.Pp 1887c2cc9b2SKyle EvansThe 1897c2cc9b2SKyle Evans.Fn be_active_name 190cc624025SKyle Evansfunction returns the name of the currently booted boot environment. 191cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe 192cc624025SKyle Evansis operating on! 19384e61219SKyle Evans.Pp 1947c2cc9b2SKyle EvansThe 1957c2cc9b2SKyle Evans.Fn be_active_path 1967c2cc9b2SKyle Evansfunction returns the full path of the currently booted boot environment. 197cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe 198cc624025SKyle Evansis operating on! 19984e61219SKyle Evans.Pp 2007c2cc9b2SKyle EvansThe 2017c2cc9b2SKyle Evans.Fn be_nextboot_name 2027c2cc9b2SKyle Evansfunction returns the name of the boot environment that will be active on reboot. 20328f16a0fSKyle Evans.Pp 2047c2cc9b2SKyle EvansThe 2057c2cc9b2SKyle Evans.Fn be_nextboot_path 2067c2cc9b2SKyle Evansfunction returns the full path of the boot environment that will be 2077c2cc9b2SKyle Evansactive on reboot. 20828f16a0fSKyle Evans.Pp 2097c2cc9b2SKyle EvansThe 2107c2cc9b2SKyle Evans.Fn be_root_path 2117c2cc9b2SKyle Evansfunction returns the boot environment root path. 21228f16a0fSKyle Evans.Pp 2137c2cc9b2SKyle EvansThe 2147c2cc9b2SKyle Evans.Fn be_create 2157c2cc9b2SKyle Evansfunction creates a boot environment with the given name. 2167c2cc9b2SKyle EvansIt will be created from a snapshot of the currently booted boot environment. 21728f16a0fSKyle Evans.Pp 2187c2cc9b2SKyle EvansThe 2197c2cc9b2SKyle Evans.Fn be_create_from_existing 2207c2cc9b2SKyle Evansfunction creates a boot environment with the given name from the name of an 2217c2cc9b2SKyle Evansexisting boot environment. 2227c2cc9b2SKyle EvansA snapshot will be made of the base boot environment, and the new boot 2237c2cc9b2SKyle Evansenvironment will be created from that. 22428f16a0fSKyle Evans.Pp 2257c2cc9b2SKyle EvansThe 2267c2cc9b2SKyle Evans.Fn be_create_from_existing_snap 2277c2cc9b2SKyle Evansfunction creates a boot environment with the given name from an existing 2287c2cc9b2SKyle Evanssnapshot. 22928f16a0fSKyle Evans.Pp 2307c2cc9b2SKyle EvansThe 2317c2cc9b2SKyle Evans.Fn be_rename 2328369ba42SKyle Evansfunction renames a boot environment without unmounting it, as if renamed with 2338369ba42SKyle Evansthe 2348369ba42SKyle Evans.Fl u 2358369ba42SKyle Evansargument were passed to 2368369ba42SKyle Evans.Nm zfs 2378369ba42SKyle Evans.Cm rename 2389b1662e6SKyle Evans.Pp 2397c2cc9b2SKyle EvansThe 2407c2cc9b2SKyle Evans.Fn be_activate 2417c2cc9b2SKyle Evansfunction makes a boot environment active on the next boot. 2427c2cc9b2SKyle EvansIf the 2437c2cc9b2SKyle Evans.Fa temporary 2447c2cc9b2SKyle Evansflag is set, then it will be active for the next boot only, as done by 2457c2cc9b2SKyle Evans.Xr zfsbootcfg 8 . 2467c2cc9b2SKyle EvansNext boot functionality is currently only available when booting in x86 BIOS 2477c2cc9b2SKyle Evansmode. 24828f16a0fSKyle Evans.Pp 2497c2cc9b2SKyle EvansThe 2507c2cc9b2SKyle Evans.Fn be_destroy 2517c2cc9b2SKyle Evansfunction will recursively destroy the given boot environment. 2527c2cc9b2SKyle EvansIt will not destroy a mounted boot environment unless the 2537c2cc9b2SKyle Evans.Dv BE_DESTROY_FORCE 2547c2cc9b2SKyle Evansoption is set in 2557c2cc9b2SKyle Evans.Fa options . 256446ae812SKyle EvansIf the 257446ae812SKyle Evans.Dv BE_DESTROY_ORIGIN 258446ae812SKyle Evansoption is set in 259446ae812SKyle Evans.Fa options , 260446ae812SKyle Evansthe 261446ae812SKyle Evans.Fn be_destroy 262446ae812SKyle Evansfunction will destroy the origin snapshot to this boot environment as well. 263843e39ceSKyle Evans.Pp 2647c2cc9b2SKyle EvansThe 2657c2cc9b2SKyle Evans.Fn be_nicenum 2667c2cc9b2SKyle Evansfunction will format 2677c2cc9b2SKyle Evans.Fa name 2687c2cc9b2SKyle Evansin a traditional ZFS humanized format, similar to 2697c2cc9b2SKyle Evans.Xr humanize_number 3 . 2707c2cc9b2SKyle EvansThis function effectively proxies 2717c2cc9b2SKyle Evans.Fn zfs_nicenum 2727c2cc9b2SKyle Evansfrom libzfs. 27328f16a0fSKyle Evans.Pp 2747c2cc9b2SKyle EvansThe 2757c2cc9b2SKyle Evans.Fn be_mount 2767c2cc9b2SKyle Evansfunction will mount the given boot environment. 2777c2cc9b2SKyle EvansIf 2787c2cc9b2SKyle Evans.Fa mountpoint 2797c2cc9b2SKyle Evansis 2807c2cc9b2SKyle Evans.Dv NULL , 2817c2cc9b2SKyle Evansa mount point will be generated in 2827c2cc9b2SKyle Evans.Pa /tmp 2837c2cc9b2SKyle Evansusing 2847c2cc9b2SKyle Evans.Xr mkdtemp 3 . 2857c2cc9b2SKyle EvansIf 2867c2cc9b2SKyle Evans.Fa result 2877c2cc9b2SKyle Evansis not 2887c2cc9b2SKyle Evans.Dv NULL , 289a8e44f4dSKyle Evansit should be large enough to accommodate 290a8e44f4dSKyle Evans.Dv BE_MAXPATHLEN 291a8e44f4dSKyle Evansincluding the null terminator. 2927c2cc9b2SKyle Evansthe final mount point will be copied into it. 2937c2cc9b2SKyle EvansSetting the 2947c2cc9b2SKyle Evans.Dv BE_MNT_FORCE 2957c2cc9b2SKyle Evansflag will pass 2967c2cc9b2SKyle Evans.Dv MNT_FORCE 2977c2cc9b2SKyle Evansto the underlying 2987c2cc9b2SKyle Evans.Xr mount 2 2997c2cc9b2SKyle Evanscall. 30028f16a0fSKyle Evans.Pp 3017c2cc9b2SKyle EvansThe 3027c2cc9b2SKyle Evans.Fn be_mounted_at 3037c2cc9b2SKyle Evansfunction will check if there is a boot environment mounted at the given 3047c2cc9b2SKyle Evans.Fa path . 3057c2cc9b2SKyle EvansIf 3067c2cc9b2SKyle Evans.Fa details 3077c2cc9b2SKyle Evansis not 3087c2cc9b2SKyle Evans.Dv NULL , 3097c2cc9b2SKyle Evansit will be populated with a list of the mounted dataset's properties. 3107c2cc9b2SKyle EvansThis list of properties matches the properties collected by 3117c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 31228f16a0fSKyle Evans.Pp 3137c2cc9b2SKyle EvansThe 3147c2cc9b2SKyle Evans.Fn be_unmount 3157c2cc9b2SKyle Evansfunction will unmount the given boot environment. 3167c2cc9b2SKyle EvansSetting the 3177c2cc9b2SKyle Evans.Dv BE_MNT_FORCE 3187c2cc9b2SKyle Evansflag will pass 3197c2cc9b2SKyle Evans.Dv MNT_FORCE 3207c2cc9b2SKyle Evansto the underlying 3217c2cc9b2SKyle Evans.Xr mount 2 3227c2cc9b2SKyle Evanscall. 32328f16a0fSKyle Evans.Pp 3247c2cc9b2SKyle EvansThe 3257c2cc9b2SKyle Evans.Fn libbe_errno 3267c2cc9b2SKyle Evansfunction returns the 3277c2cc9b2SKyle Evans.Nm 3287c2cc9b2SKyle Evanserrno. 32928f16a0fSKyle Evans.Pp 3307c2cc9b2SKyle EvansThe 3317c2cc9b2SKyle Evans.Fn libbe_error_description 3327c2cc9b2SKyle Evansfunction returns a string description of the currently set 3337c2cc9b2SKyle Evans.Nm 3347c2cc9b2SKyle Evanserrno. 33528f16a0fSKyle Evans.Pp 3367c2cc9b2SKyle EvansThe 3377c2cc9b2SKyle Evans.Fn libbe_print_on_error 3387c2cc9b2SKyle Evansfunction will change whether or not 3397c2cc9b2SKyle Evans.Nm 3407c2cc9b2SKyle Evansprints the description of any encountered error to 3417c2cc9b2SKyle Evans.Dv stderr , 3427c2cc9b2SKyle Evansbased on 3437c2cc9b2SKyle Evans.Fa doprint . 34428f16a0fSKyle Evans.Pp 3457c2cc9b2SKyle EvansThe 3467c2cc9b2SKyle Evans.Fn be_root_concat 3477c2cc9b2SKyle Evansfunction will concatenate the boot environment root and the given boot 3487c2cc9b2SKyle Evansenvironment name into 3497c2cc9b2SKyle Evans.Fa result . 35028f16a0fSKyle Evans.Pp 3517c2cc9b2SKyle EvansThe 3527c2cc9b2SKyle Evans.Fn be_validate_name 3535b7803a9SKyle Evansfunction will validate the given boot environment name for both length 3545b7803a9SKyle Evansrestrictions as well as valid character restrictions. 3555b7803a9SKyle EvansThis function does not set the internal library error state. 35628f16a0fSKyle Evans.Pp 3577c2cc9b2SKyle EvansThe 3587c2cc9b2SKyle Evans.Fn be_validate_snap 3597c2cc9b2SKyle Evansfunction will validate the given snapshot name. 3607c2cc9b2SKyle EvansThe snapshot must have a valid name, exist, and have a mountpoint of 3617c2cc9b2SKyle Evans.Pa / . 3627c2cc9b2SKyle EvansThis function does not set the internal library error state. 36328f16a0fSKyle Evans.Pp 3647c2cc9b2SKyle EvansThe 3657c2cc9b2SKyle Evans.Fn be_exists 3667c2cc9b2SKyle Evansfunction will check whether the given boot environment exists and has a 3677c2cc9b2SKyle Evansmountpoint of 3687c2cc9b2SKyle Evans.Pa / . 369162ec569SKyle EvansThis function does not set the internal library error state, but will return 370162ec569SKyle Evansthe appropriate error. 371734e362fSKyle Evans.Pp 3727c2cc9b2SKyle EvansThe 3737c2cc9b2SKyle Evans.Fn be_export 3747c2cc9b2SKyle Evansfunction will export the given boot environment to the file specified by 3757c2cc9b2SKyle Evans.Fa fd . 3767c2cc9b2SKyle EvansA snapshot will be created of the boot environment prior to export. 377734e362fSKyle Evans.Pp 3787c2cc9b2SKyle EvansThe 3797c2cc9b2SKyle Evans.Fn be_import 3807c2cc9b2SKyle Evansfunction will import the boot environment in the file specified by 3817c2cc9b2SKyle Evans.Fa fd , 3827c2cc9b2SKyle Evansand give it the name 3837c2cc9b2SKyle Evans.Fa be_name . 3844146029bSKyle Evans.Pp 3857c2cc9b2SKyle EvansThe 3867c2cc9b2SKyle Evans.Fn be_prop_list_alloc 3877c2cc9b2SKyle Evansfunction allocates a property list suitable for passing to 3887c2cc9b2SKyle Evans.Fn be_get_bootenv_props , 3897c2cc9b2SKyle Evans.Fn be_get_dataset_props , 3907c2cc9b2SKyle Evansor 3917c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots . 3927c2cc9b2SKyle EvansIt should be freed later by 3937c2cc9b2SKyle Evans.Fa be_prop_list_free . 39496c5db58SKyle Evans.Pp 3957c2cc9b2SKyle EvansThe 3967c2cc9b2SKyle Evans.Fn be_get_bootenv_props 3977c2cc9b2SKyle Evansfunction will populate 3987c2cc9b2SKyle Evans.Fa be_list 3997c2cc9b2SKyle Evanswith 4007c2cc9b2SKyle Evans.Vt nvpair_t 4017c2cc9b2SKyle Evansof boot environment names paired with an 4027c2cc9b2SKyle Evans.Vt nvlist_t 4037c2cc9b2SKyle Evansof their properties. 4047c2cc9b2SKyle EvansThe following properties are currently collected as appropriate: 4057c2cc9b2SKyle Evans.Bl -column "Returned name" 4067c2cc9b2SKyle Evans.It Sy Returned name Ta Sy Description 4077c2cc9b2SKyle Evans.It dataset Ta - 4087c2cc9b2SKyle Evans.It name Ta Boot environment name 4097c2cc9b2SKyle Evans.It mounted Ta Current mount point 4107c2cc9b2SKyle Evans.It mountpoint Ta Do mountpoint Dc property 4117c2cc9b2SKyle Evans.It origin Ta Do origin Dc property 4127c2cc9b2SKyle Evans.It creation Ta Do creation Dc property 4137c2cc9b2SKyle Evans.It active Ta Currently booted environment 4147c2cc9b2SKyle Evans.It used Ta Literal Do used Dc property 4157c2cc9b2SKyle Evans.It usedds Ta Literal Do usedds Dc property 4167c2cc9b2SKyle Evans.It usedsnap Ta Literal Do usedrefreserv Dc property 4177c2cc9b2SKyle Evans.It referenced Ta Literal Do referenced Dc property 4187c2cc9b2SKyle Evans.It nextboot Ta Active on next boot 4197c2cc9b2SKyle Evans.El 4207c2cc9b2SKyle Evans.Pp 4217c2cc9b2SKyle EvansOnly the 4227c2cc9b2SKyle Evans.Dq dataset , 4237c2cc9b2SKyle Evans.Dq name , 4247c2cc9b2SKyle Evans.Dq active , 4257c2cc9b2SKyle Evansand 4267c2cc9b2SKyle Evans.Dq nextboot 4277c2cc9b2SKyle Evansreturned values will always be present. 4287c2cc9b2SKyle EvansAll other properties may be omitted if not available. 4297c2cc9b2SKyle Evans.Pp 4307c2cc9b2SKyle EvansThe 4317c2cc9b2SKyle Evans.Fn be_get_dataset_props 4327c2cc9b2SKyle Evansfunction will get properties of the specified dataset. 4337c2cc9b2SKyle Evans.Fa props 4347c2cc9b2SKyle Evansis populated directly with a list of the properties as returned by 4357c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 4367c2cc9b2SKyle Evans.Pp 4377c2cc9b2SKyle EvansThe 4387c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots 4397c2cc9b2SKyle Evansfunction will retrieve all snapshots of the given dataset. 4407c2cc9b2SKyle Evans.Fa snap_list 4417c2cc9b2SKyle Evanswill be populated with a list of 4427c2cc9b2SKyle Evans.Vt nvpair_t 4437c2cc9b2SKyle Evansexactly as specified by 4447c2cc9b2SKyle Evans.Fn be_get_bootenv_props . 4457c2cc9b2SKyle Evans.Pp 4467c2cc9b2SKyle EvansThe 4477c2cc9b2SKyle Evans.Fn be_prop_list_free 4487c2cc9b2SKyle Evansfunction will free the property list. 44928f16a0fSKyle Evans.Sh DIAGNOSTICS 450cc58f749SMateusz PiotrowskiUpon error, one of the following values will be returned: 451cc58f749SMateusz Piotrowski.Bl -dash -offset indent -compact 452cc58f749SMateusz Piotrowski.It 453cc58f749SMateusz PiotrowskiBE_ERR_SUCCESS 454cc58f749SMateusz Piotrowski.It 455cc58f749SMateusz PiotrowskiBE_ERR_INVALIDNAME 456cc58f749SMateusz Piotrowski.It 457cc58f749SMateusz PiotrowskiBE_ERR_EXISTS 458cc58f749SMateusz Piotrowski.It 459cc58f749SMateusz PiotrowskiBE_ERR_NOENT 460cc58f749SMateusz Piotrowski.It 461cc58f749SMateusz PiotrowskiBE_ERR_PERMS 462cc58f749SMateusz Piotrowski.It 463cc58f749SMateusz PiotrowskiBE_ERR_DESTROYACT 464cc58f749SMateusz Piotrowski.It 465cc58f749SMateusz PiotrowskiBE_ERR_DESTROYMNT 466cc58f749SMateusz Piotrowski.It 467cc58f749SMateusz PiotrowskiBE_ERR_BADPATH 468cc58f749SMateusz Piotrowski.It 469cc58f749SMateusz PiotrowskiBE_ERR_PATHBUSY 470cc58f749SMateusz Piotrowski.It 471cc58f749SMateusz PiotrowskiBE_ERR_PATHLEN 472cc58f749SMateusz Piotrowski.It 473cc58f749SMateusz PiotrowskiBE_ERR_BADMOUNT 474cc58f749SMateusz Piotrowski.It 475cc58f749SMateusz PiotrowskiBE_ERR_NOORIGIN 476cc58f749SMateusz Piotrowski.It 477cc58f749SMateusz PiotrowskiBE_ERR_MOUNTED 478cc58f749SMateusz Piotrowski.It 479cc58f749SMateusz PiotrowskiBE_ERR_NOMOUNT 480cc58f749SMateusz Piotrowski.It 481cc58f749SMateusz PiotrowskiBE_ERR_ZFSOPEN 482cc58f749SMateusz Piotrowski.It 483cc58f749SMateusz PiotrowskiBE_ERR_ZFSCLONE 484cc58f749SMateusz Piotrowski.It 485cc58f749SMateusz PiotrowskiBE_ERR_IO 486cc58f749SMateusz Piotrowski.It 487cc58f749SMateusz PiotrowskiBE_ERR_NOPOOL 488cc58f749SMateusz Piotrowski.It 489cc58f749SMateusz PiotrowskiBE_ERR_NOMEM 490cc58f749SMateusz Piotrowski.It 49128f16a0fSKyle EvansBE_ERR_UNKNOWN 492*be7dd423SKyle Evans.It 493*be7dd423SKyle EvansBE_ERR_INVORIGIN 494cc58f749SMateusz Piotrowski.El 49528f16a0fSKyle Evans.Sh SEE ALSO 496f5c8cb4cSMateusz Piotrowski.Xr bectl 8 49728f16a0fSKyle Evans.Sh HISTORY 49828f16a0fSKyle Evans.Nm 49984e61219SKyle Evansand its corresponding command, 50084e61219SKyle Evans.Xr bectl 8 , 50128f16a0fSKyle Evanswere written as a 2017 Google Summer of Code project with Allan Jude serving 50228f16a0fSKyle Evansas a mentor. 5037c2cc9b2SKyle EvansLater work was done by 5047c2cc9b2SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 505