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.- Extract the kernel source into /usr/src (i.e. /usr/src/linux-2.6.20). Make a symlink to /usr/src/linux
- Copy the existing kernel build config. cp /boot/config-2.6.9-42.0.10.EL /usr/src/linux/.config
- 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.
- If you wish to make additional changes, do a make menuconfig
- Type make rpm. This involves serious waiting on my p3 notebook!
Now your kernel is build. It's time to install it.
- locate the built files at /usr/src/redhat/SRPMS & /usr/src/redhat/RPMS/i386
- Install the rpm by cd /usr/src/redhat/RPMS/i386 && rpm -ivh --nodeps kernel-2.6.20xxxxx.rpm
- run ldconfig just in case
- 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
- Edit grub loader vi /boot/grub/menu.lst
- Reboot your system!
Post install
These are required for vbox / nvidia driver to buildcd /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- make all
- make modules_install
- make install
- Reboot your system!
Compiling kernel 2.4
- Download kernel from kernel.org
- cd /usr/src
- tar jxf linux-2.4.32.tar.bz2
- cd linux-2.4.32
- make mrproper
- cp /boot/config-2.4.xx.EL ./.config
- make oldconfig
- make menuconfig
- make dep
- make -j2 bzImage
- make -j2 modules
- cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.32
- make modules_install
- cp System.map /boot/System.map-2.4.32
- unlink /usr/src/linux-2.4
- ln -s /usr/src/linux-2.4.32 /usr/src/linux-2.4
- cd /boot
- mkinitrd /boot/initrd-2.4.32.img 2.4.32
- edit /etc/grub.conf
- 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
There are 2 comments on this page. [Display comments]