FreeBSD updates

September 2, 2009

I updated couple of FreeBSD machines to test out the latest sources. This is my notes on doing the updates “the right way”! This is based on the Handbook (which is a great reference BTW). These are the steps.

1. Install CVSup and portupgrade.

Installation of these programs can be done via the usual pkg_add mechanism or via ports. To add via pkg_add, do this:

$ pkg_add cvsup
$pkg_add portupgrade

That's it!

If you want to install via the ports directory:

$ cd /usr/ports/net/cvsup
$ make install && make clean

$ cd /usr/ports/ports-mgmt/portupgrade
$ make install && make clean

2. Edit the cvs-supfile

cvs-supfile is the input file for CVSup. You can find an example file in /usr/share/examples/cvsup/cvs-supfile. You will need to edit this file to let CVSup know which parts of the source needs to be updated. These were the edits I did on the file:

Change host to cvsup.FreeBSD.org.

Next, you need to edit the major portions of that file.

They are: Sources, Ports, Documentation, WWW, Projects, CVSROOT. I used “src-all” and “ports-all” and disabled the rest. It is really advisable to update all the sources. If you update parts of source tree, it might result in unpredictable behavior. Updating all the sources is well worth the time. I think updating ports is also well worth the time. Remember that updating ports just downloads all the info files (like Makefiles, patches etc) and not the actual sources (I will talk about actual install of updated ports in a while).

3. Update sources and ports

This step downloads all the latest sources and ports configuration files. Its straightforward. Use this command:

$ cvsup -g -L 2

This will take a while. So, go ahead, get some coffee.

After all the files are downloaded, you need to build world (compilers etc) and kernel.

4. Reboot to single user mode

It is recommended to build world and kernel in single user mode. This will obviously speed things up and won’t mess with the configuration files in /etc directory, for instance.
After rebooting in single user more, you need to manually mount all the UFS file systems. These are the steps:

$ fsck -p

This runs file system checks on all UFS systems to make sure they are consistent.

$ mount -u /

This remounts the root file system with read/write permissions.

$ mount -a -t ufs

This mounts all the UFS file systems on your machine.

$ swapon -a

This turns all the swap partitions on.

5. Build world

This step is very important. Before updating any ports, you need to rebuild world. This will rebuild the kernel, compilers, and other utilities (like files in /sbin/ /usr/sbin etc). Before you rebuild world you need to look at /usr/src/UPDATING file. This file will have notes on any issues with the latest kernel sources or compilers.
The most important part is to rebuild kernel with the latest compiler sources. So, you will have to first rebuild the compilers first! These are the steps:

$ cd /usr/src
$ make buildworld

This will build the compilers and place them in /usr/obj. This will take a while, obviously.

Now, you are ready to build and install the new kernel with the compilers from /usr/obj. It is very simple! This kernel, however uses the standard configuration file. If you have your own configuration file, you need to specify with KERNCONF option. Please also not that the standard configuration file will include options to enable debugging. Please turn it off if you don’t need them.

$ make kernel

Now, reboot the machine to single user mode. After the machine reboots, please mount all UFS partitions as in step 4. In the next step we will be installing world (meaning all utilities like compilers, editors etc).

6. Install world.

Installing world is straightforward.

$ cd /usr/src
$ make installworld

This will copy all the files from /usr/obj/. After this step, you can remove this directory.

$ cd /usr/obj
$ chflags -R noschg * (Recursively remove all the immutable flags)

The next step is to update files in /etc

7. Updating files in /etc

This step is needed to update various configuration files in /etc directory. You would use a Bourne script utility called mergemaster.sh. On my system, I didn’t make any changes to /etc directory. So, I just accepted the new changes.

$ mergemaster

Not that in this process you will be presented with diffs for all the /etc files that need to be updated. This can be a bit tedious, but you have to do it anyway. On my system, I accepted all the diffs for the new files.

You are done now. You can reboot to multi user mode now. Next, we update all the ports.

7. Update the ports database

Before you update the ports database, make sure you read /usr/ports/UPDATING. This file will usually enlist any issues in the current development branch.

In this step, you would update the ports database with the new ports that we downloaded during the CVSup stage. This creates a new /usr/ports/INDEX.db file

$ portsdb -Uu

Depending on the number of ports you have installed, it will take a while for this command to run. So, please be patient!

8. portversion

portversion is a tool which compares the installed ports with the updated database and outputs them with either “=” sign (meaning no updating needed) or “<" sign (meaning the port needs upgrade). To see the ports that need to be updated, use this command:

$ portversion -l “<"

9. Update the ports.

Finally! This step will update all the ports.

$ portupgrade -arR

This command recursively updates all the ports. This step will obviously take a while.

You are almost done now!

10. Sync with the packages database

It is a good idea to sync your ports database with the packages database. It is very simple.

$ pkgdb -F

This is an interactive command. It will ask if any obsolete packages need to be deleted. I didn’t have any obsolete packages on my machine. If you want this to be done automatically, use this command

$ pkgdb -fu

Now you are done!