13 Maret 2013

linux kernel kompilation

again? yeah sadly!
  • 0. Source Preparation
    If you just downloaded the latest kernel, just go to no. 1. In case you already have previous kernel source, you should download just the patch, instead of downloading the whole new kernel. How to apply patch? its in the kernel Documentation/applying-patches.txt
    summary:
    in version 3 kernel, linux patch from 3.x.y is relative to 3.x
    but the patch of 3.x1 is relative to 3.x0
    illustration:
    linux-3.8.2/ is created from linux-3.7.9, so you have to go back to 3.7
    from 3.7.9 apply reverse patch you get 3.7
    apply patch (forward) from 3.7 to 3.8
    apply patch (forward) from 3.8 to 3.8.2
    voila!
    note: What if my kerne source is 3.0.1? just go back to 3.0 then repeatedly patch forward 3.1, 3.2, ..., until 3.8, then apply 3.8 to 3.8.2
    in short:
    $ cd kernel-source-directory
    for reverse patch (-R option)
    $ patch -R -p1 < ../patch-x.y.z
    for (forward) patch
    $ patch -p1 < ../patch-x.y.z

    Now you can configure your kernel.
    small note on .config file, keep it back up, every time runs make menuconfig.
  • 1. In Debian
    If you want to be cool even though in debian, go to no. 2.
    Debian has a very nice tool to compile kernel.
    http://www.debian.org/releases/stable/i386/ch08s06.html.en
    $ make menuconfig
    $ make-kpkg clean
    $ fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image
    you might want the header as well
    $ fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_header
    ok you've got a deb package, just run dpkg -i  on it.
    nice and easy but it takes time for compilation somehow, because it doesn't compile incrementally, clean up everything every time make-kpkg runs. If you want the incremental compilation check the traditional way, no. 2.
  • 2. Traditional
    http://kernelnewbies.org/FAQ/KernelCompilation
    in short:
    compile everything
    $ make

    install modules, it will create the kernel directory /lib/modules/x.y.z and fill it with the kernel modules. Basically this is the kernel modules that you marked as [M] on kernel config.
    # make modules_install

    install the kernel into /boot, yep the kernel is just one file vmlinuz.x.y.z. It will not touch your /lib/modules directory.
    # make install
    not mandatory but preferable to create the initrd image, option -c for creating new, and -k for kernel version
    # update-initramfs -c -k x.y.z

    update your boot menu, I only know for _debian_
    run this anywhere, then copy  the grub.cfg into /boot/grub/
    # grub-mkconfig -o grub.cfg

voila, it's done,  just reboot!