• Sign in to Neowin Faster!

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

Sign in to follow this  

A Guide to Recompiling the Kernel

Recommended Posts

Ultra Frosty    0

Downloading and installing the kernel

The new kernel is quite easy to find and download. Follow these steps.

1. First, become root (use the: su command in a shell)

2. Go to The Linux Kernel Archives.

3. Download the Linux 2.6.xx kernel and save it to your /usr/src directory.

4. As root, run the following commands in the console. (Note: This assumes you've installed your Linux distribution with all the developer options. If you haven't, take a look at your distribution's website for more information on 2.6 kernel packages you can download.)

tar -zxvf linux-2.6.xx.tar.gz
cd linux-2.6.xx
make menuconfig

After your machine takes a bit of time to compose the menus, you should see the Linux kernel menu system. The menu gives you the ability to choose which options are included in your kernel. After choosing these options, you'll be able to compile your kernel.

Compiling the kernel

First, type in the following.

make bzImage

If you use LILO as your boot manager, then type the following.

make install

If you configured your kernel to use modules, which many people want to do, you'll need to type in the following command.

make modules
make modules_install

Hurry up and wait

If it's your first time building a kernel, keep the boot disk from the first time you installed your OS. It'll come in handy if you did something wrong when configuring your kernel!

Building the kernel can take a lot of time, depending on your machine's specs. Think in terms of at least a half-hour and you won't be far off. It's a big plate of spaghetti for your computer to munch on, so be patient.

The good news is that Linux is great at multitasking, so you can go surf the Web while the kernel compiles. And have fun!

Share this post


Link to post
Share on other sites
Keldyn    1

Not a bad guide. Perhaps if you could include a run down on the recommended options in the Linux Kernel Menu system? For newbies this can be a very daunting process. Remember. Always aim your guide towards first time users. Keep it as simplified as possible. Step by step instructions are a must!

Share this post


Link to post
Share on other sites
Dessimat0r    0

You should really symlink linux-* to linux using ln -s /usr/src/linux-* /usr/src/linux first.

I'm not sure if you break module compatability by not doing it.

Share this post


Link to post
Share on other sites
+John Teacake    454
tar -xzvf linux-2.6.0.tar.gz
for that bit my linux file is a .bz2 file ? Im a total noob at linux here and ive just decided to give this recompiling thing a go. Can anyone help me ?

Share this post


Link to post
Share on other sites
mercuryx013    0

Use jxvf instead of zxvf

Share this post


Link to post
Share on other sites
+John Teacake    454

I get Unexpected EOF in archive error

Share this post


Link to post
Share on other sites
CaKeY    0

I thought the one I posted here was a little more indepth.

Share this post


Link to post
Share on other sites
kongit    0

A couple of things:

1) you want to untar the file with

tar -xvjpf linux.whatever

or

tar -xvzpf linux.whatever

It keeps the permissions correct. I don't know if the p is necessary for compiling and using, but it is a good practive for kernels

2) With the latest 2.6 kernels you only need to type

make

after the menuconfig. It will make the bzlmage and the modules. then type

make modules_install

3) You don't need to symling to /usr/src/linux. This is for the kernel headers. Actually it is advisable to have this linked to an older 2.4 kernel or a 2.4 header set for backwards compatibility. It will not mess up compiling anything if you set it to a 2.4 kernel. However the 2.6 kernel's headers are slightly different than normally expected by the compiler and its libraries.

4) you can run

make install

for both lilo and grub if they are set right.

5) For the menuconfig I suggest that you get a listing of all your hardware on a piece of paper and make sure that it is very detailed. Additionally you need to check with the distro to make sure that you don't need to add in extra stuff to make that distro work right. I know you need to with gentoo.

6) lastly if you don't choose make install to install the kernel, don't overwrite the last one. and if you choose make install it will over write the last kernel installed if it has the same name. For example if you have installed a 2.6.3 kernel and want to change some things and don't do anything to the kernel source (ie add patches) and re make the 2.6.3 kernel and choose make install the original 2.6.3 kernel will be replaced with the newer one. However you can change this in the make file in the base kernel source directory. it is in the extraversion options. I suggest you patch the kernel source to see what I am talking about because most patches will change the append on the end of the image files and system map files.

7) I am sorry if I confused anyone. Compiling your own kernel isn't difficult. However you have to make sure you configure it correctly in the menuconfig. Wierd things can happen, and at worse a kernel panic. But these are all fixable. Try to have another kernel for just in case your new one fails. Then you can boot with it at lilo or grub and you can fix whatever error you made.

I get Unexpected EOF in archive error

Most likely you downloaded a bad kernel source. download a new one and try again.

Share this post


Link to post
Share on other sites
hornett    0

What about generate-modprobe.conf?

I've always had to do that in order to get everything working. Remember that you have to specify the output of the modprobe.conf file to the /etc dir tho.

Also I found make gconfig better than menuconfig, but I guess that is a matter of personal taste.

Share this post


Link to post
Share on other sites
HellBender    0

Did you write that guide?

Share this post


Link to post
Share on other sites
+John Teacake    454

I did all that and i dont see any difference.

Edit : As far as i know its still using my old (2.4) kernel. How do i tell it to use the new one ive just installed ? Any help would be greatly appricated.

Edited by Sawyer12

Share this post


Link to post
Share on other sites
CaKeY    0

from the console type uname -a

Share this post


Link to post
Share on other sites
+John Teacake    454

That just tells me what version kernel im using. It says its using the 2.4 version. Is there any way of telling Linux to use the 2.6 version ive just installed ?

Share this post


