Sei sulla pagina 1di 11

How to Compile Linux Kernel from Source to Build Cust...

1 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Home
Free eBook
Start Here
Contact
About

How to Compile Linux Kernel from


Source to Build Custom Kernel
by Lakshmanan Ganapathy on June 13, 2013
25

Like

66

Tweet

Linux kernel is the life force of all Linux family of operating systems including Ubuntu,
CentOS, and Fedora.
For most part, you dont need to compile the kernel, as it is installed by default when
you install the OS. Also, when there is a critical update done to the kernel, you can use
yum, or apt-get to update the kernel on your Linux system.
However you might encounter certain situation, where you may have to compile kernel
from source. The following are few situation where you may have to compile Kernel on
your Linux system.
To enable experimental features that are not part of the default kernel.
To enable support for a new hardware that is not currently supported by the default
kernel.
To debug the kernel
Or, just to learn how kernel works, you might want to explore the kernel source
code, and compile it on your own.
In this tutorial, well explain how to compile Linux kernel from source.
Also, please note that if you just want to compile a driver, you dont need to compile the
kernel. You need only the linux-headers package of the kernel.

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

2 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

1. Download the Latest Stable Kernel


The rst step is to download the latest stable kernel from kernel.org.
# cd /usr/src/
# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.3.tar.xz

2. Untar the Kernel Source


The second step is to untar the kernel source le for compilation.
# tar -xvJf linux-3.9.3.tar.xz

3. Congure the Kernel


The kernel contains nearly 3000 conguration options. To make the kernel used by most
people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat,
CentOS, etc, will generally include support for most common hardware. You can take
any one of conguration from the distro, and on top of that you can add your own
conguration, or you can congure the kernel from scratch, or you can use the default
cong provided by the kernel.

# cd linux-3.9.3
# make menuconfig

The make menucong, will launch a text-based user interface with default conguration
options as shown in the gure. You should have installed libncurses and libncursesdevel packages for this command to work.

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

3 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

We will use the default cong provided by the kernel. So select Save and save the
cong in the le name .cong.
The following is a sample of the .cong le:
CONFIG_MMU=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_GENERIC_ISA_DMA=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_HWEIGHT=y

4. Compile the Linux Kernel


Compile the main kernel:
# make

Compile the kernel modules:


# make modules

Install the kernel modules:


# make modules_install

At this point, you should see a directory named /lib/modules/3.9.3/ in your system.

5. Install the New Kernel


Install the new kernel on the system:
# make install

The make install command will create the following les in the /boot directory.

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

4 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

vmlinuz-3.9.3 The actual kernel


System.map-3.9.3 The symbols exported by the kernel
initrd.img-3.9.3 initrd image is temporary root le system used during boot
process
cong-3.9.3 The kernel conguration le
The command make install will also update the grub.cfg by default. So we dont need
to manually edit the grub.cfg le.

6. Boot Linux to the new Kernel


To use the new kernel that you just compiled, reboot the system.
# reboot

Since, in grub.cfg, the new kernel is added as default boot, the system will boot from the
new kernel. Just in case if you have problems with the new kernel, you can select the old
kernel from the grub menu during boot and you can use your system as usual.
Once the system is up, use uname command to verify that the new version of Linux
kernel is installed.
$ uname -r
3.9.3
25

Tweet

Like

66

> Add your comment

Linux provides several powerful administrative tools and


utilities which will help you to manage your systems eectively. If you dont know what
these tools are and how to use them, you could be spending lot of time trying to perform
even the basic administrative tasks. The focus of this course is to help you understand
system administration tools, which will help you to become an eective Linux system
administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..


1. 50 Linux Sysadmin Tutorials
2. 50 Most Frequently Used Linux
Commands (With Examples)
3. Top 25 Best Linux Performance

Awk Introduction 7 Awk Print


Examples
Advanced Sed Substitution
Examples

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

5 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Monitoring and Debugging Tools


4. Mommy, I found it! 15 Practical Linux
Find Command Examples
5. Linux 101 Hacks 2nd Edition eBook

