History log of /freebsd-head/sbin/bectl/bectl.c
Revision Date Author Comments
a9be09f45f9fb89863944ed758705caf3ccc4b65 21-Sep-2020 tsoome <tsoome@FreeBSD.org> loader: zfs should support bootonce an nextboot

bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.

By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.

By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.

bootonce dataset name is recorded in boot pool labels, bootenv area.

in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.

bootonce and nextboot features are usable in both UEFI and BIOS boot.

To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).

At this time, only lua loader is updated.

Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
1477dd823eeba35fa5a7a07de0a6a4273cdc59d6 25-Aug-2020 mmacy <mmacy@FreeBSD.org> Merge OpenZFS support in to HEAD.

The primary benefit is maintaining a completely shared
code base with the community allowing FreeBSD to receive
new features sooner and with less effort.

I would advise against doing 'zpool upgrade'
or creating indispensable pools using new
features until this change has had a month+
to soak.

Work on merging FreeBSD support in to what was
at the time "ZFS on Linux" began in August 2018.
I first publicly proposed transitioning FreeBSD
to (new) OpenZFS on December 18th, 2018. FreeBSD
support in OpenZFS was finally completed in December
2019. A CFT for downstreaming OpenZFS support in
to FreeBSD was first issued on July 8th. All issues
that were reported have been addressed or, for
a couple of less critical matters there are
pull requests in progress with OpenZFS. iXsystems
has tested and dogfooded extensively internally.
The TrueNAS 12 release is based on OpenZFS with
some additional features that have not yet made
it upstream.

Improvements include:
project quotas, encrypted datasets,
allocation classes, vectorized raidz,
vectorized checksums, various command line
improvements, zstd compression.

Thanks to those who have helped along the way:
Ryan Moeller, Allan Jude, Zack Welch, and many

Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D25872
61fd26bb8d03c2e28a65133cf40feae700ddab94 24-Jan-2020 kevans <kevans@FreeBSD.org> Drop "All Rights Reserved" from all libbe/bectl files

I sent out an e-mail on 2020/01/21 with a plan to do this to Kyle, Rob, and
Wes; all parties have responded in the affirmative that it's OK to drop it
from these files.
df7a83da0e332f28bdda39d1958561d9067f1576 30-Nov-2019 bcr <bcr@FreeBSD.org> Capitalize some user-visible output messages in
the bectl utility.

No functional changes.

Approved by: imp@
MFC after: 7 days
Differential Revision: https://reviews.freebsd.org/D22330
2550d91204e6a00d5fe4ae6fcd2e5dc9923104f3 16-Oct-2019 kevans <kevans@FreeBSD.org> bectl(8): destroy: use BE_DESTROY_AUTOORIGIN if -o is not specified

-o will force the origin to be destroyed unconditionally.
BE_DESTROY_AUTOORIGIN, on the other hand, will only destroy the origin if it
matches the format used by be_snapshot. This lets us clean up the snapshots
that are clearly not user-managed (because we're creating them) while
leaving user-created snapshots in place and warning that they're still
around when the BE created goes away.
add96fb8ab0607d1a7997c8c7fb7ae91aa2d9c99 11-Sep-2019 kevans <kevans@FreeBSD.org> bectl(8): Add a "check" command

This command simply returns 0 at the moment and explicitly takes no
arguments. This should be used by utilities wanting to see if bectl can
operate on the system they're running, or with a specific root (`bectl -r`).
It may grow more checks than "will libbe successfully init" in the future,
but for now this is enough as that checks for the dataset mounted at "/" and
that it looks capable of being a BE root (e.g. it's not a top-level dataset)

bectl commands can now specify if they want to be silent, and this will turn
off libbe_print_on_error so they can control the output as needed. This is
already used in `bectl check`, and may be turned on in the future for some
other commands where libbe errors are better suppressed as the failure mode
may be obvious.

Requested by: David Fullard
MFC after: 3 days
a7bf7ad2187ebfd03e079b6265df68dfe2311600 04-Sep-2019 kevans <kevans@FreeBSD.org> bectl(8): implement sorting for 'bectl list' output

Allow 'bectl list' to sort output by a given property name. The property
name is passed in using a command-line flag, '-c' for ascending order and
'-C' for descending order. The properties allowed to sort by are:

- name (the default output, even if '-c' or '-C' are not used)
- creation
- origin
- used
- usedds
- usedsnap
- usedrefreserv

The default output for 'bectl list' is now ascending alphabetical order of
BE name.

To sort by creation time from earliest to latest, the command would be
'bectl list -c creation'

Submitted by: Rob Fairbanks <rob.fx907 gmail com>
Reviewed by: ler
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D20818
9833cb47cf61d471450dc1e2fa175d16ee865054 27-Jun-2019 kevans <kevans@FreeBSD.org> bectl(8): create non-recursive boot environments

bectl advertises that it has the ability to create recursive and
non-recursive boot environments. This patch implements that functionality
using the be_create_depth API provided by libbe. With this patch, bectl now
works as bectl(8) describes in regards to creating recursive/non-recursive
boot environments.

Submitted by: Rob Fairbanks <rob.fx907 gmail com> (with minor changes)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D20240
4d060aa696cb029d066bb59dd46a73155a39bf9c 11-Feb-2019 kevans <kevans@FreeBSD.org> bectl(8): Add -o flag to destroy to clean up the origin snapshot of BE

We can't predict when destruction of origin is needed, and currently we have
a precedent for not prompting for things. Leave the decision up to the user
of bectl(8) if they want the origin snapshot to be destroyed or not.

Emits a warning when -o isn't used and an origin snapshot is left to be
cleaned up, for the time being. This is handy when one drops the -o flag but
really did want to clean up the origin.

A couple of -e ignore's have been sprinkled around the test suite for places
that we don't care that the origin's not been cleaned up. -o functionality
tests will be added in the future, but are omitted for now to reduce
conflicts with work in flight to fix bits of the tests.

Reported by: Shawn Webb
MFC after: 1 week
c8fc070608e2937cb63b9e47361ebfc780521e9f 10-Jan-2019 kevans <kevans@FreeBSD.org> libbe(3): Change be_mount to mount/unmount child datasets

This set of changes is geared towards making bectl respect deep boot
environments when they exist and are mounted. The deep BE composition
functionality (`bectl add`) remains disabled for the time being. This set of
changes has no effect for the average user. but allows deep BE users to
upgrade properly with their current setup.

libbe(3): Open the target boot environment and get a zfs handle, then pass
that with the target mountpoint to be_mount_iter; If the BE_MNT_DEEP flag is
set call zfs_iter_filesystems and mount the child datasets.

Similar logic is employed when unmounting the datasets, save for children
are unmounted first.

bectl(8): Change bectl_cmd_jail to pass the BE_MNT_DEEP flag when
calling be_mount as well as call be_unmount when cleaning up after the
jail has exited instead of umount(2) directly.

PR: 234795
Submitted by: Wes Maag <jwmaag_gmail.com> (test additions by kevans)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D18796
6cc50ba9728745ded17ff32109bc4a55db63eebe 26-Nov-2018 yuripv <yuripv@FreeBSD.org> bectl: sync usage with man page, removing stray multibyte characters
in the process.

PR: 233526
Submitted by: tigersharke@gmail.com (original version)
Reviewed by: kevans
Approved by: kib (mentor, implicit)
MFC after: 3 days
Differential revision: https://reviews.freebsd.org/D18335
259052139d27f1424fb6d4849b3044f949ba1423 19-Nov-2018 kevans <kevans@FreeBSD.org> bectl(3)/libbe(3): Allow BE root to be specified

Add an undocumented -r option preceding the bectl subcommand to specify a BE
root to operate out of. This will remain undocumented for now, as some
caveats apply:

- BEs cannot be activated in the pool that doesn't contain the rootfs
- bectl create cannot work out of the box without the -e option right now,
since it defaults to the rootfs and cross-pool cloning doesn't work like
that (IIRC)

Plumb the BE root through to libbe(3) so that some things -can- be done to
it, e.g.

bectl -r tank/ROOT create -e default upgrade
bectl -r tank/ROOT mount upgrade /mnt

this aides in some upgrade setups where rootfs is not necessarily ZFS, and
also makes it easier/possible to regression-test bectl when combined with a
file-backed zpool.

MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D18029
51650c5969219f52352889e7a7f1a8625ef03015 24-Aug-2018 kevans <kevans@FreeBSD.org> libbe(3)/bectl(8): Make consistent with beadm

vermaden (maintainer of beadm) points out the following inconsistencies:
- "missing command" is not printed prior to usage if the error is simply a
missing command; this should be obvious from the context
- "bectl rename" isn't using the "don't unmount" flag (zfs rename -u), so
the active BE can't be renamed. It doesn't make sense in our context to
*not* use -u, so use it.

Documentation updates reflect the above and note an inconsistency with the
'destroy' command that is consistent with other parts of the base system.

A fix for libbe(3) not properly being installed to /lib is included.
SHLIBDIR should have been added when it was moved in r337995.

Approved by: re (kib)
9bd716fd96036a97ac053afc6977fc11f4485159 23-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Man page and usage cleanup

- Some overly-long lines
- Consistently using .Brq ({})
- Consistently using .Cm
- Not using .Ao/.Ac around .Ar

PR: 230576
Submitted by: Yuri Pankov (with a fair amount of rebasing pre-commit)
5fd4108940b65db21f4fafa9bcbd6a09d520d7c7 23-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): jail: Tear down jail by default after command exits

Add a -U flag to get back the old behavior. The new behavior is a little
more friendly to the common use cases, jail the BE and execute a script.
Having the jail torn down automatically when the script is finished, or when
you exit the shell, is a little more friendly than having to remember to
`bectl ujail`.

Batch mode (-b) will continue to leave the jail up, as it's assumed the
caller has other intentions.

Submitted by: Shawn Webb (partially)
3719708451096e21bfd692bafca4187a17bc0db0 18-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Allow running a custom command in the 'jail' subcommand

Instead of always running /bin/sh, allow the user to specify the command
to run. The jail is not removed when the command finishes. Meaning,
`bectl unjail` will still need to be run.

For example:

bectl jail newBE pkg upgrade
bectl ujail newBE

Submitted by: Shawn Webb
Obtained from: HardenedBSD (8b451014ab)
7404e36f697dc487f05fe7b163d7ca7319be1dbd 17-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Add batch mode to jail subcommand

Adding batch mode to the jail `bectl(8)` subcommand enables jailing of
ZFS Boot Environments in a scriptable fashion.

Submitted by: Shawn Webb
Obtained from: HardenedBSD (9e72d1c59a and ef7b6d9e1c with minor edit)
4cdb717ea7b0a522935889ab688d6a41abc0d499 16-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Kit-kat bar
2018f9b4db373a70475f3cd9385778ccd67780d3 16-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Implement the 'create a snapshot' variant of create
0a437023fb924747aa9ae6453b92076d6aba36a0 12-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Rename "index" variable, which shadows a global in some lands
92afc1f6f98af9951dbd6b9f92103449a551bdcd 11-Aug-2018 kevans <kevans@FreeBSD.org> libbe(3)/bectl(8): Kill off the 'add' functionality for now

The mostly-undocumented 'add' functionality, from initial read-through, is
intended for construction of deep ("bdrewery style") boot environments.
However, it's mostly broken at this point. `#if SOON` it out on both sides
so that we're not exposing a broken API/feature.

Work will resume on it in due time.
7c587a9287ee408d46991a4b79a23504cc21df99 07-Aug-2018 kevans <kevans@FreeBSD.org> libbe(3)/bectl(8): Standardize $FreeBSD$ IDs
e449ef064192fbe93cade01f57986f2a6a8c6df1 07-Aug-2018 kevans <kevans@FreeBSD.org> libbe(3)/bectl(8): Standardize copyright headers

- File names don't necessarily need to be repeated
- Add SPDX tags
- Add a missing copyright for Kyle Kneitinger in bectl.8, originally written
by him in GSoC 2017; his standard copyright notice has been copied from
other files within the same directory to remain consistent with how he
clearly wished to portray it
b98d40579d1dadfe712d81c4dd8d0e8e356eac61 06-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Provide -u option to unset jail parameters

All but name, host.hostname, and path may be completely unset.
8983506f04fed14419a4a2554e58742c11a83574 06-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Split list functionality out into its own file as well
b6064a85353243f26272780416cbadba45ea0aa3 06-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): bectl jail improvements

