Rebuilding world on FreeBSD

To upgrade FreeBSD between versions, I generally rebuild world with the latest sources. You can easily get the -RELEASE tarballs using fetch.
I generally remove the old /usr/obj and /usr/src completely before I start.

# cd /usr
# rm -R obj
# rm -R src
# fetch "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/src.txz"
# tar -x -C / -f src.txz

Obviously, for a different architecture or a different version, you’d use a different url.

Next we need to build world, build a new kernel, install the new kernel and then install the new world. There are some extra intermediate steps. This process is described very accurately in the FreeBSD Handbook, but it’s scattered all over the page. It’s also a highly interactive process, which annoys me (I don’t like pressing `yes’ repeatedly for no obvious reason). By now I’ve figured out the flags for each command so they’ll require the least amount of user intervention.

When there are no special circumstances, these should be the commands that get it all done with the lease amount of hassle:

# cd /usr/src
# make buildworld
# make buildkernel KERNCONF=GENERIC
# make installkernel KERNCONF=GENERIC
# reboot

After reboot, in the loading screen, indicate that you want to boot in single-user mode. After it has finished loading (it will ask you which shell to use, just use the default), continue with:

# mount -u /
# mount -a -t ufs
# swapon -a
# adjkerntz -i
# cd /usr/src
# mergemaster -piFU
# make installworld
# mergemaster -iFU
# make -DBATCH_DELETE_OLD_FILES delete-old
# reboot

This time, you can let FreeBSD boot normally. After the reboot, it’s generally wise to rebuild all your ports, to make sure they use the latest libraries:

# portmaster -af -dB --delete-build-only
# make -DBATCH_DELETE_OLD_FILES delete-old-libs

Note that the above commands are selected to make everything as automatic as possible. Mergemaster will only ask about files you have changed, and the make delete-old and delete-old-libs will assume you have no reason to keep old libraries.

I use portmaster to maintain my ports tree, and the above flags are once again set to minimize user interaction, as well as keeping the system clean of unneeded leaf ports.

Let me finish by stretching that this is an easy process, but can also be used to easily destroy your server. Don’t use the above commands unless you’re clear about their purpose! Usual disclaimers apply.

Final note: I generally use a bunch of tricks to speed up the build process, like storing /usr/obj and /usr/src on memory disks and using the -j flag for make. I’ll go deeper into those another time.

One Comment

  • Nice write up. This process is also used when one does a freebsd-update upgrade -r RELEASE## . Only steps I don’t do are the mergemaster and single usermode. Since I am upgrading remotely on a physical server with no console.

Leave a Reply

Your email is never shared.Required fields are marked *