8 Essential Vim Editor Navigation


Fundamentals
25 Most Frequently Used Linux
IPTables Rules Examples
Turbocharge PuTTY with 12
Powerful Add-Ons

Tags: CentOS Compile Kernel, Compiling Kernel, Compiling Kernel Modules, Debian
Compile Kernel, Fedora Compile Kernel, Install Linux Kernel, Kernel Cong File, Linux
Kernel Cong, Linux Kernel Modules, Linux Kernel Source, Recompile Linux Kernel,
Ubuntu Compile Kernel
{ 18 comments read them below or add one }
1 Anthony June 13, 2013 at 6:10 am
Nowdays, all computers CPU are multicore, multithreaded. It would have been
nice to show make -j N with N the number of (core * thread-by-core) to help built
faster otherwise it can take forever!
nu said!
2 Deepak June 13, 2013 at 8:36 am
one more reason to compile a kernel is if we want to install latest kernel whose rpm
is not available yet.
3 me June 13, 2013 at 8:38 am
You make no mention of things like
make localmodcong
to avoid making hundred of unnecessary modules.
Maybe I dont want gcc on every linux pc, how can an rpm be made.
Your making the compile extremely slow by not including -j # representing the
number of concurrent compiles.
This is guide is far from complete.
4 Feiticeir0 June 13, 2013 at 8:50 am

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

6 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Or if you dont want all the bloatware that comes with predened kernels from your
distro although it packs security and enhancement patches.
5 me June 13, 2013 at 8:57 am
/proc/cong.gz
If present, this is the current running cong le compressed.
6 Jalal Hajigholamali June 13, 2013 at 8:59 am
Hi,
Thanks a lot,
useful article
7 Koratsuki June 13, 2013 at 9:25 am
@Deepak: Or use new options/drivers/congs unavailable on older kernels Nice
article
8 Bob June 13, 2013 at 10:42 am
Nice article. Thanks
9 John Yost June 13, 2013 at 1:13 pm
I believe make install updates the lilo.cong le not grub.cfg
10 Jim Lee June 13, 2013 at 3:28 pm
I used to do steps #4 and #5 for my Debian (Sid) install but sometimes found that I
needed the associated headers to satisfy dependencies for things I wanted to install
or recompile afterward (like VMWare player, for example); many times those
headers were not available, especially if I was compiling a bleedding-edge kernel.
These days I just use make deb-pkg instead. This takes care of the compile and
produces the linux-rmware-image, linux-image, linux-headers and linuxlibc-dev .deb packages. A subsequent dpkg -i *.deb installs these packages and
satises those dependencies.
11 Daniel June 13, 2013 at 3:49 pm
Very nice article. But you could have given a warning like This may take some
time, so dont do it right before you are going to bed Now Ill have to wait!
12 chris June 15, 2013 at 12:09 pm
hi i tried to install kernel-3.9.0 but it got interupted during compiling (after
entering the make command).it logged out by itself.so i logged in and assuming
that the compiling was over i proceded to compile the modules and install it .
when i entered the make install command it requested to redo the make make
process.and then install.
Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

7 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

after rebooting the resolution changed and the keyboard and mouse stopped
working.
im currently using the old kernel and i would like to delete the one that i installed.
13 Ethan June 16, 2013 at 3:07 am
Good to see the concise explaination by Lakshmanan.
14 Chad June 19, 2013 at 11:24 am
@chris
Theres no auto pilot here.
And customizing kernel is not for the faint of heart , you should read quite a lot
before you actually start customizing it.
15 Anonymous July 1, 2013 at 10:18 am
make bzImage;
make modules && make modules_install
16 Gomathi August 22, 2013 at 5:45 am
The BEST!
17 YektaPardaz October 4, 2013 at 10:36 am
Thanks for nice article.
But I have a question. How can I cong kernel source for best performance on my
vps? I mean is there a way to remove unnecessary modules of kernel before
building it? Modules like new VGA support, new other le-system support(other
than ext3 and ext4), .. . Im looking for ways to make my custom kernel as small
and fast as possible.
18 cybernard October 7, 2013 at 6:21 am
make localmodcong
that eliminates all modules not currently loaded in memory.
Leave a Comment
Name
E-mail
Website

Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

