The branch main has been updated by kevans:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f28f138905416c45ebaa6429f44a0b88a72f54b1

commit f28f138905416c45ebaa6429f44a0b88a72f54b1
Author:     Dave Fullard <d...@fullard.ca>
AuthorDate: 2021-07-16 04:02:48 +0000
Commit:     Kyle Evans <kev...@freebsd.org>
CommitDate: 2021-07-16 04:07:00 +0000

    freebsd-update: create a ZFS boot environment on install
    
    Updated freebsd-update to allow it to create boot environments using
    bectl should the system support it. The bectl utility was updated in
    r352211 (490e13c1403f) to support a 'check' to determine if the system
    supports boot environments.  If UFS is used, the bectl check will fail
    then no attempt will be made to create the boot environment.
    
    If freebsd-update is run inside a jail, no attempt will be made to
    create a boot environment.
    
    The boot environment function will create a new environment using the
    format: current FreeBSD kernel version and date/timestamp, example:
    
    12.0-RELEASE-p10_2019-10-03_185233
    
    This functionality can be disabled by setting 'CreateBootEnv' in
    freebsd-update.conf to 'no'.
    
    Discussed with: allanjude
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D21892
---
 usr.sbin/freebsd-update/freebsd-update.conf |  3 ++
 usr.sbin/freebsd-update/freebsd-update.sh   | 57 +++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/usr.sbin/freebsd-update/freebsd-update.conf 
b/usr.sbin/freebsd-update/freebsd-update.conf
index 7f0917053750..62e6acf96cc8 100644
--- a/usr.sbin/freebsd-update/freebsd-update.conf
+++ b/usr.sbin/freebsd-update/freebsd-update.conf
@@ -74,3 +74,6 @@ MergeChanges /etc/ /boot/device.hints
 
 # When backing up a kernel also back up debug symbol files?
 # BackupKernelSymbolFiles no
+
+# Create a new boot environment when installing patches
+# CreateBootEnv yes
diff --git a/usr.sbin/freebsd-update/freebsd-update.sh 
b/usr.sbin/freebsd-update/freebsd-update.sh
index f82ec7d7730c..4fbac58cb562 100644
--- a/usr.sbin/freebsd-update/freebsd-update.sh
+++ b/usr.sbin/freebsd-update/freebsd-update.sh
@@ -410,6 +410,23 @@ config_BackupKernelSymbolFiles () {
        fi
 }
 
+config_CreateBootEnv () {
+       if [ -z ${BOOTENV} ]; then
+               case $1 in
+               [Yy][Ee][Ss])
+                       BOOTENV=yes
+                       ;;
+               [Nn][Oo])
+                       BOOTENV=no
+                       ;;
+               *)
+                       return 1
+                       ;;
+               esac
+       else
+               return 1
+       fi
+}
 # Handle one line of configuration
 configline () {
        if [ $# -eq 0 ]; then
@@ -586,6 +603,7 @@ default_params () {
        config_BackupKernel yes
        config_BackupKernelDir /boot/kernel.old
        config_BackupKernelSymbolFiles no
+       config_CreateBootEnv yes
 
        # Merge these defaults into the earlier-configured settings
        mergeconfig
@@ -850,6 +868,44 @@ install_check_params () {
        fi
 }
 
+# Creates a new boot environment
+install_create_be () {
+       # Figure out if we're running in a jail and return if we are
+       if [ `sysctl -n security.jail.jailed` = 1 ]; then
+           return 1
+       fi
+       # Create a boot environment if enabled
+       if [ ${BOOTENV} = yes ]; then
+               bectl check 2>/dev/null
+               case $? in
+                       0)
+                               # Boot environment are supported
+                               CREATEBE=yes
+                               ;;
+                       255)
+                               # Boot environments are not supported
+                               CREATEBE=no
+                               ;;
+                       *)
+                               # If bectl returns an unexpected exit code, 
don't create a BE
+                               CREATEBE=no
+                               ;;
+               esac
+               if [ ${CREATEBE} = yes ]; then
+                       echo -n "Creating snapshot of existing boot 
environment... "
+                       VERSION=`freebsd-version -k`
+                       TIMESTAMP=`date +"%Y-%m-%d_%H%M%S"`
+                       bectl create ${VERSION}_${TIMESTAMP}
+                       if [ $? -eq 0 ]; then
+                               echo "done.";
+                       else
+                               echo "failed."
+                               exit 1
+                       fi
+               fi
+       fi
+}
+
 # Perform sanity checks and set some final parameters in
 # preparation for UNinstalling updates.
 rollback_check_params () {
@@ -3366,6 +3422,7 @@ cmd_updatesready () {
 cmd_install () {
        finalize_components_config ${COMPONENTS}
        install_check_params
+       install_create_be
        install_run || exit 1
 }
 
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to