Re-compile the linux kernel and make your own kernel version

Feb 25, 2012 8:54 AM

.____/\ ._______.______  .______  ._______.___    
:   /  \: .____/: __   \ :      \ : .____/|   |   
|.  ___/| : _/\ |  \____||       || : _/\ |   |   
|     \ |   /  \|   :  \ |   |   ||   /  \|   |/\ 
|      \|_.: __/|   |___\|___|   ||_.: __/|   /  \
|___\  /   :/   |___|        |___|   :/   |______/
     \/+Suwardi - Sun Feb 19 09:25:41 2012                                


+++: Introduction

I have easy way to modify and recompile the linux kernel. I will not explain about what is the kernel, you can find huge explaination about kernel in internet or in the kernel documentation. In this article, i just want to show you tips about how to recompile the linux kernel with fun and easy way. 

+++: Step one, you must have the kernel source installed your linux machine. If you didn't have it, you must install. For example a kernel source in rpm.



# rpm -i kernel-headers*.rpm
# rpm -i kernel-source*.rpm
# rpm -i dev86*.rpm
# rpm -i bin86*.rpm

After you install the kernel source, check kernel source in /usr/src/linux. "linux" in this case is a symbolic link to directory linux-. So after you enter 'linux' directory, you are in a kernel source area. After the kernel source available, you can continued to step number two.

+++: Step two, backup the original kernel config. It's important, copy your original kernel config file, so you have kernel config backup.

# mv /usr/src/linux/.config /usr/src/linux/.config-original
# cp /boot/config-2.6.37-smp /usr/src/linux/.config
# cd /usr/src/linux

+++: Step three, modify the kernel config file. In this step you must be familiar with computer system like arch, irq, cpu, memory, dma, subsystem, .. etc. For example configuration:

#
# Automatically generated make config: don't edit
# Linux/i386 2.6.37-smp Kernel Configuration
# Sun Feb 19 09:25:41 2012
#

# CONFIG_64BIT is not set
CONFIG_X86_32=y

# CONFIG_X86_64 is not set
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_OUTPUT_FORMAT="elf32-i386"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/i386_defconfig"
CONFIG_GENERIC_CMOS_UPDATE=y
CONFIG_CLOCKSOURCE_WATCHDOG=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_HAVE_LATENCYTOP_SUPPORT=y
CONFIG_MMU=y
CONFIG_ZONE_DMA=y
# CONFIG_NEED_DMA_MAP_STATE is not set
CONFIG_NEED_SG_DMA_LENGTH=y
...

You can read the kernel documentation to find out these configuration items. Also you can define your configuration without editing config file, by using xconfig and menuconfig. Before running them, do cleaning first bellow:

# make clean
# make mrproper
then:
# make xconfig  <-- running in X window system (QT base)
or
# make gconfig <--running in X window system (GTK base)
or
# make menuconfig <-- text mode 
Select options do you want in the menu config.
By running menuconfig and xconfig will produce .config file as kernel configuration file. The important thing for this file is: 

--> Select proper CPU, is it x86, i386, DEC, Alpha,..etc

CONFIG_X86_32=y
CONFIG_X86=y

... and more

--> Select SMP support
CONFIG_X86_32_SMP=y

-->Select file system
CONFIG_VFAT_FS=y
CONFIG_NTFS_FS=y
CONFIG_SYSV_FS=m
CONFIG_UFS_FS=m

... and more

+++: Step four, now make dep:
# make dep

+++Step five, give an unique name for your kernel. To do this step, open Makefile in /usr/src/linux directory with your favorite text editor.

# vi Makefile

You can edit your the kernel version to your own version. For example: like: EXTRAVERSION=-2.6.37 change to EXTRAVERSION=-2.6.37-WAR49 or EXTRAVERSION=-2.6.37-my.kernel.24.feb.2012 or whatever... So, you can make you own version in this step.

+++: Step six, do make:

# make
# make modules
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      kernel/bounds.s
  GEN     include/generated/bounds.h
  CC      arch/x86/kernel/asm-offsets.s
  GEN     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
...

Check is there the error message if any. But if it doesn't have any error message, then do make modules_install.

# make modules_install
# make install

Both make modules and make modules_install takes too long time execution. So, you can go to bed while it execution and dreaming it will succeed or go for lunch and back when it done.

+++: Step seven, 'make' in the previous step will create 3 files in /boot: System.map-, config-, vmlinuz-. Then, in this step, you must inserti the vmlinuz into bootloader lilo/grub.


%%[ for lilo, add this in lilo configuration:
image = /boot/vmlinuz-2.6.37-WAR49-smp
root = /dev/sda1
label = slackware
read-only

%%[ for grub, add this in grub configuration file:
title           My kernel on slackware, kernel-2.6.37-WAR49-smp
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.37-WAR49-smp root=/dev/hda1 ro
savedefault
boot

+++: Optional step, you could create the initrd file. Not all computer create initrd, but it safe to do. The initrd file contains device drivers to load operating system later on.



# cd /boot
# mkinitrd -o initrd.img-2.6.37-WAR49-smp

%%[ add initrd result into the grub config file:
title           My kernel on slackware, kernel-2.6.37-WAR49-smp
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.37-WAR49-smp root=/dev/hda1 ro
initrd         /boot/initrd.img-2.6.37-WAR49-smp <-----\add this line\
savedefault
boot

+++: End step, reboot your linux, and go to your linux own version and check your kernel version.

wardi@darkstar:~$ uname -r
2.6.37-WAR49-smp



Article list :