8 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Notify me of followup comments via e-mail

Submit
Previous post: How to Write C++ Virtual Functions with Examples
Next post: How to View and Change DELL Server BIOS Settings
RSS | Email | Twitter | Facebook | Google+

Search

COURSE
Linux Sysadmin CentOS 6 Course - Master the Tools, Congure it Right, and
be Lazy

EBOOKS
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a
Strong Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell
Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and
Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive
in Vim Editor
Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

9 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well


The Geek Stuff
Like
4,723 people like The Geek Stuff.

Facebook social plugin

POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
50 UNIX / Linux Sysadmin Tutorials
50 Most Frequently Used UNIX / Linux Commands (With Examples)
How To Be Productive and Get Things Done Using GTD
30 Things To Do When you are Bored and have a Computer
Linux Directory Structure (File System Structure) Explained with Examples
Linux Crontab: 15 Awesome Cron Job Examples
Get a Grip on the Grep! 15 Practical Grep Command Examples
Unix LS Command: 15 Practical Examples
15 Examples To Master Linux Command Line History
Top 10 Open Source Bug Tracking System
Vi and Vim Macro Tutorial: How To Record and Play
Mommy, I found it! -- 15 Practical Linux Find Command Examples
15 Awesome Gmail Tips and Tricks
15 Awesome Google Search Tips and Tricks
RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams
Can You Top This? 15 Practical Linux Top Command Examples
Top 5 Best System Monitoring Tools
Top 5 Best Linux OS Distributions
How To Monitor Remote Linux Host using Nagios 3.0
Awk Introduction Tutorial 7 Awk Print Examples
How to Backup Linux? 15 rsync Command Examples
The Ultimate Wget Download Guide With 15 Awesome Examples
Top 5 Best Linux Text Editors
Packet Analyzer: 15 TCPDUMP Command Examples
The Ultimate Bash Array Tutorial with 15 Examples
3 Steps to Perform SSH Login Without Password Using ssh-keygen &
ssh-copy-id
Unix Sed Tutorial: Advanced Sed Substitution Examples
UNIX / Linux: 10 Netstat Command Examples
The Ultimate Guide for Creating Strong Passwords
6 Steps to Secure Your Home Wireless Network
Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

10 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Turbocharge PuTTY with 12 Powerful Add-Ons

CATEGORIES
Linux Tutorials
Vim Editor
Sed Scripting
Awk Scripting
Bash Shell Scripting
Nagios Monitoring
OpenSSH
IPTables Firewall
Apache Web Server
MySQL Database
Perl Programming
Google Tutorials
Ubuntu Tutorials
PostgreSQL DB
Hello World Examples
C Programming
C++ Programming
DELL Server Tutorials
Oracle Database
VMware Tutorials
Ramesh Natarajan
Follow

About The Geek Stu

My name is Ramesh Natarajan. I will be posting instruction guides,


how-to, troubleshooting tips and tricks on Linux, database, hardware, security and
web. My focus is to write articles that will either teach you or help you resolve a
problem. Read more about Ramesh Natarajan and the blog.

Support Us
Support this blog by purchasing one of my ebooks.
Bash 101 Hacks eBook
Monday 10 March 2014 11:26 PM

How to Compile Linux Kernel from Source to Build Cust...

11 of 11

http://www.thegeekstu.com/2013/06/compile-linux-kernel/

Sed and Awk 101 Hacks eBook


Vim 101 Hacks eBook
Nagios Core 3 eBook

Contact Us
Email Me : Use this Contact Form to get in touch me with your comments,
questions or suggestions about this site. You can also simply drop me a line to say
hello!.
Follow us on Google+
Follow us on Twitter
Become a fan on Facebook
Copyright 20082014 Ramesh Natarajan. All rights reserved | Terms of Service

Monday 10 March 2014 11:26 PM

Potrebbero piacerti anche