How to update Linux kernel using YUM

Upgrading a kernel is always a difficult task . If anything goes wrong during the upgrade, the system may become unusable. If you are upgrading the kernel from source , then it needs lots of time and presence of mind while doing the upgrade .  But after yum has come into the picture of package management, upgrading a kernel has become quite easy and that's also in one step .

Using YUM to update the Linux kernel:

Upgrading the Linux kernel using yum is quite easy. yum is intelligent enough in not upgrading the current kernel. Yum installs a newer kernel without upgrading the existing kernel . So , if the new kernel fails to boot up , then you can still use your system by booting from your old kernel . During the upgrade , it also takes care to make entry of the new kernel in /boot/grub/grub.conf  without making any changes to the old entires . So , upgrade your kernel and test it out. Before going with the upgrade , keep a backup of your grub configuration file. The following are the steps I have followed while doing the upgrade on a RHEL 5 box. 




1. Keep a backup of your existing grub boot loader config file  
       $  sudo cp /boot/grub/grub.conf /boot/grub/grub.conf.orig

2. Fire the yum update command to upgrade the kernel. 
      $  sudo yum update kernel    
          Loading "installonlyn" plugin
          Loading "rhnplugin" plugin
          Loading "security" plugin
          This system is not registered with RHN.
          RHN support will be disabled.
          Setting up Update Process
          Setting up repositories
          Reading repository metadata in from local files
          Skipping security plugin, no data
          Resolving Dependencies
          Skipping security plugin, no data
          Populating transaction set with selected packages. Please wait.
          Package kernel.i686 0:2.6.18-164.2.1.el5 set to be installed
          Running transaction check
         Dependencies Resolved
        ==================================================================
        Package                Arch       Version             Repository          Size
        ==================================================================
         Installing:
         kernel                  i686    2.6.18-164.2.1.el5   updates            16 M
        Transaction Summary
        =================================================================
        Install          1 Package(s)        
        Update        0 Package(s)        
        Remove       0 Package(s)        
        Total download size: 16 M
        Is this ok [y/N]: y
        Downloading Packages:
       (1/1): kernel-2.6.18-164. 100% |===============|  16 MB    00:59    
        Running Transaction Test
        Finished Transaction Test
        Transaction Test Succeeded
        Running Transaction
        Installing: kernel                       ######################### [1/1]
       Installed: kernel.i686 0:2.6.18-164.2.1.el5
       Complete!

 



3. Check the grub config file to view entry of the new kernel. 

      $ sudo diff /boot/grub/grub.conf /boot/grub/grub.conf.or
       14,17d13 
        title Red Hat Enterprise Linux Server (2.6.18-164.2.1.el5)
        root (hd0,2)
        kernel /vmlinuz-2.6.18-164.2.1.el5 ro root=/dev/md0 pci=nommconf rhgb quiet
        initrd /initrd-2.6.18-164.2.1.el5.img
 

Thus we can see that a new entry was made in /boot/grub/grub.conf which points to the new kernel. Reboot your box and put the new kernel into test.

Comments

Anonymous said…
> it also takes care to make entry of the new kernel in /boot/grub/grub.conf without making any changes to the old entires

What mechanism is used to modify the grub.conf without removing any of the other entries? Is this something specific to YUM? I did not think that RPM binaries had the ability to modify files rather than outright replacing them entirely.
Brian Wilkins said…
It's part of the kernel RPM upgrade scriptlet. In the postinstall scriptlet, it runs /sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install

Man page for new-kernel-pkg (http://linux.die.net/man/8/new-kernel-pkg):

"new-kernel-pkg is a tool used in packaging to automate the installation of a new kernel, including the creation of an initial ram filesystem image, updating of bootloader configuration, and other associated tasks. "

Popular Posts