• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

Sign in to follow this  

[HOW-TO] Recompiling kernel

Recommended Posts

muskratattack    0

Anyone know where I can find a really good guide to kernel compiling. I've searched the net but could only find old, crappy ones

Share this post


Link to post
Share on other sites
CaKeY    0

Part 1

In the bowls of your /usr/src directory you will find your kernel source in the /linux dir. Most often it's a symlink to another dir that has the linux verson number attached.

For starters lets become root and enter the dir. I'll show you what I have

bash-2.05$ su
Password:
bash-2.05# cd /usr/src/
bash-2.05# ls -la
total 64192
drwxr-xr-x    9 root     root         4096 Jul 13 15:43 .
drwxr-xr-x   19 root     root         4096 Jun 26 15:48 ..
lrwxrwxrwx    1 root     root           12 Oct  7  2002 linux -> linux-2.4.18
drwxr-xr-x   14 1046     console      4096 Sep  1  2002 linux-2.4.15
drwxr-xr-x   14 573      573          4096 Apr 27 15:55 linux-2.4.18
-rw-------    1 root     root     30108170 Oct  7  2002 linux-2.4.18.tar.gz
drwxr-xr-x   14 root     root         4096 Aug 31  2002 linux-2.4.5
drwxr-xr-x    7 root     root         4096 May 29  2001 rpm

now you can see that I have three kernels floating on my HD. 2.4.5 2.4.15, adn 2.4.18. The linux link is pointing to 2.4.18, my current running kenrel

bash-2.05# uname -a
Linux naru 2.4.18 #5 Fri Jan 10 01:59:23 CST 2003 i686 unknown

Now before we do *ANYTHING* we will want to copy the current kernel config from the current kernel dir. This will make a backup of you config in case anything goes funny. Also we can use it for the new kernel we will be getting. It makes upgrading much less of a pain.

bash-2.05# cp linux/.config .

You can list the contents of the .config file, and you can see what it currently configured on your system. Now what we do is download a new kernel from kernel.org or your favorite mirror.

If you don't know how to download a tarball, you shouldn't be compiling a kenrel

Let look at my dir now.

bash-2.05# ls -la
total 64192
drwxr-xr-x    9 root     root         4096 Jul 13 15:43 .
drwxr-xr-x   19 root     root         4096 Jun 26 15:48 ..
-rw-r--r--    1 root     root        31560 Jul 13 15:42 .config
lrwxrwxrwx    1 root     root           12 Oct  7  2002 linux -> linux-2.4.18
drwxr-xr-x   14 1046     console      4096 Sep  1  2002 linux-2.4.15
drwxr-xr-x   14 573      573          4096 Apr 27 15:55 linux-2.4.18
-rw-------    1 root     root     30108170 Oct  7  2002 linux-2.4.18.tar.gz
-rw-------    1 halkun   users    35475346 Jul 13 15:42 linux-2.4.21.tar.gz
drwxr-xr-x   14 root     root         4096 Aug 31  2002 linux-2.4.5
drwxr-xr-x    7 root     root         4096 May 29  2001 rpm

Ok, we have the kernel, now let's nuke the old linux symlink. After we do that we untar the new kernel and make a new symlink that points to that.

bash-2.05# rm linux
bash-2.05# tar -xvzf linux-2.4.21.tar.gz
............(it uncompresses)............
bash-2.05# ln -s linux-2.4.21 linux

Let's do a dir again, just to make sure everything is spiffy

bash-2.05# ls -la
total 64196
drwxr-xr-x   10 root     root         4096 Jul 13 16:04 .
drwxr-xr-x   19 root     root         4096 Jun 26 15:48 ..
-rw-r--r--    1 root     root        31560 Jul 13 15:54 .config
lrwxrwxrwx    1 root     root           12 Jul 13 16:04 linux -> linux-2.4.21
drwxr-xr-x   14 1046     console      4096 Sep  1  2002 linux-2.4.15
drwxr-xr-x   14 573      573          4096 Apr 27 15:55 linux-2.4.18
-rw-------    1 root     root     30108170 Oct  7  2002 linux-2.4.18.tar.gz
drwxr-xr-x   12 root     root         4096 Jul 13 16:04 linux-2.4.21
-rw-------    1 halkun   users    35475346 Jul 13 15:42 linux-2.4.21.tar.gz
drwxr-xr-x   14 root     root         4096 Aug 31  2002 linux-2.4.5
drwxr-xr-x    7 root     root         4096 May 29  2001 rpm

Yup, it's pointing to the new kernel now, so let copy out old config in there and then get out fingers really dirty by going in!

bash-2.05# cp .config linux
bash-2.05# cd linux

Part 2

Ok, now we need to set up and compile the puppy. The first thing you should do is run a config program. What this will do is read in your .config and set up everything.

Now what I would do, as this was just a dry run, is simply let it parse the .config and then save it. This will update the .config with any new items that the new kernal has, compleating it. It will also keep our original config intact.

