Re: rolling your own kernel - guidelines?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Florin Andrei wrote:
Let's say I want to use a much newer kernel - even one from the future, such as the upcoming 2.6.24. :-) What would y'all smart folks do in this case, in order to avoid any possible nasty consequences? Would you import the config file from the original CentOS5 kernel into the new kernel, and let the kernel deal with the differences? I.e. have the old configuration as some sort of baseline that can be further tweaked.
Or some other strategy?

I may post a real HOWTO, or add a page to the wiki, if I get a chance, but until then, here's what I did to obtain a newer kernel package as similar as possible to the default CentOS kernel.

Install CentOS in a new VMware instance, or on a clean system. Make sure to install the Development packages, and also the relevant kernel packages, especially kernel-devel and kernel-headers. kernel-doc doesn't hurt either. ;-) This will be your clean build environment.

Optionally, create a dedicated account for building packages as non-root. This is discussed in other HOWTOs. Login as that account.

Do a "yum update" to get all the recent patches and updates. Reboot.

Get the kernel source tarball with the desired kernel version. Unpack, do "make clean; make mrproper"

Get the CentOS kernel's config file (it's in /boot, e.g. /boot/config-2.6.18-8.1.14.el5) and save it into the kernel source tree as ".config"
Then do a "make oldconfig".

Optionally, do a "make menuconfig" and tweak the kernel options even more.
You may especially want to edit the CONFIG_LOCALVERSION field to reflect the fact that you're building a custom kernel. I prefer to make that field "COMPANYNAME.x" where x is the build number - start with x=1 for the first build, and bump it up as you're building new versions of the same kernel. This will enable painless upgrades if you decide to tweak the kernel options later.

Save the .config file (now modified by the make commands) in a safe place for future re-use.

Apply this patch to the scripts/package/mkspec file (careful, at least one line is wrapped by the Gmane mail archive, so unwrap manually):

http://thread.gmane.org/gmane.linux.kernel/593172

Or just use the patch file attached to this message if the mail archive doesn't work for you. Either way, the command to apply the patch is the same - from within the kernel source tree, run:

patch -p1 < mkspec.patch

Do "make rpm"

You will obtain a kernel rpm package that is similar in kernel features to the original CentOS kernel. Also, the package will do the right things (modify grub.conf, build initrd) when installed or uninstalled - that's what my patch to mkspec does.

Install with "rpm -i". Do not install with "rpm -U" (but you should know that already).

You may also want to upgrade packages such as iproute and iptables if you're using fancy features of very recent kernels. The actual versions to upgrade to depend on what you're doing. This upgrade may not be needed in "boring" scenarios.

Works For Me (TM) on CentOS 5 x86_64 with kernel 2.6.23.1

--
Florin Andrei

http://florin.myip.org/
--- linux-2.6.23.1.orig/scripts/package/mkspec	2007-10-19 02:07:58.000000000 -0700
+++ linux-2.6.23.1/scripts/package/mkspec	2007-10-19 05:42:47.000000000 -0700
@@ -81,6 +81,11 @@ echo 'cp $KBUILD_IMAGE $RPM_BUILD_ROOT'"
 echo "%endif"
 echo "%endif"
 
+if $RPM_RH5_STYLE; then
+echo 'touch $RPM_BUILD_ROOT'"/boot/initrd-$KERNELRELEASE.img"
+echo 'gzip -c9 < Module.symvers > $RPM_BUILD_ROOT'"/boot/symvers-$KERNELRELEASE.gz"
+fi
+
 echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$KERNELRELEASE"
 
 echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$KERNELRELEASE"
@@ -88,9 +93,44 @@ echo ""
 echo "%clean"
 echo '#echo -rf $RPM_BUILD_ROOT'
 echo ""
+
+if $RPM_RH5_STYLE; then
+cat <<RH5_POST_PREUN
+%post
+if [ `uname -i` == "x86_64" -o `uname -i` == "i386" ]; then
+  if [ -f /etc/sysconfig/kernel ]; then
+    /bin/sed -i -e 's/^DEFAULTKERNEL=kernel-smp$/DEFAULTKERNEL=kernel/' /etc/sysconfig/kernel || exit $?
+  fi
+fi
+/sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install $KERNELRELEASE || exit $?
+if [ -x /sbin/weak-modules ]
+then
+    /sbin/weak-modules --add-kernel $KERNELRELEASE || exit $?
+fi
+
+%preun
+/sbin/new-kernel-pkg --rminitrd --rmmoddep --remove $KERNELRELEASE || exit $?
+if [ -x /sbin/weak-modules ]
+then
+    /sbin/weak-modules --remove-kernel $KERNELRELEASE || exit $?
+fi
+
+RH5_POST_PREUN
+fi
+
 echo "%files"
 echo '%defattr (-, root, root)'
 echo "%dir /lib/modules"
 echo "/lib/modules/$KERNELRELEASE"
+if $RPM_RH5_STYLE; then
+cat <<RH5_FILES
+/boot/vmlinuz-$KERNELRELEASE
+/boot/System.map-$KERNELRELEASE
+/boot/symvers-$KERNELRELEASE.gz
+/boot/config-$KERNELRELEASE
+%ghost /boot/initrd-$KERNELRELEASE.img
+RH5_FILES
+else
 echo "/boot/*"
+fi
 echo ""
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux