Linux Kernel Panic — Not Syncing Fix
In this tutorial, you'll learn about Linux Kernel Panic. We cover key concepts, practical examples, and best practices.
A Linux kernel panic displays "Kernel panic - not syncing" with a stack trace and freezes the system. This happens when the kernel encounters a fatal error it cannot recover from — typically a bad driver, corrupted initramfs, faulty hardware, or filesystem corruption.
The Problem
On boot or during operation:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Or:
Kernel panic - not syncing: Fatal exception
Kernel Offset: 0x...
Wrong Approach
# WRONG — rebooting without collecting information
sudo reboot
Right Approach
# Capture the panic message for diagnosis
sudo dmesg > kernel-panic-log.txt
# Or take a photo of the screen if the system is frozen
Then boot into a previous kernel from GRUB:
# At GRUB menu, select "Advanced options"
# Choose the previous kernel version
Expected with working kernel:
Normal boot with login prompt.
Step-by-Step Fix
Step 1: Identify the panic cause from the message
Key messages to look for:
Unable to mount root fs → bad root= parameter or missing drivers
Fatal exception → hardware fault or kernel bug
Attempted to kill init → init binary corrupted
Out of memory and no killable processes → OOM panic
Step 2: Boot from an older kernel
At GRUB, select "Advanced options for Ubuntu" and choose a previous kernel.
Step 3: Rebuild initramfs from the working kernel
sudo update-initramfs -u -k all
sudo update-grub
Step 4: Fix root filesystem
# If the panic mentions root fs mounting
sudo fsck -yf /
Step 5: Remove problematic kernel modules
# Boot into recovery mode, then
sudo apt-get purge linux-image-6.x.x-generic
sudo apt-get autoremove
sudo update-grub
Step 6: Check hardware
sudo memtest86+ # Test RAM
sudo smartctl -H /dev/sda # Test disk
Step 7: Add kernel boot parameters
Edit /etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="nomodeset acpi=off panic=10"
Then:
sudo update-grub
Prevention Tips
- Keep at least 2 kernels installed so you can roll back
- Test kernel updates on a staging system before production
- Monitor hardware health with SMART checks and memtest
- Use error-correcting code (ECC) RAM for critical servers
- Always rebuild initramfs after modifying storage drivers
Common Mistakes with kernel panic
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro