Run freebsd-update at first boot instead of build

Since the image probably isn't going to be rebuild that often,
it's better to update at first boot, even though that will take longer.
This commit is contained in:
Jørn Åne de Jong 2022-05-29 17:17:42 +02:00 committed by Nico Schottelius
parent a4daf87a34
commit d35d04801a
1 changed files with 7 additions and 12 deletions

View File

@ -79,6 +79,11 @@ CLOUDSETUP_PKG="/usr/ports/sysutils/firstboot-cloudsetup/work/pkg/firstboot-clou
tar -tzf "$CLOUDSETUP_PKG" >/dev/null # check that it's a valid tar, or we crash due to set -e
# tar -t lists the contents of a tar file, but does not extract
make -C /usr/ports/sysutils/firstboot-freebsd-update clean package
FBUPDATE_VERSION="$(fgrep VERSION /usr/ports/sysutils/firstboot-freebsd-update/Makefile | cut -f2- | tr -d \\t)"
FBUPDATE_PKG="/usr/ports/sysutils/firstboot-freebsd-update/work/pkg/firstboot-freebsd-update-${FBUPDATE_VERSION}.pkg"
tar -tzf "$FBUPDATE_PKG" >/dev/null # check that it's a valid tar, or we crash due to set -e
ufsdisk="$(mktemp /var/tmp/ufsdisk.XXXXX)"
truncate -s 6G "$ufsdisk"
mdconfig -a -t vnode -f "$ufsdisk" -u md1
@ -154,7 +159,7 @@ mount_nullfs /var/tmp "$UFSTARGET/var/tmp"
# --automatic means that the package is considered to be installed "automatically",
# aka as a dependency of something, so pkg autoremove will remove it.
# We do not run pkg autoremove ourselves, that's up to the administrator.
pkg --rootdir "$UFSTARGET" add --automatic "$CLOUDSETUP_PKG"
pkg --rootdir "$UFSTARGET" add --automatic "$CLOUDSETUP_PKG" "$FBUPDATE_PKG"
# Configure new system.
touch "$UFSTARGET/firstboot"
@ -168,6 +173,7 @@ sysrc -f "$UFSTARGET/etc/rc.conf" \
growfs_enable=YES \
hostname=freebsd \
firstboot_cloudsetup_enable=YES \
firstboot_freebsd_update_enable=YES \
# The resolv.conf file is written by firstboot_cloudsetup
#cp /etc/resolv.conf "$UFSTARGET/etc/resolv.conf"
@ -180,17 +186,6 @@ PasswordAuthentication no
PermitEmptyPasswords no
EOF
# freebsd-update is only supported for RELEASE
if printf %s "$RELEASE" | grep -q '.-RELEASE$'
then
env PAGER=true /usr/sbin/freebsd-update \
-b "$UFSTARGET" \
--currently-running "$RELEASE" \
--not-running-from-cron -F \
fetch install
fi
rm -rf "$UFSTARGET/var/db/freebsd-update/"* ||:
# Set zstd-19 compression, copy all data to the pool, and then set compression to default again
# This will make the base image smaller, at the cost of taking longer to generate, as zstd-19 is slow to write
# Therefore, afterwards we restore compression to default, so written files stay zstd-19, which is fast to read,