Results 1 to 5 of 5
Hybrid View
-
01-19-2004, 08:45 AM #1Web Hosting Master
- Join Date
- Aug 2002
- Location
- UK
- Posts
- 852
Kernel Compilation Guide - Linux x86
Ok, I guess i'll write a series of tutorials as i've been the one pining for this forum for a long time.
Lets begin, basic compilation of the kernel
Step 1 - Get your kernel
Depending on your distribution, there are different ways to obtain your kernels:
- Redhat/Fedora - Supplied by the manufacturer, also available via rpmfind.net
- Debian - Provided in .deb format, either apt-cache search for it or check out the online repository
- Gentoo - Under the sys-kernel tree of portage (/usr/portage/sys-kernel/gentoo-sources is the more common ebuild)
- Any Linux admin can get kernel tarballs from http://www.kernel.org but they're plain vanilla, no optimisations for any distribution etc
- FreeBSD - Will be covered in a seperate tutorial
Step 2 - Unpack it
Ok, a handy lesson in the tar command to go along with this, for this example our kernel is called linux-2.4.24.tar.bz2. We can see this is a bzipped image so we use the following command to untar and unzip it:
tar xvjfp linux-2.4.24.tar.bz2
Here is a breakdown of this command:
- x - extract files from archive
v - be verbose about files (list every file extracted)
j - parse the file through the bzip2 decompressor
f - simply means, use the file supplied on the command line
p - preserve permissions (instead of creating files in reference to the umask.. If you are running as root this behaviour is default anyway)
You should run this command inside /usr/src/ .. This is the most common directory for source code compilation, you may need to provide a full path if the file is not present in that directory. You should end up with a directory labelled after the kernel, for example, /usr/src/linux-2.4.24/.
Step 3 - Symlink directory
You will need to link your current kernel source tree (which we just extracted) to /usr/src/linux .. this is to avoid clumsy searching and pointless configuration, the appropriate command is ln -sf /usr/src/<kernel directory> /usr/src/linux .. Absolute paths can be substituted depending on your preference. The s option indicates this link is symbolic only, the f option overwrites any old existing link.
Step 4 - Begin configuration
Assuming you have ncurses installed (which you should have regardless, hell it's a system utility on Gentoo), we will use the menuconfig setup (X users, substitute 'xconfig' wherever 'menuconfig' is mentioned, non-ncurses users use 'config')
First, change to the source tree's directory: cd /usr/src/linux
Second, start the menu configuration program: make menuconfig
Several compilations should occur then a nice menu should pop up with all your kernel options, these options will be discussed at a later date, for now we'll assume you know how to configure your kernel
Step 5 - Compilation
Once you have finished your configuration, exit and save your configuration file.
You will now need to run two commands, the first is make dep - this will make all the basic dependancies needed for the kernel. Please note, this is not required for 2.6 kernels
Once make dep has finished, you will need to build the rest of the kernel
2.4 kernels:
make bzImage modules modules_install - This will compile the kernel image (bzImage), the modules and also install the modules into /lib/modules/<kernel-version>/
2.6 kernels:
make && make modules_install - Does the same as listed before, just using the new modifications to the makefile
Step 6 - Install your kernel
This step is only generalised as it's impossible to predict how you want your kernel to be configured, plus how you have your bootloader setup, so here is how I do it.
Copy the kernel image into /boot, labelled appropriately: cp arch/i386/boot/bzImage /boot/kernel-2.4.24
Copy the System.map file into /boot, again labelled with the kernel version: cp System.map /boot/System.map-2.4.24
Copy the config you have used to /boot: cp .config /boot/config-2.4.24
This ensures you have enough information at any time to find the kernel version used and all configuration options, even if you have disabled /proc/config support and/or the kernel isn't running.
You should be able to reboot your system (after reconfiguring your bootloader) and boot quite happily into your new kernel
Not covered by this tutorial:
- FreeBSD Kernels
- Linux kernel configuration
- initrd usage
- vmlinux usage
- bootloader configuration
I will attempt to touch on these in the future.
-
01-19-2004, 03:15 PM #2Web Hosting Master
- Join Date
- Aug 2002
- Location
- UK
- Posts
- 852
Please move this to T+SI, it was intended for there.
-
01-22-2004, 06:45 PM #3Web Hosting Master
- Join Date
- Apr 2002
- Location
- Southampton, UK
- Posts
- 1,025
Several compilations should occur then a nice menu should pop up with all your kernel options, these options will be discussed at a later date, for now we'll assume you know how to configure your kernel
-
01-22-2004, 06:58 PM #4Web Hosting Master
- Join Date
- Aug 2002
- Location
- UK
- Posts
- 852
^^ I never said the assumption would hold true, it's just the scope of this howto does not cover kernel configuration, you could if you wanted copy /proc/config to /usr/src/linux/.config assuming your old kernel was compiled with /proc/config support in which case you'll use the same config as your old kernel used.
-
01-26-2004, 03:39 PM #5
Great newbie tutorial, only one thing that I can see missing:
First, change to the source tree's directory: cd /usr/src/linux
Second, start the menu configuration program: make menuconfig
First, change to the source tree's directory: cd /usr/src/linux
Second, configure all the old options into your new kernel configuration : make oldconfig
Third, set the dependencies thus far: make dep
Fourth, start the menu configuration program: make menuconfig
Adding oldconfig will ensure that you haven't left something out that was in the previous kernel compilation, which could be anything from custom drivers to, well more custom drivers (that's where most kernels fail is at the driver level). It's rather important that you make sure to get the "oldconfig" in there so that this doesn't happen.Tom Whiting, WHMCS Guru extraordinaire
Linux problems? WHMCS Problems? Give me a shout
Check out my WHMCS Addons