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.
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
# 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
# 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
# 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
# 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
# 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
# Edit main GRUB configuration file
sudo nano /etc/default/grub
# 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=""
# Update GRUB configuration
sudo update-grub # Ubuntu/Debian
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL/CentOS
Changing the Default Kernel
# 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:
- Select Advanced options for Ubuntu (or your distribution)
- Choose the older kernel version from the list
- 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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.
Related Articles
How to Connect to Your VDS Server via SSH (Complete Guide)
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
How to Connect to Windows VDS via RDP: Complete Guide
Complete guide to connecting to Windows Server VDS via Remote Desktop (RDP): setup steps, NLA security, Path Panel firewall rule, and troubleshooting tips.
How to Change VDS Server OS: Step-by-Step Reinstall Guide
Step-by-step guide to changing your VDS server OS via REXE panel: backup tips, supported Linux distributions and Windows Server versions explained.