2 .\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 .\" Copyright (c) 2017 Kyle Kneitinger
5 .\" All rights reserved.
6 .\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nd library for creating, destroying and modifying ZFS boot environments
41 .Ft "libbe_handle_t *hdl" Ns
42 .Fn libbe_init "const char *be_root"
45 .Fn libbe_close "libbe_handle_t *hdl"
48 .Fn be_active_name "libbe_handle_t *hdl"
51 .Fn be_active_path "libbe_handle_t *hdl"
54 .Fn be_nextboot_name "libbe_handle_t *hdl"
57 .Fn be_nextboot_path "libbe_handle_t *hdl"
60 .Fn be_root_path "libbe_handle_t *hdl"
63 .Fn be_create "libbe_handle_t *hdl" "const char *be_name"
66 .Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin"
69 .Fn be_create_from_existing_snap "libbe_handle_t *hdl" "const char *be_name" "const char *snap"
72 .Fn be_rename "libbe_handle_t *hdl" "const char *be_old" "const char *be_new"
75 .Fn be_activate "libbe_handle_t *hdl" "const char *be_name" "bool temporary"
77 .Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options"
80 .Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz"
82 .\" TODO: Write up of mount options
84 .\" BE_MNT_FORCE = 1 << 0,
85 .\" BE_MNT_DEEP = 1 << 1,
88 .Fn be_mount "libbe_handle_t *hdl" "char *be_name" "char *mntpoint" "int flags" "char *result"
91 .Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details"
94 .Fn be_unmount "libbe_handle_t *hdl" "char *be_name" "int flags"
97 .Fn libbe_errno "libbe_handle_t *hdl"
100 .Fn libbe_error_description "libbe_handle_t *hdl"
103 .Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint"
106 .Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result"
109 .Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name"
112 .Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap"
115 .Fn be_exists "libbe_handle_t *hdl" "char *be_name"
118 .Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd"
121 .Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd"
124 .Fn be_prop_list_alloc "nvlist_t **prop_list"
127 .Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list"
130 .Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props"
133 .Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list"
136 .Fn be_prop_list_free "nvlist_t *prop_list"
139 interfaces with libzfs to provide a set of functions for various operations
140 regarding ZFS boot environments including "deep" boot environments in which
141 a boot environments has child datasets.
143 A context structure is passed to each function, allowing for a small amount
144 of state to be retained, such as errors from previous operations.
146 may be configured to print the corresponding error message to
148 when an error is encountered with
149 .Fn libbe_print_on_error .
151 All functions returning an
153 return 0 on success, or a
155 errno otherwise as described in
160 function takes an optional BE root and initializes
163 .Vt "libbe_handle_t *"
167 If a BE root is supplied,
169 will only operate out of that pool and BE root.
170 An error may occur if:
172 .It /boot and / are not on the same filesystem and device,
173 .It libzfs fails to initialize,
174 .It The system has not been properly booted with a ZFS boot
177 fails to open the zpool the active boot environment resides on, or
179 fails to locate the boot environment that is currently mounted.
184 function frees all resources previously acquired in
186 invalidating the handle in the process.
190 function returns the name of the currently booted boot environment.
191 This boot environment may not belong to the same BE root as the root libbe
196 function returns the full path of the currently booted boot environment.
197 This boot environment may not belong to the same BE root as the root libbe
202 function returns the name of the boot environment that will be active on reboot.
206 function returns the full path of the boot environment that will be
211 function returns the boot environment root path.
215 function creates a boot environment with the given name.
216 It will be created from a snapshot of the currently booted boot environment.
219 .Fn be_create_from_existing
220 function creates a boot environment with the given name from the name of an
221 existing boot environment.
222 A snapshot will be made of the base boot environment, and the new boot
223 environment will be created from that.
226 .Fn be_create_from_existing_snap
227 function creates a boot environment with the given name from an existing
232 function renames a boot environment without unmounting it, as if renamed with
235 argument were passed to
241 function makes a boot environment active on the next boot.
244 flag is set, then it will be active for the next boot only, as done by
246 Next boot functionality is currently only available when booting in x86 BIOS
251 function will recursively destroy the given boot environment.
252 It will not destroy a mounted boot environment unless the
257 .Dv BE_DESTROY_ORIGIN
262 function will destroy the origin snapshot to this boot environment as well.
268 in a traditional ZFS humanized format, similar to
269 .Xr humanize_number 3 .
270 This function effectively proxies
276 function will mount the given boot environment.
281 a mount point will be generated in
289 it should be large enough to accommodate
291 including the null terminator.
292 the final mount point will be copied into it.
303 function will check if there is a boot environment mounted at the given
309 it will be populated with a list of the mounted dataset's properties.
310 This list of properties matches the properties collected by
311 .Fn be_get_bootenv_props .
315 function will unmount the given boot environment.
331 .Fn libbe_error_description
332 function returns a string description of the currently set
337 .Fn libbe_print_on_error
338 function will change whether or not
340 prints the description of any encountered error to
347 function will concatenate the boot environment root and the given boot
348 environment name into
353 function will validate the given boot environment name for both length
354 restrictions as well as valid character restrictions.
355 This function does not set the internal library error state.
359 function will validate the given snapshot name.
360 The snapshot must have a valid name, exist, and have a mountpoint of
362 This function does not set the internal library error state.
366 function will check whether the given boot environment exists and has a
369 This function does not set the internal library error state, but will return
370 the appropriate error.
374 function will export the given boot environment to the file specified by
376 A snapshot will be created of the boot environment prior to export.
380 function will import the boot environment in the file specified by
386 .Fn be_prop_list_alloc
387 function allocates a property list suitable for passing to
388 .Fn be_get_bootenv_props ,
389 .Fn be_get_dataset_props ,
391 .Fn be_get_dataset_snapshots .
392 It should be freed later by
393 .Fa be_prop_list_free .
396 .Fn be_get_bootenv_props
397 function will populate
401 of boot environment names paired with an
404 The following properties are currently collected as appropriate:
405 .Bl -column "Returned name"
406 .It Sy Returned name Ta Sy Description
408 .It name Ta Boot environment name
409 .It mounted Ta Current mount point
410 .It mountpoint Ta Do mountpoint Dc property
411 .It origin Ta Do origin Dc property
412 .It creation Ta Do creation Dc property
413 .It active Ta Currently booted environment
414 .It used Ta Literal Do used Dc property
415 .It usedds Ta Literal Do usedds Dc property
416 .It usedsnap Ta Literal Do usedrefreserv Dc property
417 .It referenced Ta Literal Do referenced Dc property
418 .It nextboot Ta Active on next boot
427 returned values will always be present.
428 All other properties may be omitted if not available.
431 .Fn be_get_dataset_props
432 function will get properties of the specified dataset.
434 is populated directly with a list of the properties as returned by
435 .Fn be_get_bootenv_props .
438 .Fn be_get_dataset_snapshots
439 function will retrieve all snapshots of the given dataset.
441 will be populated with a list of
443 exactly as specified by
444 .Fn be_get_bootenv_props .
447 .Fn be_prop_list_free
448 function will free the property list.
450 Upon error, one of the following values will be returned:
451 .Bl -dash -offset indent -compact
499 and its corresponding command,
501 were written as a 2017 Google Summer of Code project with Allan Jude serving
503 Later work was done by
504 .An Kyle Evans Aq Mt kevans@FreeBSD.org .