Skip to content

Instantly share code, notes, and snippets.

@dch
Last active May 18, 2020 09:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dch/9389537e4cadad247419 to your computer and use it in GitHub Desktop.
Save dch/9389537e4cadad247419 to your computer and use it in GitHub Desktop.
freebsd upgrade using git or svn source & making a low-fat bootable image aka memstick

overview

FreeBSD OS upgrades are done in 3 phases:

  • install new kernel
  • install new userland
  • upgrade all packages

Around these 3 stages, we use zfs snapshot and a git snapshot of /etc to make rollback and diffing any releases easier. freebsd-version -ku has been used liberally to help you see the changes as you step through.

upgrade via packages

for a vanilla/new box

zpool set failmode=continue zroot
zfs set checksum=sha256 zroot
pkg install rsync tmux git

keep a record of changes

  • zfs rollback for the whole system
  • git history for /etc specifically incase of merge issues
cd /etc
git add -A
git commit -am pre-11.0R
zfs snapshot -r zroot@`date -u +%Y%m%d-%H%M`:pre-11.0R

kernel upgrade

During the upgrade you'll be asked about merging / diffing various files in /etc/ and see a few messages about various files not being present. These should be straightforwards, in most cases Yes is the correct answer. Most important is the password & group file changes, leave these as proposed, as generally they're correct and include changes from system daemons that have been added or perhaps removed. Make sure your username/ssh id is listed here so you can get in again remotely after reboots.

freebsd-version -ku
/usr/sbin/freebsd-update -r 11.0-RELEASE upgrade
freebsd-version -ku
/usr/sbin/freebsd-update install
freebsd-version -ku
reboot

If you encounter freebsd-update failed an integrity check then the issue is that your current FreeBSD release needs to be moved to the latest patch level first. Use /usr/sbin/freebsd-update fetch install and follow most of the steps below, then reboot, and jump to the beginning again.

userland upgrade

freebsd-version -ku
/usr/sbin/freebsd-update install
freebsd-version -ku
reboot

package upgrade

pkg-static install -f pkg
pkg update -f
pkg upgrade -y

At this point let's snapshot everything again:

cd /etc
git add -A
git commit -am post-11.0R
zfs snapshot -r zroot@`date -u +%Y%m%d-%H%M`:post-11.0R

We're done - if you want to, reboot again just for kick.s

source upgrade

a fresh start

# vagrant init freebsd/FreeBSD-11.0-RELEASE
cat <<EOF > Vagrantfile
# -*- mode: ruby -*-
Vagrant.configure(2) do |config|
    config.vm.box = "freebsd/FreeBSD-11.0-RELEASE"
    config.ssh.insert_key = false
    config.vm.hostname = "currant"
    config.vm.boot_timeout = 600
    config.vm.network "public_network", ip: "10.0.0.120"
    config.vm.provider "vmware_fusion" do |v|
        v.vmx["memsize"] = "8192"
        v.vmx["numvcpus"] = "2"
        v.gui = true
    end
end
EOF
vagrant up

Stash some Tools

vagrant ssh as usual, sudo all the way.

sudo -s
pkg install -y ccache tmux rsync git mosh p7zip
mkdir -m 0700 /root/.ssh
curl https://home.apache.org/~dch/authorized_keys >> /root/.ssh/authorized_keys
echo "PermitRootLogin prohibit-password" >> /etc/ssh/sshd_config
service sshd restart
alias l /bin/ls -AFGhl
echo alias l /bin/ls -AFGhl >> /root/.cshrc
echo alias l=\'/bin/ls -AFGhl\' >> /root/.profile

Go Ram

echo <<EOT >> /etc/fstab
tmpfs		/tmp			tmpfs	rw,mode=01777,size=12g		0		0
tmpfs		/usr/obj		tmpfs	rw,mode=01777,size=12g,late	0		0
EOT
# reboot if needed for /tmp
cat <<EOF >> /etc/make.conf
DEVELOPER=yes
WRKDIRPREFIX=/tmp
CCACHE_DIR=/tmp/ccache
EOF

Get the Source

# optionally make a new ramdisk backed /usr/src
rm -rf /usr/src /tmp/usr_src
mkdir /tmp/usr_src
ln -s /tmp/usr_src /usr/src
# now clone
git clone -b master --single-branch --depth 1 \
  git://github.com/freebsd/freebsd.git /usr/src
a specific branch
git clone -b stable/11 --single-branch --depth 1 \
  git://github.com/freebsd/freebsd.git /usr/src
# or for the faint of heart, use 
svnlite checkout https://svn0.eu.freebsd.org/base/stable/11 /usr/src
svnlite checkout https://svn0.eu.freebsd.org/base/ /usr/src

wrt http://www.wonkity.com/~wblock/docs/html/buildworld.html

cd /usr/src
make -j8 buildworld && echo DONE BW && \
  make -j8 kernel && echo DONE MK && \
  make installworld  && echo DONE IW && \

Make a Release

cd /usr/src/release && \
  make -DNOPORTS -DNODOC -DNOSRC memstick && echo DONE IMG && \
  echo OK | tee /var/tmp/build.log
# if that fails, try `make memstick` & live with it

Clean Up

cd /etc
git init .
git add -A
git commit -am import
# mergemaster -Ui
etcupdate
git add -A
git commit -am update
shutdown -r now
cd /usr/src
make check-old delete-old delete-old-libs
make clean

Recover

Oops! Run rescue and then:

zpool import -R /zroot -f zroot &
mkdir /root/.ssh
cd /root/.ssh
fetch https://home.apache.org/~dch/authorized_keys
alias l /bin/ls -AFGhl
echo alias l /bin/ls -AFGhl >> /root/.cshrc
echo alias l=\'/bin/ls -AFGhl\' >> /root/.profile
zfs rollback -r zroot/zroot@....

check other zfs datasets if required, and reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment