Compiling Linux Kernel

To be prepared to make changes to the kernel, it’s necessary to give it a try to compile the linux kernel successfully.

Environment

  • VMware Fusion 7
  • Ubuntu 12.04.5
  • Root permission

Objective

Initially, the kernel version of the Ubuntu 12.04.5 is 3.13.0-32-generic according to

1
uname -r

If you wanna check your ubuntu version, use

1
cat /etc/issue

Our goal is to update the version of kernel to newer one, in this case, 3.18.

Compile the Linux Kernel

1. Download the kernel from here.
2. Copy to a directory and extract.
1
2
3
4
5
cp linux-3.X.X.tar.xz /usr/src
cd /usr/src
xz -d linux-3.X.X.tar.xz
tar -xf linux-3.X.X.tar
cd linux-3.X.X
3. If not the first time to compile
1
2
make clean
make mrproper
4. Configuration
1
make menuconfig

There might be a tiny prob here saying

1
fatal error: curses.h: No such file or directory

Solution under Ubuntu:

1
sudo apt-get install libncurses5-dev libncursesw5-dev
5. Compile
1
2
3
make
make modules_install
make install

Suggestion here: enlarge the memory size of your virtual system, which may help reduce the compiling time dramatically.

It takes hours to compile with 1 core and 1-GB memory with GUI turned on…

6. Update GRUB
1
2
3
4
5
cd /boot
mkinitramfs 3.18.8 -o initrd.img-3.18.8
cp /usr/src/linux-3.18.8/arch/x86_64/boot/bzImage /boot/vmlinuz-3.18.8
ln -s /boot/System.map-3.18.8 /boot/System.map
sudo update-grub2
7. Reboot and Check!