bumbler
December 27th, 2005, 22:17
You've installed FreeBSD, and it works fine, of course. If you are as seriously committed to using it as your desktop as I am, you'll want to get the most out it. Let's go hardcore! The key with FreeBSD is optimization -- tweaking the compile process so the resulting binary code runs as efficiently as possible.

So you've got some decent hardware. Optimization has always been fairly easy with FreeBSD, but recent changes in version 6.0 have made it even better. Here's the concept: You use FreeBSD on the desktop or laptop. Set aside the time upfront to invest in the system, and the return over the next year or so will likely make you glad you did. Starting with around 500Mhz CPUs, the difference is noticeable. For CPUs above 1Ghz, the difference is often quite surprising.

This article assumes you have some sort of broadband access. Without, this procedure would require about two weeks, even if you have the time to nurse the system through the inevitable dropped connections. As it is, this can take up to three days with a fast connection. Also, you'll need to note much of this depends on having at least 1Ghz of CPU speed, and a half-gig of RAM. Lesser machines take much longer. More robust machines take less, and a large CPU cache makes a major difference. Also, unless you have tons of work files, 20GB of harddrive is plenty, and a 40GB will be huge. However, a faster harddrive will make the system faster, for obvious reasons.

Having installed FreeBSD at least two-dozen times, I tend to glance only rarely at my notes on the walkthrough (http://ed.asisaid.com/index.html#fbsd) The steps haven't changed much since the 4.x release series. You may need a more thorough review. However, given the goal of optimization, this will be rather different. We will install only the core system, rebuild and optimize that, then add the other userland packages from the latest sources. When we are through, the entire OS and all binaries will be optimized.

Preliminary Steps

Again, get it set in your mind this takes awhile. Once you begin adding the userland packages, there will be frequent occasions when you'll need to select options for a given item. This cannot be done unattended.

Up through the point of partitioning the disk and creating the file system, there's nothing new. However, when the prompt comes up asking you to select a "distribution" (pre-selected package collection), only take the bare minimum for building the core system. You want #4, "Developer" without X. Since I was working from the installation CD, I chose that source. After the congratulation message, you'll need to configure your Internet connection. You'll need this very soon.

When the message asks about ethernet or slip/ppp, choose "yes." The next window lists the various interfaces the installer thinks it can address. If you have an ethernet controller, much depends on the chipset and how it connects to your hardware. There are several dozen drivers already included in the FreeBSD kernel. Mine offered to use the interface rl0 (that's RL-zero), because my system has an onboard RealTek 8100 series chipset. If you don't see an option that describes the chipset for yours, you'll need to spend some time with Google, and I recommend you use keywords which include "freebsd" and the brand and model of your ethernet chipset. It is possible you can load the driver manually later, or you may need to compile in a special driver. While this is relatively painless for most things, it's beyond the scope of this article. I highly recommend you join a forum where there are plenty of experience BSD users.

You'll need to know what your ISP requires from you to connect. At a minimum you'll need to know whether to engage DHCP. For something like SBC/Yahoo DSL, that's about all you'll need. When the form pops up for the host information, most of it will be filled in correctly under DHCP. You'll need to give your machine a name. I suggest a simple four or five letter nickname in this pattern: name.local.bsd. If you have a fixed IP address and a legitimate host name, use that instead.

For the next few questions, I said "yes" only to the use of SSH. This makes it easier to transfer files between machines on the same local network (hint: man scp). Most everything else should be "no." Eventually you'll work your way to the option of adding pre-built packages from the CD. We need only three:


bash: I won't apologize for choosing the most user-friendly shell. If you become curious, read up on the others and try them out. Most desktop users prefer bash
cvsup-without-gui: This will allow you to download core system update code and update your ports tree.
pine: This package includes the pico editor, which is far simpler than anything else easily available in this situation.


Tell the installer you are finished and be ready to swap disks around. If you find you are missing disk 2, or it is unreadable, you can come back to this later. In fact, once you've done your first reboot, you can do it anytime using the command /stand/sysinstall, then changing your install source to FTP, as long as you know the exact FTP address you want to use. Once you have sysinstall running, take time to read the listed options, and you should be able to find that option, plus the option for adding packages. In my case, the installer couldn't read the cvsup-without-gui package. You'll see how I got it later.

In fact, the only thing left is adding your user account and setting the root password. Once you've done that, the installer asks if you wish to revisit any last install options. Select "yes" and you'll be back at the sysinstall main window. When I changed to FTP install source, in the blank line for FTP directory, I decided to use ftp.freebsd.org because for a single package, it shouldn't make too much difference whether you use a mirror close to you. Pay attention to the prompts, and realize you can always go back to the main sysinstall window and keep trying it over until you get it right. You can find more details here (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/install-media.html).

Optimizing and Building the Core

Your first boot should stop at the point of starting the SSH daemon by asking you to type random characters on the screen. Be sure you don't hit the key sequence CTRL-C nor the Scroll Lock in the process, as they can ruin the whole thing. Just use the main letter and number keys and hit ENTER when you have at least one line of random junk. The system will then create your SSH keys and come back to the login prompt.

Login as root. Keep in mind, at this stage we do everything from the console. First, let's configure make.conf. We'll copy the generic system default and modify it.

cp /usr/share/examples/etc/make.conf /etc/
pico -w /etc/make.conf

The pico editor will allow us to add compile-time options for the system in general. The basic standard C and C++ libraries allow for CPU optimizations. With each new generation, the processor manufacturer adds new commands to make the processor more efficient and powerful. You'll notice in the top of the make.conf file, we have a list of processors for which there are command-set optimizations in the libraries. Mine is a Pentium4, so I set the first CPU line like this: CPUTYPE=pentium4. If the list of choices offered confuse you, consider choosing simply i686 (unless you have an ancient 586 or AMD K5). Bench testing indicates the greatest improvement begins there, and anything fancier is only a small increment faster. However, if you know what you've got for sure, there's no harm taking it to the max. Also note, things in FreeBSD have advanced to the point where the general prohibition against optimization level 2 in the CFLAGS is no longer applicable. So I made that one like this: CFLAGS= -O2 -pipe. There are other possibilities, but you'll need more expert guidance for your purposes.

Now we need to update our source and ports tree. This is adequately covered elsewhere (http://ed.asisaid.com/cugbsd7.html) The only difference is, since we have no GUI, we use the cvsup command provided in the cvsup files:

cvsup -g -L 2 stable-supfile

for the system core, and similar for the ports-supfile. You should see displayed on the console a detailed report of what is being dowloaded. When finished, you'll see a Finished successfully, and the command prompt will return. Next, you'll need to navigate to the kernel configuration file and make some changes. That is also covered in the system update tutorial (http://ed.asisaid.com/cugbsd7.html). Make sure you don't get too zealous in deleting options in the kernel configuration. I once removed the da driver and couldn't mount any USB storage devices. You can find details here (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html).

I'll only outline here the steps to rebuilding the core system:

cd /usr/src
make buildworld
make buildkernel
make installkernel
reboot
shutdown now
cd /usr/src
make installworld
mergemaster
reboot

Don't be afraid to keep all that code in the /usr/obj/ directory until the next system update. Should you ever damage or corrupt part of your core system, it's a simply matter to run make installworld again and fix things. Upon rebooting, everything you have so far will be optimized. Next, we add uesrland stuff.

Adding the Desktop

Because we updated our ports tree, we can be comfortable we are getting the latest and greatest for FreeBSD. You can choose any desktop you want. For this exercise, I chose KDE, which is a common choice for home and small business users. Building KDE from source and optimizing can easily halve the time and resources required to run. Because the ports tree handles dependencies for us, we need not worry too much about all the niggling details. The shortest path is this:

cd /usr/ports/x11/kde3
make install

However, that adds components I won't use. The path I chose is probably not the shortest, but the one with which I'm most comfortable. I went through the ports tree and ran the build and install scripts for the following:

qt3.3
kdebase3
kdeadmin3
kdeutils3
kdenetwork3
kdepim3
kdegraphics3
kdeartwork3
kdemultimedia3
kdegames3

If you watch, you'll notice in the process you'll get some of the X.org packages built automatically as dependencies, and all of it will be optimized. However, to actully have a GUI on your machine, you'll need to add the following manually:

xorg-fonts-type1
xorg-fonts-75dpi
xorg-fonts-100dpi
xorg-fonts-miscbitmaps
xorg-server
xorg-wrapper
dri (if your graphics chipset is capable of 3D rendering)
urwfonts-ttf
webfonts

If you own any version of Windows on CD, you can add an option to that last one when you make install:

make WITH_MSLICENSE="YES" install

and it will add the Tahoma fonts. Other packages you might consider, based on your desktop use habits:

mozilla
mplayer
mplayer-plugin
mplayer-skins
kmplayer
nedit
elinks
joe-devel
lynx-ssl
mc

Notice many of these will also pull in various dependencies. The last package of significance I added was OpenOffice. Since I really don't like the bloat in version 2.0, I went with 1.1.5, which is found in the ports tree: /usr/ports/editors/openoffice.org-1.1. By itself, this takes some 12 hours or more. Because the developers haven't worked too hard at enabling optimizations, you won't get anything fancier than i686 ("pentiumpro"), though. If you have a 64-bit CPU, the code must run in 32-bit mode.

Once you've finished building all your chosen packages, you will have spent at least two days most likely, and it's time to run the last configurations. Setting up the X.org server is covered elsewhere (http://ed.asisaid.com/cugbsd0.html). However, you can't do any of this from sysinstall any more. It's simplest, in my opinion, to run /usr/X11R6/bin/xorgcfg -textmode and follow the instructions on the screen. Also, don't forget to configure fonts (http://ed.asisaid.com/cugbsd1.html).

It's simplest to test the configuration while still logged in as root. First, type cd by itself to return you to root's home directory. There, create a file that starts KDE automatically:

cd
pico .xinitrc

Type in this line: exec /usr/local/bin/startkde, then hit ENTER because configuration files in BSD must have one blank line at the bottom. Save and close. Then try the command startx and see what happens. If it fails and you have no idea what to do, see your friends on a BSD forum, or you can contact me and I might be able to help.

molotov
December 28th, 2005, 03:07
A very good, comprehensive write up!

Three notes:
-tcsh is plenty user friendly! I just personal preference I guess =)
-I would suggest deleteing /usr/obj before updating, it can cause problems if you dont. That is covered elsewhere though, so its a minor point.
-For a lightweight office, AbiWord rocks.

On an side, check out the comments in the source of your network card driver sometime when youre bored, they're pretty amusing.

bumbler
December 28th, 2005, 14:13
Yes, I like Abiword, too. I'm finding they are just now getting around to making some of the features more convenient. Not so long ago, Ted was actually easier and more useful. The drawback is Abiword pulls in a huge amount of dependencies. I dislike a lot of Gtk/Gnome structure when it comes to dependencies. It seems too extravagant for what you get back in terms of functionality. Still, I often recommend Gnome Office for laptops running less than an 800Mhz CPU. On my old 266 laptop, I use Ted.