[HOW-TO] Recompiling kernel


Recommended Posts

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.

  • 2 weeks later...
  • 2 months later...

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 ;)

  Danrarbc641 said:
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

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.

  • 9 months later...
  • 1 month later...
  Evolution said:
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.

  DjmUK said:
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...

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 :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They've been focusing on security and quality? Could have fooled me. Their own paying customers literally just got breached because they failed to push SharePoint updates downstream to on prem servers operating outside of their "365" ecosystem.
    • The animosity is unnecessary, when I opened the page I only saw one response which never mentioned your other steps, and when I hit reply it jumped straight to the bottom and again, I saw no other responses.  I was simply agreeing with the first comment that said yes, you should be fine if you erase its current operating system. Using another PC, or the copy of Windows that comes on that PC (former option is more trustworthy), download and run the Windows Media Creation tool.  It will walk you thru the process of downloading Windows and writing it to a USB stick.  It will even ask you at one point whether you're reinstalling it to the current machine or installing it on another machine. Then just boot the PC in question from that USB stick.  Usually spamming Esc, Del, F-8, F-9, F-10, F-11, F-12 or F-2 immediately after power on will bring up a boot menu, it varies by manufacturer.  If Windows starts booting you either missed your window or hit the wrong key. Follow the on-screen instructions.  When it gets to the disk formatting part I usually just delete all the partitions on the destination drive, then select the unpartitioned space as my destination.  The Windows installer will then automatically partition the drive as needed. Be prepared to download drivers from the PC manufacturer's website, they may not come bundled with Windows and you may not be able to use things like WiFi or ethernet until you have them.  They "might" work straight away, but they also might not.  Better to be prepared with a spare PC and a USB stick to transfer them over.
    • Wise Disk Cleaner 11.2.5 by Razvan Serea Wise Disk Cleaner is a free disk utility designed to help you keep your disk clean by deleting any unnecessary files. Usually, these unnecessary, or junk files appear as a result of program's incomplete uninstalls, or Temporary Internet Files. It is best if these files are wiped out from time to time, since they may, at some point, use a considerable amount of space on your drives. Wise Disk Cleaner, with its intuitive and easy to use interface, helps you quickly wipe out all the junk files. Using the program is indeed easy. It also works fast when both scanning for files and deleting files. The new Wise Disk Cleaner has more advantages: improved performance, better interface and scans/cleans more thoroughly. Wise Disk Cleaner Free provides lifetime free update service and Unlimited Free technical support. The first Slimming System software Wise Disk Cleaner is the first system slimming tool, which will help you to remove Windows useless files that you don't need, such as Korean IME, Windows Sample music, videos, pictures, Installers and Uninstallers of Updates Patches etc. Wise Disk Cleaner 11.2.5 Build 845 changelog: Added cleaning rules for Legacy Games Launcher, Letasoft Sound Booster, Macrium Reflect, MagicLine4NX, MAGIX Photostory, MakeHuman, Max Recorder, Maxprog iCash, Lexware, LG PC Suite, Lightworks, LINE, Listary, and LockHunter. Improved cleaning rules for Xunlei, PowerToys, Meitu, OneDrive, and Tencent Video. For security reasons, users can no longer delete the latest system restore point in the Restore Center. Enhanced System Slimming. Fixed minor bugs from the previous version. Download: Wise Disk Cleaner 11.2.5 | 6.9 MB (Freeware) Download: Portable Wise Disk Cleaner 11.2.5 | 7.3 MB View: Wise Disk Cleaner Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I keep getting ignored when I ask what you guys mean by nuke it. I described the steps and I keep getting the same generic instructions. Can you look at what I have posted multiple times already and validate what I have described? You can't assume everyone has your level of expertise and can interpret your nuking advice. After this many posts in this thread, I don't think we need the same generic advice about just nuke it and reinstall. It's already been said. So can you please outline the specifics? Made in Ukraine? Are you sure?
  • Recent Achievements

    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
    • Week One Done
      MoJo624 earned a badge
      Week One Done
    • Collaborator
      aeganwn earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      617
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      156
    4. 4
      +FloatingFatMan
      120
    5. 5
      Michael Scrip
      114
  • Tell a friend

    Love Neowin? Tell a friend!