Building a New Custom Kernel

NOTIFICATION: These examples are provided for educational purposes. Using this code is under your own responsibility and risk. The code is given ‘as is’. I do not take responsibilities of how they are used.

1- Preparing your system:
a- Download your new kernel from www.kernel.org
b- Make yourself the administrator: sudo -i
c- Install the following libraries which are going to be use by menuconfig and xconfig when making changes to your kernel
i. if you plan to use ‘make xconfig’: sudo apt-get install qt3-dev-tools libqt3-mt-dev
ii. if you plan to use ‘make menuconfig’: sudo apt-get install libncurses5 libncurses5-dev
d. Make a backup of all your information. You never know how bad things can get.

2- Prepare your new kernel for installation (as root):

a- Move your file to your home folder:
i. cd /home/your-home-folder
ii. Assuming your compress kernel file is in your Desktop:
I. mv ./Desktop/linux-2.6.XX.XX.tar.YY
II. XX are the numbers your kernel version, YY is the extension of the compress file
b- Extract the files of your new kernel:
i. if your compressed file kernel ends in .bz2: tar xvjf linux-2.6.XX.XX.tar.bz2
ii.if your compressed file kernel ends in .gz: tar xvzf linux-2.6.XX.XX.tar.gz
c- Create a symbolic link from one subdirectory to another subdirectory
i. ln -s linux-2.6.XX.XX linux
ii. linux-2.6.XX.XX is the subfolder created when uncompressing the compressed kernel file, linux is the directory symbolic link pointing to linux-2.6.XX.XX subfolder. So, if you need to start again, you only have to uncompress the kernel compressed file.

3- Install your new kernel (as root):
a. make clean
b. if you want to configure everything from scratch without using the old config: make mrproper
c. If you would like to see what is different between your original kernel config and the new one: make oldconfig
d. If you want to update the configuration to to only compile modules that are actually used in your system (feature only since 2.6.32 kernel): make localmodconfig
e. Configurate your config, you can you menuconfig(Text Mode) or xconfig(GUI mode):
i. make menuconfig
ii. make xconfig
f. After making any modification on which modules should be on the kernel (y or n) and which should be load after the kernel is load (m).
i. Save the configuration in .config or .Kconfig
ii. For information about which modules are being use by the system you can:
I. Look at the information about all loaded modules: lsmod
II. Check the kernel ring buffer: dmesg
III. Check the system log: cat /var/log/syslog | more
IV. Check the system messages: cat /var/log/messages | more
g. Compile the kernel (can take some time): make bzImage 2> bzImage.err
i. The 2> bzImage.err will forward any error messages to the file bzImage.err
h. Compile all of the modules which you did not specify in the kernel configuration: make modules
i. Installs the modules in /lib/modules/x.y.z, where x.y.z is the kernel release: make modules_install
j. Install kernel itself: make install
k. Create an image:
i. cd /boot
ii. Generating an initramfs image: mkinitramfs -o initrd.img.2.6.XX 2.6.XX

4- Configurate grub (as root)
a- install gedit or use your preference editor
i. apt-get install gedit
b- Modify the grub configuration file:
i. if you are using Grub
I. cd /boot/grub
II. gedit menu.lst
III. Using # to make a line as a comment, turn to comments lines that have
1. “nomenu” or “hiddenmenu”,
IV. Increase the timeout (for example from 5 to 30, so you will have 30 seconds)
ii. if you are using Grub2
I. cd /etc/default
II. gedit grub
1. Comment this line using #, so menu will show:

GRUB_HIDDEN_TIMEOUT=0

2. Increase number of second: GRUB_TIMEOUT=5 to GRUB_TIMEOUT=30
3. if you want to see the counting of second: GRUB_HIDDEN_TIMEOUT_QUIET=true to GRUB_HIDDEN_TIMEOUT_QUIET=false
c. Use update-grub which will check your folder /boot and make the proper changes: update-grub
d. reboot

If you encounter any problems or errors, please let me know by providing an example of the code, input, output, and an explanation. Thanks.

Share
Leave a comment