Compile Linux Kernel in Ubuntu


The new Linux kernel 3.7.9 has been released last week. Here is how I compiled it in my Ubuntu laptop.

1) Install the prerequisites.
jchen@JC:~$ sudo apt-get install git-core libncurses5 libncurses5-dev
 libelf-dev asciidoc binutils-dev linux-source libncurses5 libncurses5-dev
 fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge kernel-package
2) Check the current kernel version.
jchen@JC:~$ uname -r
3.5.0-25-generic

3) Download the kernel 3.7.9

jchen@JC:~/Downloads$ wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.7.9.tar.bz2

4) Extract the kernel package
jchen@JC:~/Downloads$ sudo tar -xvjf linux-3.7.9.tar.bz2 -C /usr/src

5) Configure the kernel

jchen@JC:/usr/src/linux-3.7.9$ sudo make menuconfig
or use the current kernel configuration file as a base
jchen@JC:/usr/src/linux-3.7.9$ sudo cp -vi /boot/config-`uname -r` .config
`/boot/config-3.5.0-25-generic' -> `.config'
jchen@JC:/usr/src/linux-3.7.9$ sudo make oldconfig

6) Compile kernel modules

jchen@JC:/usr/src/linux-3.7.9$ sudo make modules

or use the following command to only compile the modules that available in the current system.

jchen@JC:/usr/src/linux-3.7.9$ sudo make localmodconfig

7) Compile the kernel

jchen@JC:/usr/src/linux-3.7.9$ sudo make 

8) Install the kernel modules

jchen@JC:/usr/src/linux-3.7.9$ sudo make modules_install

9) Confirm the following files can be found in the /boot directory

jchen@JC:/boot$ ls -alh *3.7.9*
-rw-r--r-- 1 root root 106K Feb 27 11:13 config-3.7.9
-rw-r--r-- 1 root root  19M Feb 27 11:14 initrd.img-3.7.9
-rw-r--r-- 1 root root 2.3M Feb 27 11:13 System.map-3.7.9
-rw-r--r-- 1 root root 5.0M Feb 27 11:13 vmlinuz-3.7.9

10) Confirm the grub.cfg file has been updated, if not run ‘sudo update-grub’

jchen@JC:/boot/grub$ less grub.cfg

11) Reboot and check the new running kernel version

jchen@JC:~$ uname -r
3.7.9

12) (Optional) If you are not happy with the new compiled kernel, you can remove it in this way: 

jchen@JC:/lib/modules$ sudo rm -rf 3.7.9
jchen@JC:/boot$ sudo rm -rf *.3.7.9*
jchen@JC:/boot$ sudo update-grub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s