From time-to-time you will want to upgrade your FreeBSD system. My preferred method is the source method.
To start, we need to create a file to define our source update. Part of this requires you to choose a release engineering tag. This is quite simple to generate. It is the word RELENG followed by an underscore and the version number. For example, if your system is running FreeBSD 8.1-RELEASE then your release engineering tag is RELENG_8_1. If your system is FreeBSD 7.2-RELEASE, your tag is RELENG_7_2.
You can also, if you’re slightly braver, choose the ‘stable’ branch for your version of FreeBSD. This is the tag with only the major number. e.g. RELENG_8 for FreeBSD 8 stable. This is my preferred version so I will use this in my examples.
Edit/create a file called /root/bsdsrc containing:
*default release=cvs delete use-rel-suffix compress
You can change the host to be your local mirror. See my post on updating the ports tree for a list of mirror sites.
Now, to update your source tree (the files in /usr/src), make sure you’re connected to the internet and run the following command:
This will take a while as it updates any files required based on your released engineering tag. Once completed, your FreeBSD kernel/OS sources are up-to-date.
Now, we need to build a new kernel and recompile the entire OS. This sounds far worse than it is 😉
To rebuild the OS, type the following:
If you have multiple CPUs/cores in your computer, you can speed this process up by using:
make -j5 buildworld
The number after the ‘j’ should be the number of cores plus one for optimal usage.
This will take a while depending on your system specification. Once it is complete, you can build a new kernel. If you are running a custom kernel, you would replace the kernel configuration name with your custom one below. To compile a new kernel, type:
make buildkernel KERNCONF=GENERIC
Again, you can use the “-j5” notation from above to speed things up.
Ok, now you have both the OS and kernel recompiled and ready to install. At this point, you have not installed any updates, merely compiled them ready to install.
To install, type:
make installkernel KERNCONF=GENERIC
This will install the new kernel and install the OS files. Now, there’s just one step remaining. The files in /etc/ are never replaced by the install process – but they may have changed between versions.
FreeBSD includes a handy little utility that compares RCS/CVS ids on these files and allows you to see the difference and install them.
To do this, type the following while in the /usr/src folder:
This will automatically install any files that the user has not modified, or new files. Follow any instructions on the screen to handle other files.
Be weary about changes to /etc/group and /etc/master.passwd files. If you’re unsure, pressing enter will make no changes to the file.
Once this process is complete, you just need to restart your computer and it will boot with the latest kernel and OS.