Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › [FAQ] How-to compile a custom kernel
New Posts  All Forums:Forum Nav:

[FAQ] How-to compile a custom kernel

post #1 of 27
Thread Starter 
How-to compile a custom kernel.

System used: Slackware 11


You will need root user privileges to do the following that this guide covers.

First you need to download a kernel. You can find a list of kernels at www.kernel.org. After you have downloaded the kernel, have it to the directory /usr/src.

The next thing you are going to want to do is uncompress the kernel package. If your DE(KDE, Gnome, Xfce) supports it you can right click on it and uncompress(extract) it.
The other way in by the terminal, open a terminal (console) and move to the directory of the package.
Code:
cd /usr/src
and then type: (if the package was compressed with gzip. Would have the extension is .tar.gz or .tgz)
The # represent the number of what ever the newest kernel is.
Code:
tar zxvf linux-2.6.#.tar.gz
(if the package was compressed with bzip2, Would have the extension is .tar.bz2)
Code:
tar xvjf linux-2.6.#.tar.bz2
Now that the kernel package is extracted, a new folder was created. Move into the new folder.
Code:
cd linux-2.6.#
Now in the terminal you have a few options to choose from in terms of configuring the kernel.

make gconfig - Gtk based configuration tool (available in kernels 2.6 and up).

make qconfig - Same as gconfig, but uses the Qt widget set (available in kernels 2.6 and up).

make menuconfig - Uses menu boxes to configure the kernel.

make xconfig - Uses X window for the gui to the configuration tool (available in kernels 2.6 and up)..

In the terminal type either one of the configuration options you wish to use.
Now is the part that can be a pain, go through the options and choose what you need. If it is your first time compiling the kernel, than this step may take you while (don't worry the more you compile your own kernel, the faster you'll be able to go through it).
Once you are done, click save and exit. Now a new ".config" file has been created in the current directory. This file is important if you ever what to re-compile the kernel, but don't want to go through ever thing again; you can load that file and it'll load the previous kernel configuration. (you load it after you start gconfig, menuconfig, etc).

Now in the terminal type make and then once that is done type make modules_install. Then finally type make bzImage.

