![]() |
Learn How To Compile The Linux Kernel
The Internet is filled with outdated / incorrect / complicated / wrong ways to compile the Linux kernel. It's not difficult to do. I simply cannot account for all the incorrect posts.
Get the kernel source: curl -O http://www.kernel.org/pub/linux/kernel/2.6/linux-<version>.tar.bz2 Will put the kernel source file into the working directory. If you're wondering how one would know what to put for <version>, you go into the kernel archive using a web browser, and you look for the exact <version> you want. If you don't know what version you want, stick with the latest stable version, as listed on this page: http://kernel.org/ There is a link on that page to the /pub/linux directory. When you get to /pub/linux click on kernel and then 2.6 The kernel source files are .tar.bz2 OR .tar.gz. The other files in the directory are used for verifying the authenticity of the kernel. ** OPTIONAL ** If you wish to verify the kernel source file, download the proper .sign file, and get the kernel.org public encryption key here: http://kernel.org/signature.html Then install the gpg package, and verify the kernel is properly signed. ** END OPTIONAL ** Install the development or lsb package for your distro. Move the kernel source file to: /usr/src su password mv linux-<version>.tar.bz2 /usr/src Uncompress the bz2 archive: tar jxvf linux-<version>.tar.bz2 The screen will scroll. Remove the: linux soft link: rm linux Make a new soft link to the new kernel source directory: ln -s linux-<version> linux Change directory to linux: cd linux Get a config file to start with: cp /boot/config-`uname -r` .config Apply and patches: patch -p 1 < <patch>.diff Configure the kernel: make oldconfig The new kernel will work if you agree with everything the configure program suggests. If you disagree, and change something, it will usually be ok. make menuconfig OR make xconfig Now, make the changes to the kernel configuration that you desire, and save the .config file. Don't worry about ruining the kernel config. If the new kernel doesn't boot, you can boot using the old kernel and repeat the above steps to copy the config file from /boot/ And configure the kernel again. Give the kernel a unique name: nano Makefile Put something meaningful after EXTRAVERSION = AND NAME = such as the date, preceded by a hyphen. Name the kernel after an attractive female, using lowercase only. If you need to use numbers in the name of an attractive female ... Ok, Save: Makefile Compile the kernel: make clean make all make modules_install make install After you do the make install step, there is a command line left on the screen, beginning with sh You need to: chmod +x /usr/src/linux-<version>/arch/x86/boot/install.sh and then type the entire command left by: make install and execute it. Now you should have: /boot/initrd-<version> /boot/System.map-<version> /boot/vmlinuz-<version> Check /boot/grub/menu.lst for a new entry. nano /boot/grub/menu.lst Put a # and a space in front of hiddenmenu and splashimage Check for your new entry, which should read title <something> <version> root(hdx,y) kernel /vmlinuz-<version> root=<something> initrd /initrd-<version> make default=0 timeout=5 If the entry for your new kernel is in /boot/grub/menu.lst the machine should boot with the new kernel. The main rule for compiling a new kernel, or a kernel rebuild, is remove unnecessary options, such as unnecessary drivers, from the kernel config. You must know your hardware. But you can reduce the size of the kernel considerably, which is good. Usually a kernel rebuild is due to a patch being applied, requiring recompilation. |
Quote:
Code:
cp /boot/config-`uname -r` .config |
Quote:
PHP Code:
|
Quote:
Added: Oh, and there's no real need for the kernel source to be in /usr/src. |
There are differences of opinion as to where to build the kernel: /usr/src or /home/username. I've seen several howtos recommend /usr/src, but on the other hand there's this:
Quote:
|
Quote:
|
Quote:
|
You are correct. After building I manually install all the components for my kernel into /boot which amounts to manually cp'ing files from /usr/src/linux<version> to /boot.
|
Quote:
|
Quote:
|
Great idea ...
Quote:
|
Just following conventions.
Quote:
|
Kernel evangelism ...
Quote:
That's ok, but it can cause problems under certain circumstances. And, most people now know about the soft link /lib/modules/$(uname -r)/build/, so we really don't require /usr/src/linux anymore. But many instructions on how to build a kernel would seem cryptic and contradictory to this one if I didn't use /usr/src/linux. |
What I'm describing in the OP ...
Quote:
This method is the method the kernel maintainers build into the kernel sources. It's the industrial reference standard kernel compilation method. Although, when I'm working on Debian, I use Debian sources, make-kpkg, update-initramfs, and update-grub. |
Quote:
Code:
echo " --kernel-source-path=KERNEL-SOURCE-PATH" |
Quote:
|
Eric Hameleers (alien BOB) recommends building it in /usr/src. When a top Slacker and a top kernel developer disagree, what's a poor newbie like me to do? :)
http://alien.slackbook.org/dokuwiki/...kernelbuilding |
For what it's worth I follow Bob on this. It's generally a safe method, and doesn't involve removing anything, whereas some guides I have read have people removing the old kernel, before trying to boot the new one.
Also, Bob's remarks regarding using /usr/src/ are qualified by the line Quote:
From the above link: Quote:
|
Quote:
|
All times are GMT -5. The time now is 01:37 AM. |