bash-2.05# make menuconfig
(press alt-E to exit, it will as if you want to save your new kernel configuration. Say yes)

Now that we have a config, we need to clean it all up and compile it out

bash-2.05# make dep
(...works for a bit and it creates some stuff....)

bash-2.05# make modules
(...works a bit more, makes all the loadable modules...)

bash-2.05# make modules_install
(...copies all the modules into a new /lib/modules/2.4.21 dir)

bash-2.05# make bzImage
(...go get a sandwich, wash the car, and come to Maine to visit. It may be done by the time you get back...)

Now you will have a compiled kernel. The last bit is getting it to boot.

Part 3

Now that we have a kernel lets grab it, let the bootloader know about it, and then do a reboot.

The kernel (bzImage) is tucked away in /usr/src/linux/arch/i386/boot. We need to put that in a more appropoate place and rename it as to not to cause confusion. It should go in your /boot dir.

bash-2.05# cp /usr/src/linux/arch/i386/boot/bzImage /boot/bzImage-2.4.21

Now you need to copy your system map so the new kernel can find functions within iteslf correctly.

bash-2.05# cp System*.map* /boot/

Now that that's done, let's config lilo, so the bootloader knows about the new kernel. This requres a littel know-how, not bad though. Everyone's lilo config is diffrent, but's it easy to navigate.

You are going to want to add these lines at the bottom

     image=/boot/bzImage-2.4.21
      label=newkernel
      root=/dev/hda1
      read-only

also make sure that there are these lines in there

prompt
timeout 50

the number after timeout is how many tenths of a second to wait for imput, it's set here to 5 seconds. Also make a note of what you old kernel's name is. You may need to boot back into that.

then RUN LILO

bash-2.05# lilo

that will tell you what kernels are installed and any updates will have a star before them

*newkernel

Now what you do next is cross your fingers, reboot, and at the lilo prompt type "newkernel" That should boot up your new kenrel!

If something goes wrong No worries! You can just put in the other kenel's label (usally "Linux" by default) and it will load the old one like nothing ever happened. Then you can fix what went wrong where.

That's it. I hope I was a help.

Share this post


Link to post
Share on other sites
Keldyn    1

Please leave this section of the forums for HOW-TO's & FAQ's only. All questions are to go in the main Linux forum.

Share this post


Link to post
Share on other sites
Juan4Ever    6

just one question... which is the diference in set to Module and built-in when you configure the kernel after making the make menuconfig command?

Share this post


Link to post
Share on other sites
Danrarbc    1

A module is something built into a file seperate from the kernel, useful for when you need support for something but you only need to use it occasionally - keeps the kernel a little smaller. Don't build support for your root file system as a module for instance ;)

Share this post


Link to post
Share on other sites
Juan4Ever    6
A module is something built into a file seperate from the kernel, useful for when you need support for something but you only need to use it occasionally - keeps the kernel a little smaller. Don't build support for your root file system as a module for instance ;)

then support for ext3 should be set built-in for better perfomance.

i guess my hardware like my videocard should be set built-in too, right?

thanks

Share this post


Link to post
Share on other sites
kongit    0

support for your filesystem should be built in so you know it works. This isn't true for modules for your vidcard, usb, etc. There are a few essential modules that should be compiled in, while most parts can just be modules. Normally you won't notice any difference in performance between modules and compiled in parts, however some people do. You just got to experiment.

Share this post


Link to post
Share on other sites
Evolution    16

Can anyone post a guide that actually works and is relevant for the 2.6 kernal? I've followed all the steps in the initial post, and I'm still using 2.4...

Share this post


Link to post
Share on other sites
DjmUK    0
Can anyone post a guide that actually works and is relevant for the 2.6 kernal?  I've followed all the steps in the initial post, and I'm still using 2.4...

585374426[/snapback]

Theoretically this guide will work with a 2.6 kernel. I'm aware this reply is late considering you posted in Jan '05 - but I'm just getting back into Linux.

I will try this guide out on the 2.6.11 kernel once FC3 is completely installed (had to wipe because I screwed it up by playing). As soon as it's complete I'll come back here and let ya'all know.

Share this post


Link to post
Share on other sites
Evolution    16
Theoretically this guide will work with a 2.6 kernel. I'm aware this reply is late considering you posted in Jan '05 - but I'm just getting back into Linux.

I will try this guide out on the 2.6.11 kernel once FC3 is completely installed (had to wipe because I screwed it up by playing). As soon as it's complete I'll come back here and let ya'all know.

585566114[/snapback]

That's ok, I know how to compile a kernel....that post is very old heh, and the very same day I knew how to compile completely :) However...a lot of those commands are now deprecated with the new kernel...

Share this post


Link to post
Share on other sites
DjmUK    0

Well, I couldn't get it to work - everytime I bunzipped that .bz2 file, I was left with a single file where I couldn't do anything with it.

I ended up downloading the rpm of 2.6.10 - which installed fine. Give it a couple of weeks (hopefully) and 2.6.11 will be available in rpm format :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.