Compile the Linux Kernel


Root = (0,1)

Kernel = /boot/vmlinuz-3.0

initrd = /boot/initrd-3.0

First HDD
Second HDD
MBR
root (0,1)
/dev/sda1
/dev/sda2

MBR
root (1,1)
/dev/sdb1
/dev/sdb2

Kernel/boot/vmlinuz-3.0 is the Kernel consist of all necessary drivers software for booting (eg. Motherboard, Chipset). So the kernel will normally huge in size.


Drivers software which is not necessary for the booting process stored outside the kernel called Modules.

For compiling the kernel first user must know where is the source, either from DVD or from Linux itself in the PC. User can download the full kernel from Internet also.

  1. If the kernel is in DVD or compiling linux in system, first need to get the source. We can search it by, #apt-cache search linux-source. Install this linux source by #apt-get install linux-source-3.10. It will be installed in /usr/src as a bzip2 formate (ZIP file). Go to that location by #cd /usr/src then uncompress it #tar -xvjf linux-source-3.10.10.tar.bz2
    or
    If the kernel download from https://www.kernel.org/, will get a file named linux-3.10.tar.xz, save that file to /usr/src. After that unzip it by #unxz linux-3.10.tar.xz.

  2. After uncompress user can see a file in /usr/src as Linux-3.10. The standard format of compiling directory is /usr/src/linux. We create a softlink for that prupose. #ln-s /usr/src/linux-3.10 /usr/src/linux.

  3. For compilation need to install two packages. GCC and Lib n Curses. For that we install #apt-get install gcc, #apt-get install libncurses5-dev.

  4. Now need to move the location linux, #cd /usr/src/linux. After that we start to configure the kernel #make menuconfig (creates a menu where can browse options on what the kernel supports. Requires ncurses library, but that is likely already on computer). Once the configuration window is opened, will see that a specific type of configuration is already selected like support for essential drivers like Broad com wireless support/EXT4 file system etc. Configure the kernel and it will save in .Config

  5. Once the configuration finish user can compile and install the kernel. #make && make modules_install && make install

  6. Now need to make it bootable, for that there is a bz image file in /usr/src/linux/srch/i386/boot move that to /boot. #cd /usr/src/linux/srch/i386 /boot then #cp bzImage /boot. If need to check go to /lib/modules. #cd lib/modules, use #ls-l. User can see the value (3.10)

  7. Now need to create initrd for that #update-initramfs -c-k 3.10.

  8. Now need to update GRUB, for that need to go the location.
    In Wheezy #cd /boot/grub then #nano grub.cfg.
    In Older versions #cd /boot/menu then #nano menu.lst
    Last part change to

### BEGIN /etc/grub.d/10_linux ###

menuentry 'Wheezy' --class debian --class gnu-linux --class gnu --class os {

load_video

insmod gzio

insmod part_msdos

insmod ext2

set root='(hd0,msdos2)'

search --no-floppy --fs-uuid --set=root c29476a5-6178-4e70-8409-e1209cf0067e

echo 'Loading Linux 3.2.0-4-686-pae ...'

linux /boot/vmlinuz-3.2.0-4-686-pae root=UUID=c29476a5-6178-4e70-8409-e1209cf0067e ro quiet

echo 'Loading initial ramdisk ...'

initrd /boot/initrd.img-3.2.0-4-686-pae

}

Title need to change;

root = '(hd0,msdos2)'

linux /boot/bzImage-3.10 root = /dev/hda0

initrd /boot/initrd.img-3.10. 

Reboot and enjoy your customized kernel.

No comments:

Post a Comment