- Support passing arbitrary jail arguments via -o
- Split the related (and rewritten since the GSoC) jail bits out into a new
bectl_jail.c file, to reduce clutter in bectl.c
- Don't use RFC 1918 IP space [0]; we'll instead set no default IPv4 and let
the user pass in any address options they wish via -o

Reported by: rgrimes [0], Shawn Webb [0]
5466dbb076b0c66f952c0f8114f4a8641de80172 05-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Some light cleanup and commenting
5ef81a6b7766500b9f37406e90a7f6f2cff83d7f 05-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Implement `bectl list -s`

be_get_dataset_snapshots has been added to libbe(3), effectively returning
the same information as be_get_bootenv_props but for snapshots of the given
dataset. The assumption is that one will have the BE dataset name before
wanting to grab snapshots.
411563c4446398a1d3407620ca297d48a19ef8bf 05-Aug-2018 kevans <kevans@FreeBSD.org> bectl: Implement -D ("space if origin datasets were deleted")

This also accomplishes the following:

- Proxy through zfs_nicenum as be_nicenum, because it looks better than
humanize_number and would presumably be useful to other libbe consumers.

- Rename be_get_snapshot_props to be_get_dataset_props, make it more useful
05fd3946e6bc5e32eb3c37a73630badab71ae66f 05-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Take -H parameter to list into account

