hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : Hosting Security and Technology Tutorials : Kernel Compilation Guide - Linux x86
Reply

Forum Jump

Kernel Compilation Guide - Linux x86

Reply Post New Thread In Hosting Security and Technology Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-19-2004, 08:45 AM
Winkie Winkie is offline
Web Hosting Master
 
Join Date: Aug 2002
Location: UK
Posts: 846

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.



Sponsored Links
  #2  
Old 01-19-2004, 03:15 PM
Winkie Winkie is offline
Web Hosting Master
 
Join Date: Aug 2002
Location: UK
Posts: 846
Please move this to T+SI, it was intended for there.

  #3  
Old 01-22-2004, 06:45 PM
stephenM stephenM is offline
Web Hosting Master
 
Join Date: Apr 2002
Location: Southampton, UK
Posts: 1,023
Quote:
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
Somebody who knows how to configure a kernel in the first place surely doesn't need to know how to unpack/compile it?

__________________
Regards,
Stephen Marsh ServerForce Ltd - AS39332

Linux Virtual Servers | Windows Virtual Servers | Managed Hosting | Web Hosting | Reseller Web Hosting | Dedicated Servers

Sponsored Links
  #4  
Old 01-22-2004, 06:58 PM
Winkie Winkie is offline
Web Hosting Master
 
Join Date: Aug 2002
Location: UK
Posts: 846
^^ 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.

  #5  
Old 01-26-2004, 03:39 PM
twhiting9275 twhiting9275 is offline
Just me
 
Join Date: Sep 2002
Location: Among the corn
Posts: 10,472
Great newbie tutorial, only one thing that I can see missing:
Quote:
First, change to the source tree's directory: cd /usr/src/linux
Second, start the menu configuration program: make menuconfig
should be
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.

Reply

Related posts from TheWhir.com
Title Type Date Posted
Core Infrastructure Initiative Provides Funding to Improve OpenSSL Security Web Hosting News 2014-06-02 16:01:16
Linux Kernel 3.10 Sees Most Developer Contributions Ever Web Hosting News 2013-09-16 13:17:24
UK Tech Blog Challenges CloudFlare, Web Hosts on Free Speech Blog 2013-08-12 10:32:52
The Linux Foundation Partners with Xen for Open Source Cloud Project Web Hosting News 2013-04-15 15:19:00
DreamHost-Connected Cloud Storage Spinoff InkTank Joins Linux Foundation Web Hosting News 2012-08-28 16:20:56


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?