Rebuilding world under FreeBSD

Here is the procedure I usually follow to stay current with FreeBSD. All steps are well covered in FreeBSD Handbook already, but I just keep it here for my personal records.

Before we start, here is my /etc/make.conf:

CFLAGS= -O -pipe
NO_BIND= true
NO_GAMES= true

“CFLAGS= -O -pipe” option tells C compiler to perform some sort of optimization while compiling the code.

“COPTFLAGS= -O -pipe” – same as CFLAGS but kernel related.

“NO_PROFILE= true” option prevents C compiler from building profiled binaries, which is used for debugging purposes and increase the size of compiled code.

“NO_SENDMAIL/NO_BIND/NO_GAMES” are self-explanatory options. I don’t need sendmail, nor bind, neither games on my servers.

I assume you already have cvsup installed and you know what are you doing so you managed to get latest sources. Just for my records – I’m upgrading from FreeBSD 6.2-STABLE to 6.3-STABLE.

Start with the cleaning of /usr/obj. If this is your first installation, I mean you didn’t build world before, you can skip this part since /usr/obj should be empty.

cd /usr/obj
chflags -R noschg *
rm -rf *

Proceed with building of world. This is the most time consuming part. For a single-CPU computer it is recommended to use -j option to spawn several simultaneous processes. In case you own multi-CPU machine with SMP included you may try values from 6 to 10 to speed things up.

cd /usr/src
make -j4 buildworld

When finished, start with building your custom kernel. If you just installed your system from CD your kernel name is GENERIC (for a single-CPU) or SMP (for a multi-CPU) which includes many drivers/features you basically would never need or use. The GENERIC kernel contains everything necessary to boot your system up. The safest way recommended is to copy GENERIC kernel to some other file, name it differently and start editing it, like removing unnecessary drivers/features. I usually name the new kernel in a way that it contains hostname and the date I build it.

cd /usr/src/sys/i386/conf
cp GENERIC MX20080415
cd /usr/src
make -j4 buildkernel KERNCONF=MX20080415

Install the newly built kernel.

cd /usr/src
make -j4 installkernel KERNCONF=MX20080415

Time to reboot into single user mode to test our new kernel and install new system binaries. Select “single user” mode at the boot prompt. Do file system checks, mount all UFS file systems, turn swap on and install the world.

shutdown -r now

fsck -p
mount -u /
mount -a -t ufs
swapon -a

cd /usr/src
make installworld

Finally, update system configuration files (mainly /etc) by running mergemaster(8).


Tags: ,

Leave a Reply