Thursday 26 January 2012

How to compile a Kernel in linux

Kernel Compilation / Upgrading a kernel

Step # 1 Get Latest Linux kernel code

# yum install rpm-build redhat-rpm-config ncurses-devel unifdef

# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.8.tar.bz2

# tar -jxvf linux-2.6.38.8.tar.bz2 -C /usr/src/

# cd /usr/src

# ln -s linux-2.6.38.8  linux

# cd linux

# cp /boot/config-`uname -r` .config
when we run 'make menuconfig' it will read the .config file OR when we run 'make menuconfig' it will open a graphical window and we need to create some custom needs then it will create a .config automatically to read configuration from.

# make menuconfig  and select or deselect the packages/modules as said below

## make menuconfig = command to open a configuration menu for your kernel so that you can change options in the kernel

## make oldconfig = command to set up your kernel to use the options from the kernel you are currently booted into

## Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current  working kernel) as the configuration file. Then browse through the kernel configuration menu and make your choices.  Save it on exit.

Load an Alternate Configuration File

## Make sure you specify a kernel version identification string under "General Setup ---> () Local version - append  to kernel release" (in order for this setting in force, do not forget to select also "Automatically append version information to the version string").

General setup  --->
() Local version - append to kernel release
[*]Automatically append version information to the version string

## I have given 'test' as the string value to enter when prompted. the string test will append with the kernal version

## If you’re using straight-up-disks (no LVM or anything like that), you can just compile a kernel from kernel.org  without an initrd. But if you have something with LVM, and it’s your rootfs, you’re going to need an initrd at
 a minimum. The initrd is what takes care of finding/mounting your LVM volumes and allowing you to boot from it

## If you’re using straight-up-disks (no LVM or anything like that), you can just compile a kernel from kernel.org  without an initrd. But if you have something with LVM, and it’s your rootfs, you’re going to need an initrd at
 a minimum. The initrd is what takes care of finding/mounting your LVM volumes and allowing you to boot from it.

# Enable NTFS support,

File systems  --->
DOS/FAT/NT Filesystems  --->
<M> NTFS file system support
[*]   NTFS debugging support                                                                         
[*]   NTFS write support

## Sometimes after compiling and installing the kernel you will get an error like below when you boot with the new kernel,

##unmounting old /dev/
##unmounting old /proc
##unmounting old /sys
##switchroot: mount failed: No such file or directory
##Kernel panic - not syncing: Attempted to kill init

General setup  --->
[*] enable deprecated sysfs features to support old userspace tool
[*] enabled deprecated sysfs features by default

# make rpm

# make modules

# make modules_install

## cd /usr/src/linux
## make mrproper                # Clean everything, including config files
## make oldconfig                # Reuse the old .config if existent
## make menuconfig            # or xconfig (Qt) or gconfig (GTK)
## make                                 # Create a compressed kernel image
## make rpm                         # For creating a kernal RPM
## make modules                  # Compile the modules
## make modules_install       # Install the modules
## make install                       # Install the kernel
## reboot

// make && make rpm && make modules && make modules_install && make install

# cd  /usr/src/redhat/RPMS/i386/

# rpm -ivh kernel-2.6.38.8test-1.i386.rpm

# mkinitrd /boot/initrd-2.6.38.8test.img 2.6.38.8test

## Now edit /boot/grub/grub.conf to add the entry for the new kernel,

# vim /boot/grub/grub.conf
         title CentOS (2.6.38.8test)
         root (hd0,0)
         kernel /boot/vmlinuz-2.6.38.8test ro root=LABEL=/ rhgb quiet
         initrd /boot/initrd-2.6.38.8test.img 

Change "default" to the number of the new kernel.

##cd -
##pwd or cd /usr/src/linux

## To recompile the kernel, clean up the files created.
## make mrproper removes .config file.

To Clean the package folder
$$ make clean
$$ make mrproper
$$ make distclean
# uname -a
Linux pfx.com 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux

init 6
After reboot

# uname -a
Linux pfx.com 2.6.38.8test #1 SMP Wed Nov 9 20:00:58 IST 2011 i686 i686 i386 GNU/Linux


No comments:

Post a Comment