Sunday, December 1, 2013

How to - Linux Kernel Compilation in Ubuntu VM/VirtualBox


I recently compiled linux kernel in a Virtualbox VM. Here are the steps I used to compile a custom linux kernel. These steps worked for me in Ubuntu 13.10 distribution.



Check the linux version of your VM:



babu@babu-VirtualBox:~$ uname -a
Linux babu-VirtualBox 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux
babu@babu-VirtualBox:~$ 

Switch to root mode:


babu@babu-VirtualBox:~$ sudo -s
[sudo] password for babu: 
root@babu-VirtualBox:~#

Download the linux sources for the matching version to /usr/src:
root@babu-VirtualBox:~# cd /usr/src
root@babu-VirtualBox:/usr/src# 
root@babu-VirtualBox:/usr/src# ls
linux-headers-3.11.0-12          vboxguest-4.3.6
linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# wget http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.11-tar.bz2
.
.
root@babu-VirtualBox:/usr/src#

In my case, I didn't have tarball for 3.11.0 at http://www.kernel.org/pub/linux/kernel/v3x/. So, I got linux-3.11.tar.bz2 instead:
root@babu-VirtualBox:/usr/src# ls 
linux-headers-3.11.0-12          vboxguest-4.3.6
linux-3.11.tar.bz2  linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# 

Extract the source to /usr/src:
root@babu-VirtualBox:/usr/src# tar -xvf linux-3.11.tar.bz2 -C .
.
.
root@babu-VirtualBox:/usr/src# ls
linux-3.11          linux-headers-3.11.0-12          vboxguest-4.3.6
linux-3.11.tar.bz2  linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# 

Install compilation tools necessary:

apt-get update
apt-get install gcc
apt-get install make
apt-get install ncurses-*

Select the kernel configuration options you need:

root@babu-VirtualBox:/usr/src# cd linux-3.11/
root@babu-VirtualBox:/usr/src/linux-3.11# make menuconfig

Compile & Install the Kernel:

root@babu-VirtualBox:/usr/src/linux-3.11# make     <-- This step took approximately 2 hours on my dual core VM.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11#  make modules <-- This step took approximately 2 minutes.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11# make modules_install  <-- This step took approximately 10 minutes.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11# make install
.
.
root@babu-VirtualBox:/usr/src/linux-3.11#

Initrd creation & GRUB modification:

I didn't have to create initrd image or a grub entry. An initrd image was already generated in /boot directory & my new image was already in /boot/grub/grub.cfg. I guess grub2 made this step automatic?


Reboot:


/sbin/reboot

Select the new custom created kernel during bootup:

Before the VM boots up, hold the shift key to get the bootloader options list. Then, select "Advanced Options for Ubuntu":


                    















Then in the next menu, select your custom kernel:

                    















Verify that your VM indeed is running the new custom kernel:

babu@babu-VirtualBox:~$ uname -a
Linux babu-VirtualBox 3.11.0 #3 SMP Fri Feb 14 10:54:07 PST 2014 i686 i686 i686 GNU/Linux
babu@babu-VirtualBox:~$ 

Thats it. Hope this helps.



No comments:

UA-48797665-1