Installing the Grub2 tools on CentOS 7 to upgrade the kernel
I'm very fond of Packet.net, but when I tried to use my previous procedure to upgrade the kernel there, I run into some unexpected bumps with the grub2 tools missing which really threw me off. Of course, this isn't a problem specific to Packet.net but it's the first time I bumped into it. Here's what the steps look like to solve this.
1. First things first - Replace gzip with pigz so package installing goes faster:
yum -y install pigz
mv /usr/bin/gzip /usr/bin/gzip.old
ln -s /usr/bin/pigz /usr/bin/gzip
2. Check running kernel:
uname -a
Linux grub-testing 3.10.0-327.22.2.el7.x86_64 #1 SMP Thu Jun 23 17:05:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
3. Check what the installed kernel RPM is:
kernel-3.10.0-514.16.1.el7.x86_64
4. See that? the versions are different. Let's upgrade the kernel:
yum -y install kernel kernel-devel
5. Install the Grub tools so that we can tell Grub to boot with the new kernel:
yum -y install grub2-tools grub2-tools-minimal
6. OK, nice - now regenerate your /boot/grub/grub.cfg file with:
grub2-mkconfig -o /boot/grub/grub.cfg
You should see output like this:
grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.2.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.2.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.16.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.16.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.22.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.22.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ed21cfeae62c9d8b440cbc3f8e696dce
Found initrd image: /boot/initramfs-0-rescue-ed21cfeae62c9d8b440cbc3f8e696dce.img
done
7. Brilliant - now get the list of kernels:
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg
0 : CentOS
uh... wait, what? where are all the other kernels that we saw in the output of grub2-mkconfig -o /boot/grub/grub.cfg above ???
8. Turns out, that submenus are enabled by default and the awk command above doesn't show us the correct output. Let's fix that!
Edit the file /etc/default/grub and add this line at the bottom:
GRUB_DISABLE_SUBMENU=y
9. Re-run the grub2-mkconfig -o /boot/grub/grub.cfg command:
grub2-mkconfig -o /boot/grub/grub.cfg
10. Re-run the awk command again:
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg
0 : CentOS Linux (3.10.0-693.2.2.el7.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-693.2.2.el7.x86_64) 7 (Core) (recovery mode)
2 : CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core) (recovery mode)
4 : CentOS Linux (3.10.0-327.22.2.el7.x86_64) 7 (Core)
5 : CentOS Linux (3.10.0-327.22.2.el7.x86_64) 7 (Core) (recovery mode)
6 : CentOS Linux (0-rescue-ed21cfeae62c9d8b440cbc3f8e696dce) 7 (Core)
7 : CentOS Linux (0-rescue-ed21cfeae62c9d8b440cbc3f8e696dce) 7 (Core) (recovery mode)
Much better!!!
11. Now choose the 3.10.0-693 kernel by typing: grub2-set-default 0
grub2-set-default 0
Yup, the above command has no output, that's normal.
12. Confirm that 0 is going to be the next kernel:
grub2-editenv list
saved_entry=0
13. Reboot the system to switch to the new kernel:
reboot
14. Once it comes back up, confirm what's your running kernel:
[root@grub-testing ~]# uname -a
Linux grub-testing 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Our kernel upgrade was a success!
15. Check the packages as well:
kernel-3.10.0-693.2.2.el7.x86_64
kernel-devel-3.10.0-693.2.2.el7.x86_64
kernel-3.10.0-514.16.1.el7.x86_64
16. See that 3.10.0-514 package? It's safe to remove if you wish.
yum -y remove kernel-3.10.0-514.16.1.el7