This article describes the way to build a kernel right after installation, before the very first reboot. This has been performed on the request of the project leader, Matthew Dillon. I used a dual PIII-450MHz machine, and I have built an SMP kernel with pf, vlan and ALTQ features compiled-in. I used the latest PREVIEW ISO to date (20061228). No additional tools are needed. I performed a fresh installation. Prerequisities: you have to know how to create a custom kernel config and build a kernel. ## Part 1: Mounting the necessary filesystems, copying kernel sources, chroot-ing. First, boot the machine with the CD and perform a regular installation, but after configuring the system, do not reboot, just leave the installer and log in as root. Then you should mount the root filesystem to the ***/mnt*** mount point: # mount /dev/ad0s1a /mnt In ***/mnt***, you will have the root of your HD installation mounted. If you have enough space, you can copy ***/usr/src-sys.tar.bz2*** to ***/mnt***, or you can mount additional 'partitions'. Try this: # cat /mnt/etc/fstab You'll get an output like this: # Device Mountpoint FStype Options Dump Pass# /dev/ad0s1a / ufs rw 1 1 /dev/ad0s1b none swap sw 0 0 /dev/ad0s1d /var ufs rw 2 2 /dev/ad0s1e /tmp ufs rw 2 2 /dev/ad0s1f /usr ufs rw 2 2 /dev/ad0s1g /home ufs rw 2 2 proc /proc procfs rw 0 0 To mount the new home directory into ***/mnt/home***: # mount /dev/ad0s1g /mnt/home Then copy the kernel source tarball to the HDD: # cp /usr/src-sys.tar.bz2 /mnt/ There we go. But now the root is the CD's top-level filesystem and it does confuse the kernel installation (FIXME). Luckily, we can tell the operating system to use another mountpoint (or even a folder) as root. We just tell the system to use /mnt as root. # chroot /mnt Now your ***/*** is the root of your new installation. Then mount all the remaining partitions: # mount -a We are done with the first part. Let's just build the new kernel! ## Part 2: Unpacking the kernel source, building and installing the new kernel Go into ***/usr*** and unpack the kernel source tarball located in /: # cd /usr && tar xyfv /src-sys.tar.bz2 Then your kernel sources will be in ***/usr/src***. Now create a custom kernel config, I named it SMP and placed it into ***/root'. After you are done with configuring, comes the trickier part. To make sure the kernel and userland are in sync from a developmental point of view, you usually have to ***make buildworld*** before trying to ***make buildkernel***, and the tools from the freshly built world (# userland) are used to build the new kernel. But now you don't have the necessary source files to do the buildworld and if you are on a slower connection, it can take ages to fetch, let alone the build time (takes 4x or 5x of the kernel build time). Luckily you can build a kernel with the toolchain of your current system - the kernel and userland from the CD are in sync, aren't they? :) # cd /usr/src && make nativekernel KERNCONFDIR#/root KERNCONFSMP # make installkernel KERNCONFDIR#/root KERNCONFSMP Note: the ***nativekernel ***target can of course be used anytime, but the kernel and userland have to be in sync, otherwise if you make a kernel on top of an older userland, your system may become unusable. Done. Now get outta the chroot: # exit and reboot. Make sure to remove the install CD. Hint: you can perform this on a faster machine and place the HDD into the original machine afterwards if you are in a hurry. Be aware of the fact that SMP kernels won't boot on UP machines, though. ---- CategoryHowTo