Random Musings

O for a muse of fire, that would ascend the brightest heaven of invention!


Upgrading FreeBSD the Dirty Way

Thursday, 29 Nov 2018 Tags: dirtyfreebsdhacksupgrade

For some reason, you’re unable to simply upgrade this system the normal way. Instead, we’ll use the new bectl feature to provide a boot environment, and do a dirty upgrade inside that, out of the way of the current system.

things we want to keep

  • /boot/loader.conf
  • anything in our EFI partition
  • /etc/passwd,group and related files
  • /etc/shells
  • /etc/rc.conf
  • a list of leaf packages via pkg prime-origins > /etc/packages.list
  • a handful of other similar files

stash our configs

export NOW=`date -u +%Y%m%d-%H%M`
export PAGER="/bin/cat -bu"
export VERSION=`freebsd-version -ku | sort -r |head -1`-update
cd /etc
test -d .git || git init .
git add -A
git commit --allow-empty -am ${VERSION}
zfs snapshot -r zroot@${NOW}:${VERSION}
bectl create ${VERSION}

run update in the boot environment

# bectl jail -o name=next ${VERSION}
#
/usr/sbin/freebsd-update --not-running-from-cron fetch install || /usr/bin/true
echo OK freebsd-update complete
echo OK List Boot Environments
bectl list
echo now run "pkg update" and confirm that the changes/reinstall/updates

tar xzf /var/tmp/base.txz \
  -C /mnt \
  --clear-nochange-fflags \
  --exclude dhclient.conf \
  --exclude group \
  --exclude pwd.db \
  --exclude spwd.db \
  --exclude hosts \
  --exclude master.passwd \
  --exclude passwd \
  --exclude shells \
  --exclude sshd_config \
  --exclude sysctl.conf

# rmdir /tmp/be_mount.ctDB/
# pwd
/
# tar xzf /iocell/download/12.0-RC2/base.txz -C ./tmp/be_mount.82aP --clear-nochange-fflags
tar: could not chdir to './tmp/be_mount.82aP'

# tar xzf /iocell/download/12.0-RC2/base.txz -C /tmp/be_mount.82aP --clear-nochange-fflags
./var/empty/: Can't restore time
tar: Error exit delayed from previous errors.
# cat /root/bin/freebsd-update.sh 
#!/bin/sh -e
# ansible managed
/bin/freebsd-version -ku
export PAGER="/bin/cat -bu"
cd /etc
test -d .git || git init .
git add -A
git commit --allow-empty -am `freebsd-version -ku | sort -r |head -1`-update
zfs snapshot -r zroot@`date -u +%Y%m%d-%H%M`:`freebsd-version -ku | sort -r |head -1`-update
bectl create `freebsd-version -ku | sort -r |head -1`-update
/usr/sbin/freebsd-update --not-running-from-cron fetch install || /usr/bin/true
echo OK freebsd-update complete
echo OK List Boot Environments
bectl list
echo now run "pkg update" and confirm that the changes/reinstall/updates
echo are as expected. Once that has completed, sacrifice a goat and reboot.
# 
# pwd
/tmp/be_mount.82aP
# chroot
usage: chroot [-g group] [-G group,group,...] [-u user] newroot [command]
# chroot .
# pwd
/
# freebsd-update IDS
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 12.0-RC2 from update1.freebsd.org... done.
Fetching metadata index... done.
Inspecting system...