HomePage » Linux » LinuxKernel


Per process accounting

Compile kernel on Ubuntu 11

Before you begin, make sure there is enough space on /usr. You will need 10G of free spare. Download kernel, extract to /usr/src, symlink it to /usr/src/linux.

cd /usr/src/linux
cp /boot/config-$(uname -r) ./.config 
make menuconfig


In the next screen, choose select "Load an Alternate Configuration File" and load .config. Exit and save if you do not need to customize.

Backup /usr
cd /usr
tar cvf /backup/usr.tar . --exclude=./src


Build your kernel:
cd /usr/src/linux
make-kpkg clean
fakeroot make-kpkg --jobs=4 --initrd --revision=11.natty kernel-image kernel-headers
dpkg -i linux-image-2.6.39.2-*.deb
dpkg -i linux-headers-2.6.39.2-*.deb


A new entry will be added to grub.cfg automatically. Verify and reboot. Funny thing is some of the files under /usr were changed to be owned by non-root after the kernel upgrade. Problem with fakeroot? Do I even need to run make-kpkg with fakeroot if I simply run it as root? Anyway, restore the usr backup made before the compilation.


Compile kernel on CentOS

Obtain kernel source file from www.kernel.org. It's advised to download a major release that matches your machines. For instance, I have a CentOS4.4 running kernel 2.6.9, and I'll try to upgrade it to 2.6.20. Note that steps below might be a little different from what you've done on other distributions.

  1. Extract the kernel source into /usr/src (i.e. /usr/src/linux-2.6.20). Make a symlink to /usr/src/linux
  2. Copy the existing kernel build config. cp /boot/config-2.6.9-42.0.10.EL /usr/src/linux/.config
  3. Do a make oldconfig. It will prompt you to select options for newly available options. Be patient, you will have to answer a million questions.
  4. If you wish to make additional changes, do a make menuconfig
  5. Type make rpm. This involves serious waiting on my p3 notebook!

Now your kernel is build. It's time to install it.
  1. locate the built files at /usr/src/redhat/SRPMS & /usr/src/redhat/RPMS/i386
  2. Install the rpm by cd /usr/src/redhat/RPMS/i386 && rpm -ivh --nodeps kernel-2.6.20xxxxx.rpm
  3. run ldconfig just in case
  4. Create a ramdisk for the new kernel mkinitrd /boot/initrd-2.6.20xxx.img 2.6.20xxx - be careful with your current LD_LIBRARY_PATH, you might want to unset it before creating the initrd image
  5. Edit grub loader vi /boot/grub/menu.lst
  6. Reboot your system!

Post install
These are required for vbox / nvidia driver to build
cd /usr/src/linux
make prepare
make scripts


Compiling kernel in traditional way
These should work on other Linux distributions. After make oldconfig or make menuconfig above
  1. make all
  2. make modules_install
  3. make install
  4. Reboot your system!

Compiling kernel 2.4

  1. Download kernel from kernel.org
  2. cd /usr/src
  3. tar jxf linux-2.4.32.tar.bz2
  4. cd linux-2.4.32
  5. make mrproper
  6. cp /boot/config-2.4.xx.EL ./.config
  7. make oldconfig
  8. make menuconfig
  9. make dep
  10. make -j2 bzImage
  11. make -j2 modules
  12. cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.32
  13. make modules_install
  14. cp System.map /boot/System.map-2.4.32
  15. unlink /usr/src/linux-2.4
  16. ln -s /usr/src/linux-2.4.32 /usr/src/linux-2.4
  17. cd /boot
  18. mkinitrd /boot/initrd-2.4.32.img 2.4.32
  19. edit /etc/grub.conf
  20. reboot!

Editing Kernel image

cd /root/ && mkdir myinitrd/ && cd myinitrd/ (create temporary directory)
gzip -dc </boot/initrd-kernel_version.img|cpio -i (unpack the current initrd)
# do your thing
find . | cpio -o -c | gzip -9 > /boot/initrd-kernel_version.img (create the new initrd)
cd .. && rm -rf myinitrd/ (Cleanup)


Obtain kernel-source for RHEL

up2date --get-source kernel
cd /usr/src/redhat/SPECS/
rpmbuild -bp --target=<arch> kernel.spec


Obtain kernel-source for CentOS

yum install rpm-build redhat-rpm-config
# download kernel.src.rpm from http://mirror.centos.org/centos/5/updates/SRPMS/
rpm -Uvh kernel-xxxxx.src.rpm
cd /usr/src/redhat/SPECS
rpmbuild -bp --target i686 kernel-2.6.spec


Links

Preemptible kernel, seems to quite well on my desktop environment - http://www.linuxjournal.com/article/5600

There are 2 comments on this page. [Display comments]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki