Skip to main content
Back to Category

Kernel Update and GRUB Management: Safe Guide

How to update the kernel with apt/yum, check current kernel version, configure GRUB, roll back to a previous kernel, and safely manage kernel updates on Linux servers.

Read time: 12 min Server Management
kernelgrublinux kernelupdateaptyumrollback

Table of Contents

Kernel Update and GRUB Management: Safe Guide

The Linux kernel is the core of the operating system, bridging hardware and software. Kernel updates close security vulnerabilities, add new hardware support, and provide performance improvements. This guide covers the kernel update process, GRUB configuration, and how to roll back to a previous kernel version if issues arise.

Checking the Current Kernel Version

hljs bash
# View running kernel version
uname -r

# Detailed kernel information
uname -a

# Example output:
# Linux hostname 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64

# List all installed kernel versions (Ubuntu/Debian)
dpkg --list | grep linux-image

# RHEL/CentOS/AlmaLinux
rpm -qa | grep kernel

Updating the Kernel

Kernel Update on Ubuntu/Debian

hljs bash
# Update package list
sudo apt update

# List available updates
apt list --upgradable | grep linux

# Update entire system (including kernel)
sudo apt upgrade -y

# Update only the kernel
sudo apt install linux-image-generic linux-headers-generic

# Install a specific kernel version
sudo apt install linux-image-5.15.0-91-generic

# Reboot after update
sudo reboot

Kernel Update on RHEL/CentOS/AlmaLinux

hljs bash
# Update package list
sudo dnf update

# Update only the kernel
sudo dnf update kernel

# List installed kernel versions
sudo dnf list installed kernel

# Reboot after update
sudo reboot

A reboot is required after a kernel update. Save all important work and note running services before rebooting.

Post-Update Verification

hljs bash
# Verify new kernel version
uname -r

# Check system logs
sudo journalctl -b | head -50

# Check critical services are running
sudo systemctl status nginx
sudo systemctl status mysql

GRUB Configuration

GRUB (Grand Unified Bootloader) is the bootloader used in Linux systems. It manages which kernel to boot when multiple kernel versions are installed.

Viewing GRUB Menu

hljs bash
# List GRUB menu entries
grep -E "^menuentry|^submenu" /boot/grub/grub.cfg

# More readable format
grep -E "menuentry '" /boot/grub/grub.cfg | head -20

# Current default kernel
grub-editenv list

GRUB Configuration File

hljs bash
# Edit main GRUB configuration file
sudo nano /etc/default/grub
hljs bash
# Important GRUB parameters:

# Default kernel selection (0 = first, 1 = second, etc.)
GRUB_DEFAULT=0

# Menu wait time (seconds)
GRUB_TIMEOUT=5

# Always show menu
GRUB_TIMEOUT_STYLE=menu

# Kernel parameters
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
hljs bash
# Update GRUB configuration
sudo update-grub  # Ubuntu/Debian
sudo grub2-mkconfig -o /boot/grub2/grub.cfg  # RHEL/CentOS

Changing the Default Kernel

hljs bash
# List GRUB menu entries with numbers
awk -F\' '/menuentry / {print i++" : "$2}' /boot/grub/grub.cfg

# Change default kernel (0-based index)
sudo grub-set-default 1

# Verify the change
grub-editenv list

# Update GRUB
sudo update-grub

Rolling Back to a Previous Kernel

Method 1: Manual Selection from GRUB Menu

When the server reboots, in the GRUB menu:

  1. Select Advanced options for Ubuntu (or your distribution)
  2. Choose the older kernel version from the list
  3. Press Enter to boot

For remote servers, use the KVM/VNC console feature in the REXE control panel to access the GRUB menu.

Method 2: Setting Default Kernel to Older Version

hljs bash
# List installed kernel versions
dpkg --list | grep linux-image | grep -v meta

# Find the full menu entry name
grep "menuentry '" /boot/grub/grub.cfg | grep "5.15.0-88"

# Set as default (with full menu name)
sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-88-generic"

# Update GRUB
sudo update-grub

# Reboot
sudo reboot

Method 3: Removing the Problematic Kernel

hljs bash
# Remove problematic kernel version (Ubuntu/Debian)
sudo apt remove linux-image-5.15.0-91-generic
sudo apt autoremove

# Update GRUB
sudo update-grub

# For RHEL/CentOS
sudo dnf remove kernel-5.15.0-91

Kernel Parameters

hljs bash
# View current kernel parameters
cat /proc/cmdline

# Change parameter at runtime (temporary)
sudo sysctl -w net.ipv4.ip_forward=1

# Permanent parameter change
sudo nano /etc/sysctl.d/99-custom.conf

# Apply changes
sudo sysctl -p

Common Kernel Parameters

hljs bash
# Network performance
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535

# Memory management
vm.swappiness = 10
vm.dirty_ratio = 15

# File system
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288

Safe Update Strategy for Production Servers

hljs bash
# 1. Take a backup
rsync -avz /var/www/ backup-server:/backup/

# 2. Test in staging environment first

# 3. Schedule a maintenance window
# Update during low-traffic hours

# 4. Update and reboot
sudo apt update && sudo apt upgrade -y
sudo reboot

# 5. Verify services
sudo systemctl status nginx mysql
curl -I http://localhost

Rather than immediately applying kernel updates on production servers, test them in a staging environment first. For critical systems, schedule a maintenance window for updates.

Troubleshooting

System Won't Boot After Kernel Update

hljs bash
# Access GRUB menu via REXE KVM console
# Select older kernel from Advanced options

# After booting with old kernel, remove problematic kernel
sudo apt remove linux-image-[problematic-version]
sudo update-grub

Kernel Module Not Loading

hljs bash
# List loaded modules
lsmod

# Load a module
sudo modprobe module-name

# Check kernel logs
sudo dmesg | tail -50

Conclusion

Kernel updates are critical for Linux server security and performance. Regular kernel updates close security vulnerabilities and let you benefit from new features. Understanding GRUB configuration allows you to quickly roll back to a previous kernel version if issues arise.