12.17.2011

Building the Linux Kernel on Debian Based Systems

So you want to build the Linux kernel from scratch, but don't know where to start?
Wikipedia describes the Linux kernel as
The Linux kernel is an operating system kernel used by the Linux family of Unix-like operating systems. It is one of the most prominent examples of free and open source software.

If you are using a debian based system like Ubuntu or Linux Mint, building your own kernel isn't very difficult. I put together a short tutorial to that is fairly easy to follow and should make the process less painful.

Prerequisites:
In order to download, build, and install a custom kernel you will need the following packages installed.
1. Git - a fast, scalable, distributed revision control system with an
unusually rich command set that provides both high-level operations and
full access to internals.
2. kernel-package - a package used to make kernel compilation more automated and less painful.
3. fakeroot - runs in a command environment at pretends to have root privileges for file manipulation. Useful for creating archives with files inside that have root permissions.
4. buid-essential - contains an informational list of packages which are considered essential for building Debian packages. This package also depends on the packages on that list, to make it easy to have the build-essential packages installed.
5. ncurses-dev

sudo apt-get install git-core kernel-package fakeroot build-essential ncurses-dev

1. Change to the home directory
cd ~

2. Clone the mainline kernel git tree
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

3. CD to the linux directory
cd linux

4. Copy the kernel config from your existing kernel using uname -r for your currently loaded kernel
cp /boot/config-'uname -r' .config

5. Update the config file. The default answer to these questions will suffice.
make oldconfig
yes "" | make oldconfig to accept the defaults

6. Clean the kernel source directory
make-kpkg clean

7. Build the linux-image and linux-header .deb files. This is where the actual work takes place. It could take some time. On my machine with an i5 processor it took 15 - 30 minutes.
The concurrency level of this piece can be set manually. Basically it lets you allocate how many processors you would like to utilize in making the kernel image
CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN` fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

8. Change the directory level one up and install the two .deb packeges created<blockquote>
sudo dpkg -i linux-image-<insert custom kernel name here>.deb
sudo dpkg -i linux-headers-<insert custom headers name here>.deb

9. Make the kernel bootable
cd /lib/modules
sudo update-initramfs -c -k <insert kernel module name here>

10. Make sure grub recognizes your custom kernel when you reboot.
sudo update-grub

You're done! Reboot and see if it worked.

Links:
Summary of Linus's Kernel on Git

No comments:

Post a Comment