Formatting code for LinuxKernel
{{parent page="Linux"}}
==[[LinuxKernelIOAccounting 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
1) Copy the existing kernel build config. cp /boot/config-2.6.9-42.0.10.EL /usr/src/linux/.config
1) 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.
1) If you wish to make additional changes, do a **make menuconfig**
1) 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
1) Install the rpm by **cd /usr/src/redhat/RPMS/i386 && rpm -ivh --nodeps kernel-2.6.20xxxxx.rpm**
1) run ldconfig just in case
1) 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
1) Edit grub loader **vi /boot/grub/menu.lst**
1) 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
1) make modules_install
1) make install
1) Reboot your system!
=== Compiling kernel 2.4===
1) Download kernel from kernel.org
1) cd /usr/src
1) tar jxf linux-2.4.32.tar.bz2
1) cd linux-2.4.32
1) make mrproper
1) cp /boot/config-2.4.xx.EL ./.config
1) make oldconfig
1) make menuconfig
1) make dep
1) make -j2 bzImage
1) make -j2 modules
1) cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.32
1) make modules_install
1) cp System.map /boot/System.map-2.4.32
1) unlink /usr/src/linux-2.4
1) ln -s /usr/src/linux-2.4.32 /usr/src/linux-2.4
1) cd /boot
1) mkinitrd /boot/initrd-2.4.32.img 2.4.32
1) edit /etc/grub.conf
1) 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
==[[LinuxKernelIOAccounting 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
1) Copy the existing kernel build config. cp /boot/config-2.6.9-42.0.10.EL /usr/src/linux/.config
1) 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.
1) If you wish to make additional changes, do a **make menuconfig**
1) 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
1) Install the rpm by **cd /usr/src/redhat/RPMS/i386 && rpm -ivh --nodeps kernel-2.6.20xxxxx.rpm**
1) run ldconfig just in case
1) 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
1) Edit grub loader **vi /boot/grub/menu.lst**
1) 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
1) make modules_install
1) make install
1) Reboot your system!
=== Compiling kernel 2.4===
1) Download kernel from kernel.org
1) cd /usr/src
1) tar jxf linux-2.4.32.tar.bz2
1) cd linux-2.4.32
1) make mrproper
1) cp /boot/config-2.4.xx.EL ./.config
1) make oldconfig
1) make menuconfig
1) make dep
1) make -j2 bzImage
1) make -j2 modules
1) cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.32
1) make modules_install
1) cp System.map /boot/System.map-2.4.32
1) unlink /usr/src/linux-2.4
1) ln -s /usr/src/linux-2.4.32 /usr/src/linux-2.4
1) cd /boot
1) mkinitrd /boot/initrd-2.4.32.img 2.4.32
1) edit /etc/grub.conf
1) 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