/home/josephspurrier

Compile Linux Kernel

At the heart of every Linux distribution is the kernel. A great way to get more familiar with the system is to compile a customized version of the kernel for your own machine. The kernel is relatively easy to build because of the different customization options users can choose.

In order to customize the kernel, the command, make menuconfig, will bring up a nice menu that allows the addition of removal of included drivers. If a system is not recognizing a bluetooth, ethernet, wireless, or any of kind of adapter, a quick Google search may tell you exactly where in the menus the driver is inside the kernel menu. Just press “Space” to enable the driver and finish building the kernel.

Don’t use this script as a guaranteed and support way of creating a kernel. Many users will tell you to NOT compile the kernel as root for various issues, but if you just want to learn for a basic understanding, the code should work with minor code changes. I would run each line of code individually to ensure there are no errors. I’ve commented out other ways of doing the same task and left them in the code for reference.

Note: If care is not taken on the steps below, the current kernel may be overwritten or the system may fail to boot. As always, please test any of the scripts on this site on a virtual machine. VMWare Server (which is free and web based) is preferred, but VirtualBox is a great alternative. I am currently using Hyper-V, but it requires Windows Server 2008 and integration driver support is very weak.

#!/bin/bash
### ——————————————————————– ###
# This script compiles the linux kernel.
# Location: http://virtualparadise.wordpress.com/2010/04/29/compile-linux-kernel
# Date Created: 4/29/2010
# Date Modified: 4/29/2010
# Permissions Required: Non-root
# Notes: Not every link will be valid or the latest, double
# check before relying on the code
### ——————————————————————– ###
# Download the kernel source
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.2.tar.bz2
# Uncompress the source
tar xvf linux-2.6.33.2.tar.bz2
#gzip -dc linux-2.6.33.2.tar.gz | tar xvf -
# Move the kernel source folder
mv linux-2.6.33.2 /usr/src
# Navigate to the kernel folder
cd /usr/src/linux-2.6.33.2
# Install the required packages
apt-get install kernel-package ncurses-devel mkinitrd-tools
apt-get install initramfs-tools
#yum -y install kernel kernel-package ncurses-devel
# Clean the kernel source
make mrproper
# Configure the kernel
make menuconfig
#make oldconfig
# Build the kernel
make modules modules_install bzImage
# This step moves the kernel, bzImage, system.map to the /boot folder and adds an entry to the /boot/grub/menu.lst file
make install
# Create the RAM drive
#mkinitrd -f --preload hv_vmbus --preload hv_storvsc --preload hv_netvsc --preload hv_blkvsc /boot/initrd-2.6.33.2-1.img 2.6.33.2-1 - (Hyper-V only)
mkinitrd -f /boot/initrd-2.6.33.2.img 2.6.33.2
#mkinitramfs -o /boot/initrd-2.6.33.2.img
# Copy the config file to the boot folder
cp -v .config /boot/config-2.6.33.2
echo Please reboot the system now.
#bash #bsd #compile #kernel #linux #sysv