Now copy the "bzImage" over to the /boot directory (in the last few lines of the command make bzImage, it gives you the path to the bzImage)
Rename the file /boot/vmlinuz (may be something like vmlinuz-2.#.#) to something like: (Replace # with what ever the old kernel was)
Code:
 mv /boot/vmlinuz /boot/vmlinuz-2.#.#
Now rename the bzImage that you copied over to the directory /boot.
Code:
 mv /boot/bzImage /boot/vmlinuz
Now in /boot you have the new kernel and the old one that you know worked.

Now finally change the grub boot loader to boot the new kernel. Usually found in /boot/grub/menu.list

I highly recommend that when you add to the grub menu.list, you have two options to boot into for the OS that you just compiled the kernel for. One that boots the OS using the old kernel (the one you know is good), and the new one. This way if you forgot some important configuration for the kernel, you can still boot into the old kernel, so you can re-configure the new kernel.
MAKE SURE that you change the line that begins with "kernel" and edit /boot/### with what ever you renamed the old kernel, else you won't be able to boot into it. Then copy that boot configuration option and past it under the original and edit the line beginning with "kernel" and change /boot/### to what ever you named the new kernel.

Example:
Lets say my original kernel image is called /boot/vmlinuz. I compiled my kernel and moved to /boot. Now I renamed my original kernel from /boot/vmlinuz to /boot/vmlinuz-linux-2.4.33.3. Then I renamed the new kernel from /boot/bzImage to /boot/vmlinuz.

The change in my grub menu.lst file would be like so:

Original /boot/grub/menu.lst (part of it)
Code:
title        Slackware Linux (Slackware 11.0.0) (on /dev/sda6)
root        (hd0,5)
kernel        /boot/vmlinuz root=/dev/sda6 
savedefault
boot
NEW /boot/grub/menu.lst (part of it)
NOTE the bold lines.
Code:
# Original Kernel
title        Slackware Linux (Slackware 11.0.0) 2.4.33.3
root        (hd0,5)
kernel        /boot/vmlinuz-linux-2.4.33.3 root=/dev/sda6 
savedefault
boot

# Option to boot into the new kernel
title        Slackware Linux (Slackware 11.0.0) 2.6.18
root        (hd0,5)
kernel        /boot/vmlinuz root=/dev/sda6 
savedefault
boot
After this you can reboot into your new kernel.


Just patching a kernel
If you just want to patch your kernel to the newest kernel release, you can find kernel patchs at www.kernel.org and here, which are patches by Con Kolivas.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #2 of 27
Good guide. I constantly see guys recommending that you build your own kernel, but rarely does anybody give precise instructions on how to do it.
Magicbox
(17 items)
 
crapbox
(13 items)
 
 
CPUMotherboardGraphicsRAM
FX 8320 Sabertooth 990FX Nitro+ RX480 Kingston HyperX Fury 
Hard DriveHard DriveHard DriveCooling
Samsung 850 EVO  Kingston HyperX 3K Seagate Barracuda 7200.14 Noctua NH-D15 
OSOSMonitorKeyboard
Kubuntu  Windows 10 Pro Dell U2515H CM Quickfire TK (Cherry Blue) 
PowerCaseMouseMouse Pad
Cooler Master Silent Pro M 850W Enthoo Pro Logitech G502 Logitech G440 
Audio
Xonar DX 
CPUMotherboardGraphicsRAM
Sempron 3300+ HP stock mobo (laptop) 200M (IGP) 2x1GB PC3200 
Hard DriveOptical DriveOSMonitor
100GB ATA133 DVD/CDRW Kubuntu 32 bit 14.1" (1280x768) 
Power
6 cell 
  hide details  
Reply
Magicbox
(17 items)
 
crapbox
(13 items)
 
 
CPUMotherboardGraphicsRAM
FX 8320 Sabertooth 990FX Nitro+ RX480 Kingston HyperX Fury 
Hard DriveHard DriveHard DriveCooling
Samsung 850 EVO  Kingston HyperX 3K Seagate Barracuda 7200.14 Noctua NH-D15 
OSOSMonitorKeyboard
Kubuntu  Windows 10 Pro Dell U2515H CM Quickfire TK (Cherry Blue) 
PowerCaseMouseMouse Pad
Cooler Master Silent Pro M 850W Enthoo Pro Logitech G502 Logitech G440 
Audio
Xonar DX 
CPUMotherboardGraphicsRAM
Sempron 3300+ HP stock mobo (laptop) 200M (IGP) 2x1GB PC3200 
Hard DriveOptical DriveOSMonitor
100GB ATA133 DVD/CDRW Kubuntu 32 bit 14.1" (1280x768) 
Power
6 cell 
  hide details  
Reply
post #3 of 27
Thread Starter 
Thank you. The guide is still a bit rough I feel, but I plan to add to it here and there.
Also want to add the Ubuntu and Fedora ways of re-compiling the kernel. This way will work for every dirsto though, to my knowledge.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #4 of 27
Quote:
Originally Posted by dangerousHobo View Post
Thank you. The guide is still a bit rough I feel, but I plan to add to it here and there.
Also want to add the Ubuntu and Fedora ways of re-compiling the kernel. This way will work for every dirsto though, to my knowledge.
It should. Nothing you used was distro-specific.

One thing I would change though is that instead of replacing the old kernel in the boot loader, copy it's settings to a new entry, then change the name to the new kernel. That way if you messed up the new kernel config, you still have easy access to your old kernel as a backup.

Nice guide though! Manual compiles are not too easy to make understandable!
Morpheus Mini
(7 items)
 
  
CPUMotherboardGraphicsRAM
i7-6700T SN970 GTX 960 Crucial CT102464BF160B 
Hard DriveOSAudio
Samsung 850 Evo M.2 Windows 10 Pro MOTU Audio Express 
  hide details  
Reply
Morpheus Mini
(7 items)
 
  
CPUMotherboardGraphicsRAM
i7-6700T SN970 GTX 960 Crucial CT102464BF160B 
Hard DriveOSAudio
Samsung 850 Evo M.2 Windows 10 Pro MOTU Audio Express 
  hide details  
Reply
post #5 of 27
Thread Starter 
I have that in there, but it may not be clear. I'll work on re-wording it.
Quote:
I recommend that when you add to the grub menu.list, you have two options to boot into for the OS that you just compiled the kernel for. One that boots the OS using the old kernel (the one you know is good), and the new one. This way if you forgot some important configuration for the kernel, you can still boot into the old kernel, so you can re-configure the kernel.
MAKE SURE that you change the line that begins with "kernel" and edit /boot/### with what ever you renamed the old kernel, else you won't be able to boot into it.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #6 of 27
I can't find the grubmenu list anywhere. I've done every step up to that, and still 2.4.33.3 is loading. How the hell do I find it?
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
post #7 of 27
Thread Starter 
B/c Slackware is basiclly one of the only distros still using LILO as its boot loader instead of Grub. So you'll have to edit /etc/lilo.conf.

Would look something like this:
default="linux"
boot=/dev/hda
prompt
nowarn
timeout=150
message=/boot/message
menu-scheme=wb:bw:wb:bw
image=/boot/vmlinuz
label="linux"
root=/dev/hda8
initrd=/boot/initrd.img
append="devfs=nomount acpi=ht"
read-only
other=/dev/hda1
label="windows"
table=/dev/hda

other=/dev/hda2
label="windows1"
table=/dev/hda

image=/boot/vmlinuz
label="failsafe"
root=/dev/hda8
initrd=/boot/initrd.img
append="failsafe acpi=ht devfs=nomount"
read-only

image=/boot/vmlinuz
label="FC4-linux"
root=/dev/hda11
initrd=/boot/initrd.img
append="devfs=nomount acpi=ht"


Would add something like the following to it:
#What ever the name for the new kernel is
image=/boot/vmlinuz-new
label="Slackware 2.6.##"
root=/dev/hd##

#What ever the name for the old kernel is
image=/boot/vmlinuz-2.4.33.3
label="Slackware 2.4.33.3"
root=/dev/hd##

Then run the command lilo after editing and saving the file.
I don't use lilo even though I use slackware, I use the grub loader from my Arch install. So I'm not 100% sure on the lilo syntax but it should be very close to that if not it.
I believe you can run liloconfig on slackware too, to configure lilo.
However you can install grub on Slackware.
download: ftp://slackware.oregonstate.edu/pub/....97-i486-2.tgz

then type: installpkg grub-version.tgz
then: grubconfig

Now you have grub on slackware.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #8 of 27
Quote:
Originally Posted by dangerousHobo View Post
However you can install grub on Slackware.
download: ftp://slackware.oregonstate.edu/pub/....97-i486-2.tgz

then type: installpkg grub-version.tgz
then: grubconfig

Now you have grub on slackware.
Will that automatically replace Lilo, or will I need to do more?
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
post #9 of 27
Thread Starter 
That will over write lilo.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #10 of 27
Another question - does the "make" command after configuring the kernel also take on the function of the old "make modules" or do I still need to do both before "make modules_install"?

btw - you left an "l" off install in the "make modules_install" commoand in the orignal faq. (anal boy likes things letter perfect in instructions)
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
Does the trick
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E6600 @3.08Ghz MSI P6n SLI 650i EVGA 8800GTS 320 2x1Gb GSkill & 2X512mb Kingston PC6400 
Hard DriveOptical DriveOSMonitor
WD 250GB SATA 7200RPM + Seagate 7200.10 80gb HP Lightscribe DVD rw Vista home premium 64 37' Westinghouse 1080P hdtv 
KeyboardPowerCaseMouse
Dell Quietkey Mad Dog 550 Antec Sonata II Logitech Trackball 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › [FAQ] How-to compile a custom kernel