Wednesday, June 16, 2010

Recompiling the Freebsd Kernel

This is a guide on how to compile your own custom freebsd kernel. Now some people say why would you want to do that. :p There may be two main reasons as to why you would want a custom kernel on your system: 1) You want to add some functionality to your system such as bluetooth or audio support, or 2) you may want to remove some unused drivers to conserve memory.

Either way, making a custom kernel will help your machine to be a faster box rather than using the GENERIC kernel.



Installation

We will want to use sysinstall to get the src:
# sysinstall

1. select Configure
2. select Distributions
3. select src
4. select sys (/usr/src/sys (FreeBSD Kernel))
5. press Enter
6. press Enter
7. select CDROM (Or choose FTP if you chose NOT to install from CDROM)
8. select Install

This will take a few minutes to install via CDROM.

Configuration

Once you have the source installed we can then start on the kernel customization:
# cd /usr/src/sys/i386/conf

This is where FreeBSD keeps its kernel configuration files for Intel computers. The generic kernel config is in the file GENERIC. All the possible kernel options can be found in the NOTES file. What we will want to do first is copy GENERIC to a new Kernel name.

Note: *NEVER* edit the GENERIC file.
# cp GENERIC MYKERNEL

A few notes about editing your new kernel file:

1) Here is an example line from the kernel
device ppbus # Parallel port bus (required)

Any line that says (required) means exactly that. Don’t comment it out or delete it. So in this example, you can delete everything below that section if you don’t have a Printer, TCP/IP over parallel, or a Parallel port interface device.

2) Don’t delete any lines. Comment them out with a # in the front.

3) Always change your ident line as follows

Scroll down the line that reads:
ident GENERIC

Change the line to read:
ident MYKERNEL

4) If you’re not sure what you have or don’t have for devices, you can check this in /var/log/messages (provided it hasn’t been forever since your last reboot).

This is a great example. There are a ton of Network Card drivers in the kernel and you really only need one. Let’s look in /var/log/messages for your Ethernet Card. I’ll use my NIC as an example:
fxp0: port 0xec00-0xec3f mem 0xdf100000-0xdf100fff,0xdf000000-0xdf0fffff irq 11 at device 9.0 on pci0

So if we edit MYKERNEL and scroll down to the PCI and make sure you keep the following lines in there and comment everything else in the PCI and ISA Network card sections:
device miibus # MII bus support
device fxp # Intel EtherExpress PRO/100B (82557, 82558)

So go ahead and make all the changes from there.

Once you are done, it’s time to compile the kernel.
#
# cd /usr/src
make buildkernel KERNCONF=MYKERNEL

If you get some errors you screwed up. Go fix it or copy GENERIC back to MYKERNEL and start over. If not, you can continue by installing the kernel.
# make installkernel KERNCONF=MYKERNEL

You are done! You should reboot to make the changes effective!

After the reboot you should see that you are on the new kernel.
# uname -a
FreeBSD beast.local x.x-XXXXX FreeBSD 6.X-XXXXX #0: Day Mon XX XX:XX:56 EDT 2006
USER@beast.local:/usr/obj/usr/src/sys/MYKERNEL i386

No comments:

Post a Comment

Cracking Kerberos Service Tickets (TGS) Using Kerberoasting

As of late I've been spending a lot of time researching and learning different techniques when it comes to attacking Active Directory En...