Table of Contents
Linux Kernel Panic #
A kernel panic is a critical error where the Linux kernel cannot recover, forcing the system to halt. Below is a breakdown of its causes, a real-world example, and step-by-step solutions.
1. What is a Kernel Panic? #
- Definition: A fatal system crash where the kernel detects an unrecoverable error.
- Symptoms:
- System freezes with an error message (e.g.,
Kernel panic - not syncing: VFS: Unable to mount root fs). - Reboot loops.
- Blank screen with a blinking cursor.
- System freezes with an error message (e.g.,
2. Real-World Example #
Scenario: “Unable to Mount Root Filesystem” #
Error Message: #
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
What Happened? #
- The kernel couldn’t find or mount the root (
/) filesystem. - Possible causes:
- Corrupt
initramfs(initial RAM disk). - Missing or incorrect root device in GRUB.
- Hard drive failure (e.g., SSD/HDD disconnection).
- Corrupt
3. Common Causes of Kernel Panics #
| Cause | Description |
|---|---|
| Hardware Failure | Faulty RAM, dying SSD, or disconnected disk. |
Corrupt initramfs | Missing drivers needed to mount /. |
| Incorrect Kernel Parameters | Wrong root= or rd.lvm.lv in GRUB. |
| Missing Kernel Modules | Required drivers not loaded (e.g., NVMe, LVM). |
| Buggy Kernel Update | New kernel has unresolved bugs. |
| Filesystem Corruption | Improper shutdown or disk errors. |
4. How to Fix a Kernel Panic #
Solution 1: Boot into Rescue Mode #
- Reboot and hold
Shift(BIOS) or spamEsc(UEFI) to open GRUB. - Select “Advanced options” → Choose an older kernel (if available).
- If successful:
- Rebuild
initramfs:bashCopyDownloadsudo update-initramfs -u -k all # Debian/Ubuntu sudo dracut –force # RHEL/Fedora - Reinstall GRUB:bashCopyDownloadsudo grub-install /dev/sdX sudo update-grub
- Rebuild
Solution 2: Check Kernel Parameters #
- In GRUB, press
eto edit boot entry. - Verify
root=points to the correct device (e.g.,root=/dev/mapper/vg-root). - Add
nomodesetif GPU drivers are causing issues.
Solution 3: Fix Filesystem Corruption #
- Boot from a Live USB (e.g., Ubuntu ISO).
- Mount the root partition:bashCopyDownloadsudo mount /dev/sdXn /mnt
- Run
fsck:bashCopyDownloadsudo fsck -y /dev/sdXn
Solution 4: Hardware Diagnostics #
- Test RAM:bashCopyDownloadsudo memtest86+
- Check disk health:bashCopyDownloadsudo smartctl -a /dev/sdX # For HDD/SSD
5. Preventing Kernel Panics #
- Regularly update kernels (but test before production).
- Use
ext4orbtrfs(more resilient thanext3). - Monitor disk health (
smartctl,badblocks). - Avoid forced shutdowns (use
syncbefore power-off).
Final Thoughts #
- If panic persists, boot a Live USB and check logs (
/var/log/kern.log). - For servers, configure kernel crash dumping (
kdump).