sobota, 5 listopada 2011

CentOS 6.0: Updating the kernel to 3.0.8

I wanted to continue the work on the clustered filesystems and found out that linux kernel since 2.6.37 provides additional cluster filesystem ceph (http://ceph.newdream.net/) to the previosuly available gfs (gfs2), ocfs2. The description sounds promising so why not to give it a try.
However in my virtualized environment I had only CentOS'es (one running the latest 6.0) with much older kernel version (2.6.32). The standard repositories does not contain any updates and the only way to run a newer version is to download it from kernel.org and compile it by yourself. The instruction below describes the steps that I did in order to have the kernel 3.0.8 on the CentOS 6.0.

1. Prepare disk space for kernel sources, compilation output and produced rpm packages (about 5GB needed for creating the binary package, header and sources).
2. Download the sources from the kernel.org and unpack them. You can do it on the fly using the following command:

[root@localhost tmp]# wget -O - http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.8.tar.bz2 | bzip2 -d - | tar -xvf -

3. Now copy your existing configuration file and adapt it to your needs as described in step 4 (I used the menuconfig and loaded the file):

[root@localhost linux-3.0.8]# cp /boot/config-2.6.32-71.29.1.el6.x86_64 .
[root@localhost linux-3.0.8]# make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/mconf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/lex.zconf.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf Kconfig
#
# configuration written to config-3.0.4
#




*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.


[root@localhost linux-3.0.8]# 


4. Apply the changes. I have added support for ceph, ocfs2 and added the module to dump the current kernel config to the /proc filesystem.

5. Now you are ready to compile and prepare the rpms containing the new kernel. I used the target to build only binary packages (you can also create the sources package). The rpms will be created in user's home directory: $HOME/rpmbuild/:


[root@localhost linux-3.0.8]# make help | grep rpm
  rpm-pkg             - Build both source and binary RPM kernel packages
  binrpm-pkg          - Build only the binary kernel package
[root@localhost linux-3.0.8]# time make binrpm-pkg
/bin/sh /mnt/tmp/linux-3.0.8/scripts/package/mkspec prebuilt > /mnt/tmp/linux-3.0.8/binkernel.spec
make KBUILD_SRC=
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  CC      kernel/bounds.s
  GEN     include/generated/bounds.h
  CC      arch/x86/kernel/asm-offsets.s
  GEN     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/lex.c
  SHIPPED scripts/genksyms/parse.h
  SHIPPED scripts/genksyms/keywords.c
  HOSTCC  scripts/genksyms/lex.o
  ...
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Processing files: kernel-headers-3.0.8-1.x86_64
Provides: kernel-headers = 3.0.8
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(VersionedDependencies) <= 3.0.3-1
Obsoletes: kernel-headers
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/kernel-3.0.8-1.x86_64
Wrote: /root/rpmbuild/RPMS/x86_64/kernel-3.0.8-1.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/kernel-headers-3.0.8-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.VjVenh
+ umask 022
+ cd /mnt/tmp/linux-3.0.8
+ rm -rf /root/rpmbuild/BUILDROOT/kernel-3.0.8-1.x86_64
+ exit 0

real 85m20.491s
user 59m40.551s
sys 12m32.836s
[root@localhost linux-3.0.8]# ls -lh /root/rpmbuild/RPMS/x86_64/
-rw-r--r-- 1 root root 262M Nov  5 19:13 kernel-3.0.8-1.x86_64.rpm
-rw-r--r-- 1 root root 786K Nov  5 19:13 kernel-headers-3.0.8-1.x86_64.rpm


6. Install the new kernel rpm package:

[root@localhost linux-3.0.8]# rpm -i /root/rpmbuild/RPMS/x86_64/kernel-3.0.8-1.x86_64.rpm
[root@localhost linux-3.0.8]# 

7. Do the postconfiguration to boot the new kernel - the easier way is to do it using the 7.1 step and only check if the files described in manual procedure are created/configured properly.


7.1 Automatically using the new-kernel-pkg utility:


[root@localhost linux-3.0.8]# new-kernel-pkg --mkinitrd --install --make-default --depmod 3.0.8


7.2 Manually (when previous used it can be skipped - everything already done by the new-kernel-pkg utility)

7.2.1 Create the initrd image:

[root@localhost linux-3.0.8]# mkinitrd -f /boot/initramfs-3.0.8.x86_64.img 3.0.8

7.2.2 Adapt the grub menu so that the new kernel becomes an option, below an example from my system:

[root@localhost boot]# vim /boot/grub/menu.lst
...

title CentOS Linux (3.0.8.x86_64)
        root (hd0,0)
        kernel /vmlinuz-3.0.8 ro root=/dev/mapper/vg_centos6hosta-lv_root rd_LVM_LV=vg_centos6hosta/lv_root rd_LVM_LV=vg_centos6hosta/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
        initrd /initramfs-3.0.8.x86_64.img

8. Reboot the system and start the new kernel. Afterwards you should see:


[krychu@localhost ~]$ uname -a
Linux localhost.localdomain 3.0.8 #1 SMP Sat Nov 5 18:56:32 CET 2011 x86_64 x86_64 x86_64 GNU/Linux
[krychu@localhost ~]$ 


Please notice: when running on a virtual system with VirtIO disks (recognized by the guest system as vda devices) please check if the virtio_blk module is enabled (otherwise you will not be able to mount the root filsystem).



2 komentarze:

  1. Thanks for this. One thing I had to do that wasn't mentioned was:

    new-kernel-pkg --mkinitrd --install --make-default --depmod 3.2.9

    OdpowiedzUsuń
  2. Thanks for the feedback. The new-kernel-pkg is a very useful utility. I will update the instruction accordingly. Additionally when using it one can skip steps for creating the initrd and updating the grub configuration at all and only check if the utility did the job properly.

    OdpowiedzUsuń