Link to post
Share on other sites
Ultra Frosty    0

You have to restart your system

Share this post


Link to post
Share on other sites
+John Teacake    454

Yeah Done that and theres no change :(

Share this post


Link to post
Share on other sites
hornett    0

Make install should of updated lilo or grub for you. What distro are you using?

Share this post


Link to post
Share on other sites
+John Teacake    454

Redhat, So are there any commands to use to tell linux to use the 2.6 kernel. Its created the 1.6 file in the /usr/src directory.

Share this post


Link to post
Share on other sites
hornett    0

I'm not an expert but, like I think that like I said, make install will usually update grub for you so that the new kernel is listed on the statup menu.

For example here is my /etc/grub.conf file:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: ?You do not have a /boot partition. ?This means that
# ? ? ? ? ?all kernel and initrd paths are relative to /, eg.
# ? ? ? ? ?root (hd0,4)
# ? ? ? ? ?kernel /boot/vmlinuz-version ro root=/dev/hda5
# ? ? ? ? ?initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,4)/boot/grub/splash.xpm.gz
title Fedora Core (2.4.22-1.2174.nptl)
	root (hd0,4)
	kernel /boot/vmlinuz-2.4.22-1.2174.nptl ro root=LABEL=/ hdd=ide-scsi rhgb
	initrd /boot/initrd-2.4.22-1.2174.nptl.img
title Fedora Core (2.4.22-1.2115.nptl)
	root (hd0,4)
	kernel /boot/vmlinuz-2.4.22-1.2115.nptl ro root=LABEL=/ hdd=ide-scsi rhgb
	initrd /boot/initrd-2.4.22-1.2115.nptl.img
title Windows XP
	rootnoverify (hd0,0)
	chainloader +1

You see I have two different linux kernel entries (2.4.22-1.2174.nptl?& 2.4.22-1.2115.nptl)?

You could try manually adding the new kernel to the grub.conf file but to me it sounds like the install has not worked properly as it has always done this itself for me.

Share this post


Link to post
Share on other sites
+John Teacake    454

So if i just tryed make_install again what would happen

Share this post


Link to post
Share on other sites
The_Geek    0

For LILO try running the $lilo command from the terminal see if this adds the kernel to your config

Alternate

-----------

1.Assumes that you have "root" or "sudo"

Take a look in the "/boot" partition or file path depending on how you partitioned your drive.

use the following from your terminal of choice

$ls -F /boot

See what you have got there and double check that with your grub.conf file.

<snip>

kernel /boot/vmlinuz-2.4.22-1.2174.nptl ro root=LABEL=/ hdd=ide-scsi rhgb

initrd /boot/initrd-2.4.22-1.2174.nptl.img

title Fedora Core (2.4.22-1.2115.nptl)

root (hd0,4)

</snip>

Your output from the "ls" command should be able to be matched to one of your kernel entries,

ie..

If you have kernel named vmlinuz-2.4.22-1.nptl in your config file you should also have a file named

vmlinuz-2.4.22-1.nptl in your "/boot" directory. If for some chance your kernel image is not listed in

your "/boot" directory search for it then move it to your /"boot" directory manualy.

#Update your locate database

$updated

#Search for the kernel image

$locate vmlinuz-2.6.* | less

See what you can find, use the up & down cursor keys to navigate to the end of the results or until you

find what you are looking for, if you find the kernal image then move it to the "/boot" directory.

$mv -r /file.name/path/to file /boot

Repeat the above steps for the initrd image.

Now double check that your conf file and your kernel images line up. Restart the box to see if you get an option for the kernel at boot.

Hope this helps,

The_Geek

Share this post


Link to post
Share on other sites
Juan4Ever    6

i did this question in other thread, but i guess i can repeat it here too because are pretty the same post...

wich is the diference in set to Built-in or Module on the kernel configuration when you enter the make menuconfig command?

that's all. thanks

Share this post


Link to post
Share on other sites
kongit    0

built-in compiles the part into the kernel. modules compiles the part as an externel module that can be loaded or unloaded at any given time given the correct circumstances. Some parts need to be compiled in otherwise you risk a kernel panic, most doesn't and you need to experiment with those to determine the optimum settings for your computer.

Share this post


Link to post
Share on other sites
hornett    0

Kongit - is there any speed advantage to using modules over compiled-in or do I have that back to front?

Specifically I'd like to improve the boot speed of the kernel as currently it takes 5 or 10 secs before my services etc start.

Share this post


Link to post
Share on other sites
turbomonkeycock    0

I got a kernel panic :oops: :D

Couldnt mount the hard drive or something, which i imagine is pretty serious :p Im sure it just needs a little bit more care and adaptation from me, and i'll try later, but if anyone has any tips that would be appreciated.

Oh, by the way, im using SuSE and have been told that i shouldnt of just compiled 2.6.0 randomly and needed a SuSE-adapted kernel. How correct is this? Sounds a load of rubbish to me

Share this post


Link to post
Share on other sites
kongit    0
Kongit - is there any speed advantage to using modules over compiled-in or do I have that back to front?

Specifically I'd like to improve the boot speed of the kernel as currently it takes 5 or 10 secs before my services etc start.

It depends. I for one have noticed no speed increase on boot with the exception of usb. I use hotplug (almost all distros do) so only the usb stuff that is plugged in at boot will be loaded. If you get your kernel properly configured and the modules that are supposed to load at boot properly configured then you will probably have the best in time for boot. However boot times for a normal linux user shouldn't matter as you stay booted for long periods of time.

It shouldn't make a difference between compiling in or as modules if everything is configured correctly for boot speed.

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.