[BlueOnyx:15251] Re: Kernel Question

Michael Stauber mstauber at blueonyx.it
Wed Apr 23 08:35:56 -05 2014


Hi Chuck,

> But the MAN page on "sort" doesn't show a lower-case "v" switch.  I still tried 
> it mind you, but got the same error as the capital "V" - "invalid option".


>From "man sort" on a 5107R/5108R:

       -V, --version-sort
              natural sort of (version) numbers within text

And yes, the CentOS5 based "sort" is missing that option. The script
that was bounced around in this topic was rather for CentOS6/SL6 where
we've had problems with the grub configuration once.

So let me break that sequence of commands down for you:

ls -k1 /boot/vmlinuz-*| sed s#/boot/vmlinuz-##|sort -V -r|head -1

First step does an "ls" command. It with the "-k1" option it will report
full paths and filenames, but no baggage like file size or permissions:

ls -k1 /boot/vmlinuz-*
/boot/vmlinuz-2.6.32-042stab085.17
/boot/vmlinuz-2.6.32-042stab085.20
/boot/vmlinuz-2.6.32-042stab088.4

The "sed" command afterwards removes "/boot/vmlinuz-" from the output
that the directory listing of kernels gave.

So at that point we just have the version number and release number
left. On an Aventurin{e} the output at that point will look like this:

ls -k1 /boot/vmlinuz-*| sed s#/boot/vmlinuz-##


2.6.32-042stab085.17



2.6.32-042stab085.20



2.6.32-042stab088.4

Now that's where the "sort -V -r" comes in. It nicely sorts the output
according to version and release number:

ls -k1 /boot/vmlinuz-*|sed s#/boot/vmlinuz-##|sort -V -r


2.6.32-042stab088.4



2.6.32-042stab085.20



2.6.32-042stab085.17

The final command in that list uses "head -1" to trim that output down
to just the topmost entry with the highest version (and release):

ls -k1 /boot/vmlinuz-*| sed s#/boot/vmlinuz-##|sort -V -r|head -1
2.6.32-042stab088.4

So we now have the info that the kernel "2.6.32-042stab088.4" is the
latest one present on that particular box.

That's where the actual kernel activation script comes in. It gets run
with the version number of the kernel as final parameter like this:

/sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install
--make-default 2.6.32-042stab088.4

It will also rebuild the initrd of that kernel and will make the new
kernel the default kernel in either grub or lilo (depending what's present).

Bottom line: The purpose of this script is to parse /boot/ to check
which is the latest kernel. And then to make this the active kernel in
grub.conf

Which is the opposite of what you seem to need. I'm not sure why your
server won't boot with the latest CentOS5 kernels. Is your hardware a
bit out of the ordinary? Or anything special about it?

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list