linux

legion...

Articles

navigate

Compiling a new kernel

// Next »

Get the kernel source

Download the latest (or older version if desired) from “The Linux Kernel Archives.” The file is available to download in either tar.bz2 or tar.gz formats. The tar.bz2 files are smaller in size for those who need a quick download or have limited storage space.

N.B. You will need to be root to do most of these steps

Save the file to the /usr/src directory.

Installing the kernel source

Copy the downloaded file to /usr/src IF you didn’t download it to that directory copy the file there and change directories:
# cp /path/to/the/file/linux-2.6.18.tar.bz2 /usr/src && cd /usr/src

You can string commands together by using ‘&&’ between them.

Now extract the file inside /usr/src. For a tar.bz2 use this command:
# tar xfvj linux-2.6.18.tar.bz2 /usr/src
For tar.gz use:
# tar xfvz linux-2.6.18.tar.gz /usr/src
A new folder is created called linux-2.6.18. We need to create a symbolic link (shortcut) to the folder for system use and then change to the source directory:
# ln -sf /usr/src/linux-2.6.18 /usr/src/linux && cd /usr/src/linux

Configuring

If this is not your first time configuring this particular kernel source (you’re reconfiguring and making changes), it’s always good to do a:
# make mrproper
This will clean the source back to its original state. Now everything is prepared, we can start to configure our kernel. While in the /usr/src/linux directory type:
# make menuconfig
From here you can load a saved config file or begin to build your own. Recommended options have already been selected but it’s up to the user to know what hardware the computer has. If the kernel hasn’t been configured correctly for the hardware then most likely the kernel will cause a panic during bootup. Make your changes and save the configuration with a unique name. This file can be loaded later on if changes need to be made.

Compiling

Type the following to start the build process:
# make bzImage && make modules && make modules_install
The above will build the kernel image, kernel modules and then install the kernel modules to /lib/modules/2.6.18. Build times will depend on the speed of the computer.

Installing the compiled kernel image

Once the build process has finished, we can install our new kernel. Rename your current kernel image and then move the new kernel image to /boot:
# cp -p /boot/vmlinuz /boot/vmlinuz.old && cp arch/i386/boot/bzImage /boot/vmlinuz

We rename the old kernel to use as a backup incase the new one fails

Now copy System.map and .config to the /boot:
# cp System.map /boot/System.map && cp .config /boot/config
Add the reference to the old kernel in lilo.conf under the current reference:

image = /boot/vmlinuz.old
    root = /dev/hda#
    label = #name2#
    read-only

Now install the changes to lilo:
# lilo
Make sure you have both references to the new kernel image and the old kernel image like this example:

image = /boot/vmlinuz
    root = /dev/hda#
    label = #name1#
    read-only
image = /boot/vmlinuz.old
    root = /dev/hda#
    label = #name2#
    read-only

Restart linux and select the new kernel from the lilo boot menu. Note you can select two kernels images now. If the new image fails to boot, restart and select the old kernel image. You can see it’s important to have a backup to save alot of time and headaches! If you configured everything correctly, your new kernel should be able to boot without errors.

