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:

  1. CFLAGS= -O -pipe
  2. COPTFLAGS= -O -pipe
  3. NO_PROFILE= true
  4. NO_SENDMAIL= true
  5. NO_BIND= true
  6. 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.

  1. cd /usr/obj
  2. chflags -R noschg *
  3. 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.

  1. cd /usr/src
  2. 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.

  1. cd /usr/src/sys/i386/conf
  2. cp GENERIC MX20080415
  3. cd /usr/src
  4. make -j4 buildkernel KERNCONF=MX20080415

Install the newly built kernel.

  1. cd /usr/src
  2. 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.

  1. shutdown -r now
  1. fsck -p
  2. mount -u /
  3. mount -a -t ufs
  4. swapon -a
  5.  
  6. cd /usr/src
  7. make installworld

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

  1. /usr/sbin/mergemaster

Tags: ,

Leave a Reply