So, how are you liking FreeBSD? Do you believe it's something you work with, live with day after day? If you find you've gotten used to it, maybe the time has come to get more acquainted with one of the best features of FreeBSD: It's relatively painless to update the entire system by rebuilding it from code. The emphasis is not so much slavishly chasing the cutting edge of BSD technology. Instead, our focus will be on security updates and optimization.
One of the major selling points with FreeBSD is security. How silly it would be if we didn't do the minimum necessary to insure it stays secure. FreeBSD coders are some of the best on earth, but if perfect software could be written, no one could afford it. From time to time, flaws are discovered after the product is released. Fixes are often released within 24 hours of discovering a flaw, when it comes to core system files. Ported add-on packages may take longer. The core system fixes are seldom offered as a new package built and ready to download. You will have to download a patch, apply it and rebuild the flawed binaries from source. Occasionally, a flaw will affect the whole system base and will require rebuilding the whole thing.
Which brings us to the issue of optimization: Rebuilding the system base is a good idea in the first place, simply because it offers the best opportunity to make your system run as well as it can. When you install FreeBSD from a CD-ROM, you are getting generic binaries with the lowest level of optimization. Virtually everyone who tries a rebuild will swear it makes things better. The effects of optimizing become obvious in two ways. One, when the system is being optimized, successive rebuilds take less and less time. On most hardware I've tested, it's still rather dramatic for at least the first three times. Second, when you later update your desktop from source, it runs quite a bit faster. It is especially noticeable on something like KDE.
While this sounds like a major task fraught with risk, it really is quite simple. The good folks of FreeBSD have made it so easy. Even when one considers doing an upgrade using a slow dialup connection, you can be sure the time factor is reasonable, and the results well worth it.
Most recently I ran this procedure on an AMD K8 system running in
32-bit mode. However, I've worked with far slower hardware back in the
4.x days, and the effects were still worth the time and trouble. At
each step of the way, I took the defaults whenever possible. Please
note that the only tweaking I chose to do was in
/etc/make.conf, selecting to optimize on "k8" as
the CPUTYPE, because my CPU is a Sempron-64. By reading the notes in
the file above that line, you can determine the best match to your
processor. Further, I added a line for optimizations in the way C code
is compiled, with the line
CFLAGS= -O2 -pipe. Most likely
you will first have to copy that file from
edit. Naturally you'll have to be logged in as
alter system files.
Here is the process, step by step.
csup is bundled in by default.
Log in as root and navigate to
/usr/src/share/examples/cvsup. There you will see several
files which you can copy and modify for use. Our interest here is the
stable-supfile. Copy it to
open in your favorite text editor. Two main items here. Go down to
where you see:
You need to change this to a mirror that is presumably near you so
that you can get a fast and strong connection. The list of mirrors can
be found at
near the bottom of the page. The list shows about 18 mirrors for the US
alone. If you know how to use the
ping command, you can
time the response to find the one CVSup server which will serve you
quickest. Most of the time, it should be sufficient to look for the one
geographically closest, by using the
host command to
identify where each mirror was hosted. Mine ended up with:
A few lines down, I made sure there was one like this:
*default release=cvs tag=RELENG_6
This keeps me up to date with the latest code for the 6.x branch of
FreeBSD; as of this writing the latest stable version is 6.2. Save the
file and close. From the same source of example files, copy the
refuse file over to
/usr/sup (create the
directory the first time). This file keeps you from downloading a horde
of listings for language-oriented packages you probably won't use.
Check to make sure you approve of what's refused in the file, then save
2. Be sure you are connected to the Internet, but
csup as root. Simply type on the commandline:
csup -g -L 2 stable-supfile
This runs on the CLI completely. By adding the switches in the middle of that line, you get a chance to see some details of the operation. Once connected successfully, you'll see a bunch of lines stating what's happening. Watch, if you have time. On dialup, it's common to be finished in 20 minutes or less, downloading the difference between the source files one version and another.
3. When finished, the command line will return with a message about being successful. Dialup users drop your connection to the Internet at this point. Now is a good time to close down applications, shut down the X server, and work in the console. This will allow your system to devote maximum resources to the work of rebuilding. On the console, log out of your user account and login as root.
Navigate back to
/usr/src. Issue the command:
This took my system an hour the first time. Naturally, your mileage
may vary. If there are going to be any problems, this is where you are
most likely to see them. However, they are extremely rare. If it fails,
you'll get an error notice that you can copy and paste in a message
asking for help. The Handbook page
will provide the necessary details. As long as you have not installed
anything from a failed buildworld, you can simply resume using your
system as before.
What happens is that a script will tell your computer to rebuild the newest version of the basic C libraries, install themselves, then build again for optimization, and install themselves again. Then the rest of the system is built.
4. Of course, you'll need to update the kernel, too. But since nothing new has been installed, you can't use the Handbook instructions for building a kernel the normal way. You have to use the script:
This took 15 minutes for me, but was faster when I went back and built a custom kernel from the update. For now, we won't do customizations. Let's just stick with the trusted generic kernel, because you'll need to keep an updated generic kernel on hand for emergencies.
5. When building is finished, and there's no problems, run the command:
The installation should be pretty quick. When it's finished is the time to reboot and see if everything works with the new kernel. Go ahead and run the X server, use your peripherals such as soundcards, CD drives, etc. When you are satisfied all is well, close all the applications and drop back to the console mode.
6. Next, drop down out of regular run mode into single mode. On FreeBSD, this is very easy; simply type:
By leaving out the switches for shutdown, such as
-r (reboot), you are telling shutdown to go into
single mode. This means you are pulled back out of the system, as it
were, running only the absolute minimum. The reason we do this it that
it's not wise to have programs running while replacing them. Now it's
safe to install your new base system:
This will take a few minutes. When it's finished, we have one more step before running our new system.
mergemaster from the
commandline so that you can compare all our old config files with the
new defaults. Often a system update will include changes to the layout
of the config files, and the old ones may not work properly in the new
system. Mergemaster will show you the differences line-by-line using
minus (-) for what the old looks like, and plus (+) to indicate how the
new one is different. Read the prompts on the screen and decide what
you want to change. For the most part, I've always accepted the changes
offered, unless it's a file I've changed manually. I keep a written
record of changes I make to the various config files on my system in
case I miss one at this point, but with care you can figure out how to
merge a new file with your customizations. Naturally, I'll check the
manpages and read the comments in the config files in case there's a
new option I like, or an old one is removed.
Now we're done and ready for the first test run:
In a couple of minutes, I was back up. The X server started a little faster, and everythinge else was snappier.
Next time you install a system, especially with a recent release, consider just getting the base system installed, then running the buildworld process (minus update) to optimize everything before going any further. The primary difference this makes is that anything you compile afterwards will compile quite a bit faster, because the system libraries already have been optimized.
Ed Hurst is associate editor of Open for Business.