How to Compile the Linux Kernel
Edited by Happygoat, Sondra C, Flickety, Maluniu and 18 others
The Linux kernel is the heart of any Linux system. It handles user input/output, hardware, and controlling the power in the computer. While the kernel that comes with your Linux distribution is usually sufficient, this allows you to make your owns specialized kernel!
EditSteps
-
1Download the latest version of the Linux kernel from http://www.kernel.org.Ad
-
2Be sure to download the full source by clicking on the "F" where it says "The latest stable version is..." otherwise you'll just download the patch, which is used when your current kernel is a patch number lower. An example of this would be 3.4.4.1>>3.4.4.2
-
3Make sure you have downloaded the complete source code, and not a patch or change log.
-
4Once downloaded, open a terminal.
-
5Now we need to extract the kernel. Use these commands.
- tar xjvf kernel (Here -j option is for bz2 compression)
-
6Once extracted, move into the directory (in the terminal) that was created.
-
7Configure the kernel. There are 3 common ways to do this.
- Make oldconfig -- asks you questions on what the kernel should support one by one, very time consuming.
- Make menuconfig -- creates a menu where you can browse options on what the kernel supports. Requires ncurses library, but that is likely already on your computer.
- Make qconfig/xconfig/gconfig -- same as menuconfig, except that now the configuration menu is graphics based."qconfig" Requires the QT library.
-
8Once the configuration window is opened, you will see that a specific type of configuration is already selected like support for essential drivers like Broadcom wireless support/EXT4 filesystem etc. Further, you may customize the options like adding support for your specific type of device/controller/driver like you may add support for NTFS file system from "Filesystem >> DOS/FAT/NT/ >> select NTFS file system support, thereby taking full advantage of custom kernel.
-
9NOTE: While configuring the kernel, you will see a section known as kernel hacking(by hacking we mean exploring into it), where different types of options are given for hacking into kernel and learning it. If you want to use it then you may add further options, otherwise you may disable the option "kernel debugging", as it makes the kernel a lot heavier and and may be improper to use in the production environment.
-
10Once configured, it is time to compile and install the kernel. You will need to execute these commands in order. This may take a long time.
- make (-j option may also be added to fork additional processes for compiling kernel, syntax would be "make -j 3" 3 here represents the number of processes to be created)
- Make modules_install
- Make install
-
11Grab some coffee cause this is going to take a while. on a modern (-5 years old) computer this will take at least 20 minutes. you can make your life easier by entering your commands all at once. this is done by using the ampersand (&) symbol
- Make && make modules_install && make install
-
12So the kernel is installed, but you need to make it bootable.
-
13Go to boot.
-
14Run this command "mkinitrd -o initrd.img-<kernelversion> <kernelversion>" (For Redhat based distros, you need not create initrd, as it is created by default) remembering to replace <kernelverison> with the version number of the kernel you build.
-
15Point the boot loader at the new kernel so it can be started. Use the tool that came with your distro to configure your bootloader. Add a new entry for the new kernel.
-
16Reboot and enjoy your customized kernel!Ad
EditTips
- Not all computers require an initrd to be created, but it is safe to do so just in case yours does.
- Menuconfig is usually the best option when configuring the kernel.
EditWarnings
- If the new kernel isn't configured properly, you may not support all your hardware and the kernel may crash.
Article Info
Categories: Linux
Recent edits by: DogandCatlover, Hailey Girges, Chris
In other languages:
Español: Cómo compilar el Kernel de Linux
Thanks to all authors for creating a page that has been read 80,450 times.