-H is for a scripted format, where all fields are tab-delimited and the
headers go away. We accomplish this by splitting out pad printing to a
separate function that'll take into account whether we're supposed to be
scripted or not.

This has the nice side effect of maintaining positive column sizes again.
2e9b90de37a4c9386dbc81718453f76436bc802b 04-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Sort BEs lightly by active (now or later) BE, then others

While it could be preferred to do this at insert in libbe(3), there's no
convenient way to insert at the head of an nvlist. Instead, we'll make two
passes over- once to print anything active either now or at nextboot, and
another to print everything else.

This doesn't actually impact performance in a significant way here, so we'll
worry about further optimizations if the need actually arises.
45778557a3af479b733cc832f5a51d704cb612a7 04-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Add some relevant `bectl list -a` information

bectl list -a should show the boot environment, its relevant dataset, and
the snapshot it was created from. The header also changes to indicate the
rough order in which these things will show.

While here, start doing a little bit of spring cleaning and splitting
different bits out.
60ffd203c259f2d29ae6f50518797c0c2acf6450 03-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Take origin snapshot into account when calculating used space

This more closely matches the behavior for beadm. The associated libbe(3)
API is still getting worked out a little bit.
7b80e16d36f2b47d3c49e6e56e69b8e44cbb49ab 03-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Just use a single pointer for all string props
d67c0dce31bcab65403324b8302fbfe9b8a7a698 03-Aug-2018 kevans <kevans@FreeBSD.org> bectl(8): Move dataset printing out into its own function

This may later get reused for printing snapshot and/or origin snapshot
08c79a36336d8d51461879ad3208fecb797e4612 26-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Remove sneaky comment
ccd45e1825e971ac99b2bb7dae467beb88a5a617 26-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Hack together a more proper `bectl list`

Note that the space is currently just the 'used' property of the dataset.
e8f15a7d3a89a11e410a82302763669abedb2783 26-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Remove the jail mount point with unjail
caa0c010f48394f51d60f30e971fcaeb98906192 26-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Redo jail using jail(3) API

The jail is created with allow.mount, allow.mount.devfs, and
enforce_statfs=1. Upon creation, we immediately attach, chdir to "/", and
drop the user into a shell inside the jail.

The default IP for this is arbitrarily
38d4afe18749fdbba7ab61a5e21916ffbcc40f36 26-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Support unjailing a boot environment

The given parameter may either be a jid, jail name, or a BE name. In all
cases, the parameter will be resolved to a jid and bectl(8) will
sanity-check that there's actually a BE mounted at the requested jail root
before invoking jail_remove(2).
b854d08b717b69bfc8b85300cbc6bfd1a4e4e96d 25-Jul-2018 kevans <kevans@FreeBSD.org> libbe(3)/bectl(8): Provide and use proper alloc/free for property lists
fa415c9fee9cee2af67a40e6d4fc30e4123aa7e5 25-Jul-2018 kevans <kevans@FreeBSD.org> libbe(3)/be(8): Drop WARNS overrides, fix all fallout

Based on the idea that we shouldn't have all-new library and utility going
into base that need WARNS=1...

- Decent amount of constification
- Lots of parentheses
- Minor other nits
9927174fb2b57fb533af407e5ab600cfdf1cb81f 25-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Start dumping out BE information with `bectl list`

For the moment, this is a primitive nvlist dump of what we get back from
be_get_bootenv_props as a proof-of-concept and to make sure that we're
getting back the kind of information we want to see from list.
b4e1235d028bb6a3cfdb6ba2190a608ca398289d 25-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Consistent style
193203b4989b8beb2462360ea47458676010b698 25-Jul-2018 kevans <kevans@FreeBSD.org> bectl(8): Rename error messages
b45600df93a10426e36b0626bfa6c5fb361d91c7 25-Jul-2018 kevans <kevans@FreeBSD.org> bectl.c: Chase rename
4fd84870ce46c9e4cd939a2695cd91497687799a 24-Jul-2018 kevans <kevans@FreeBSD.org> Rename be(1) to bectl(8); continues to live in /sbin

Discussed with: rpokala, allanjude