16 Responses to this post

  1. Hey whats up.. really think the site is a great help, being a noob i have no expierence recompiling a kernel..i’ve done everything here and cant get it to boot the new kernel.. My system is the same except i have the t7200 cpu, i dont think that matters… i patched the unpacked source with the acpi …i tried doing this with the 2.6.17.7 a couple times and then with the 2.6.18 a few times both didnt suceed…. when i use the command the extract the kernel in /usr/src by typing that dir after the tar command. it says that the directory doesnt exist.. also. i was wondering, when i configure my kernel it doesnt have the option for pci express hotplug driver as you do…

  2. Thanks Colin,

    What is the make and model of your computer? The Dell XPS 1210? What linux distribution are you recompiling the kernel for? Did you configure the kernel options yourself or use somebody else’s .config file?

    As for extracting the kernel sources, try copying the tar.bz2 (or tar.gz) kernel source to /usr/src, then changing your directory to the same location. From here extract the source file: tar xfvj filename.tar.bz2 (or tar xfvz filename.tar.gz)

    PCI express hotplug should be under the Bus options (PCI, PCMCIA, EISA, MCA, ISA) section:

    Bus options (PCI, PCMCIA, EISA, MCA, ISA)  --->
        --- PCI support
        PCI access mode (Any)  --->
        [*] PCI Express support
        <M> PCI Express Hotplug driver
        [*] ISA support
        PCCARD (PCMCIA/CardBus) support  --->
            <M> PCCard (PCMCIA/CardBus) support
            <M> 16-bit PCMCIA support
            --- 32-bit CardBus support
            --- PC-card bridges
            <M> CardBus yenta-compatible bridge support
        PCI Hotplug Support  --->
    

    Let me know more info about your machine/distro, your methods of configurating the kernel and I’m sure we can get a running custom kernel for you.

    Lewis

  3. thanks for the post…sorry i wasnt as clear with my problem….it is the dell xps m1210, and i am using slackware 11, i tried my own config file after configuring it …once i compile it makes the config file in /usr/src/linux called ./config …and i copy the system map and that file to the boot dir.. i patched my kernel with the acpi patch …both kernels …i keep trying 2.6.17.7 & 2.6.18..

  4. o ya sorry,, i patched my 2.6.18 kernel with the patch on the linux kernel archives, then i couldnt make menuconfig..it wouldnt work.. i used the command to patch it followed by -f to force all options.. i was also wondering if i just copy the config file given on this site config2617 over to the boot dir .. instead of the one mine makes will it work? i’ll write down on the next post what my lspci says…

  5. Ok for now try it without patching the kernel. Download my 2.6.17 config for the Dell XPS m1210 (on the left, under ‘kernel configs’) and load it into menuconfig or xconfig.

    You don’t have to make any changes to it as I configured everything already. Compile the kernel and you will be booting without any errors. If that works for you, you can then make any modifications you need and try it with the acpi patch.

    I would try this first with the 2.6.17.13 kernel as I had trouble with the wireless under 2.6.18. Hope this gets it running for you, keep me posted.

  6. Another quick note, clean your kernel source up before recompiling again. Change directory to /usr/src/linux and do a:
    # make mrproper

  7. 00:00.0 Host brige: Intel Corporation Mobile 945GM/PM/GMS/940GML and 945GT Express Memory controller Hub (rev 03)
    00:01.0 PCI brige: Intel Corporation Mobile 945GM/PM/GMS/940GML and 945GT Express PCI Express Root Port (rev 03)
    00:1b.0 Audio device: Intel Coporation 82801G (ICH7 Family) High Definition Audio Controller (rev 01)
    0c:00.0 Network Controller : Intel Corporation PRO/Wireless 3945ABG Network connection (rev 02)
    01:00.0 VGA compatible controller: nVidia Corporation GeForce Go 7400 (rev a1)

    Those were the only differences from your’s…maybe that will help…

  8. None of those differences will affect the kernel booting process. I have the nVidia card, the Intel wireless, Intel audio, same host and pci bridges. I just need to post an updated lspci. Try my config though, it should fix all your problems.

    It’s most likely you just missed an important option while constructing your config file.

  9. thanks trying it now…i have one more question… Does the link linux in /usr/src/linux have any other links to like another system folder other than the link we make…because i did an install with out kernel sources..because i couldnt config any other kernel than the one supplied 2.4.3.3 or somethin…

  10. /usr/src/linux is only linked to /usr/src/linux-2.6.17 or whatever the kernel source version is. When the kernel modules are installed, a link will be created from /lib/modules/build to /usr/src/linux.

    Another thing, make sure you install the kernel headers for 2.6.17.13. Check your Slackware 11 cd in the ‘/extra/linux-2.6.17.13‘ folder.

  11. wow its takin like 10 times longer to compile than usual…i must have been doin it wrong

  12. actually i think it keeps doin it over and over again…i dont have bluetooth…can that be the problem ..

  13. thank you so much man it worked

  14. Glad it worked for you. You should have bluetooth… blue led under the power indicators. If not, it won’t be a problem as the bluetooth modules won’t cause any compatibility issues.

  15. I seem to be having some trouble and im not quite sure why. When i do a recompile of the kernel with 2.6.*, if i set lilo.conf to /dev/hda3, it wont boot (Kernel Panic, blah, root(3,3) not found). So i figured out that lilo.conf needed to be changed to /dev/sda3, but then the problem is that e2fsck still tries to check /dev/hda3 (which does not exist becuase it is seen as /dev/sda3) and wont let me boot anything but read only mode. hmph.
    I used:
    kernel 2.6.17.13 with your config
    on a dell m1210 (nearly the same hardware config as yours)

  16. Matt,
    When you installed Slackware, you most likely used the default kernel which has great support for IDE based drives but limited support for SATA drives. Using my config enabled the support for SATA (sda) but your system is still configured for IDE (hda). You got the kernel panic because the kernel was looking for /dev/sda in lilo.conf but you fixed that.

    The next problem is you can only mount in read-only because the file systems table (fstab) is looking to mount a /dev/hda drive. You need to edit /etc/fstab and change the hda values to sda. Doing that will allow your system to mount the correct drive with the correct configuration, but…

    Your drive is read-only so you cannot save changes to fstab. You will need to insert the Slackware CD/DVD and reboot. At the boot prompt type: huge26.s
    When prompted, select your keyboard map and login as root. From here, you can mount your linux filesystem /dev/sda3 with this command:
    # mount /dev/sda3 /mnt
    Now we can edit fstab with pico or vi (I use pico):
    # pico /mnt/etc/fstab
    Here, you’ll see the drive/partition configurations, just replace any hda with sda. When you’re done, press CTRL+O, then hit enter to write the file to the harddrive. Press CTRL+X to exit and reboot the system.

    You should be booting normally.

View Comment Policy & allowed tags

In effect as of 27th January 2006. ALL comments have to be reviewed before being accepted.

Relevance

Keep comments relevant to DesignLegion, article content, suggestions, requests, praise or critiques.

Formatting

The following tags are enabled for comments:

  • <a> (hyperlinks)
  • <code> (code section or quotes)
  • <cite> (Cite text)
  • <strong> or <b> (bold text)
  • <u> (underline)
  • <em> or <i> (italics)

The following classes are enabled:

  • .exclamation (for highlighting)

Spammers beware

If a comment has been classed as spam it will be deleted. Comments must be approved by the moderator and will not be displayed until approved.

If a comment seems to be relevant but the name/website seems to be an advertisement, then the given web url will be deleted and even changed to "Anonymous."

Private Matters?

If needing to contact me about private issues, please use the contact page.

XX

XX