A Raspberry Pi stuck in emergency mode after a kernel update?
I hit this one last week while upgrading to the 6.6‑raspi kernel. The Pi rebooted, the splash screen faded, and I was greeted with the dreaded “Emergency mode” prompt. I had no idea what was wrong until I dug into the initramfs. Below is a step‑by‑step guide I used to recover, plus a few lessons that apply to any Debian‑based system.
Why the initramfs matters on a Pi
The initramfs is a compressed cpio archive that the kernel unpacks early during boot. It contains the minimal set of drivers and tools needed to mount the real root filesystem. On Raspberry Pi OS (formerly Raspbian), the initramfs is generated by update-initramfs during package installation. If the archive is corrupted or missing modules, the kernel can’t mount / and drops into emergency mode.
Unlike typical x86 PCs, the Pi’s bootloader (bootcode.bin, start.elf, config.txt) hands the kernel a cmdline.txt that points to the correct initramfs. A mismatch between the kernel version and the initramfs name is a common cause of the emergency mode trap.
Symptoms that point to a broken initramfs
| Symptom | What it means |
|---|---|
Emergency mode prompt |
Kernel couldn’t mount root; initramfs failed |
Failed to mount root fs on /dev/mmcblk0p2 |
Root partition missing or inaccessible |
initramfs-tools errors in /var/log/boot.log |
Initramfs generation failed |
dmesg shows initramfs: initrd image not found |
Initramfs file missing or wrong name |
If you see any of these, the first step is to get a root shell. In emergency mode you’re already there, but the filesystem is read‑only by default.
Step 1: Switch the root filesystem to read‑write
mount -o remount,rw /
Now you can run package commands. If you’re in a container or a minimal environment, you might need to bind‑mount /proc, /sys, and /dev first, but the Pi’s emergency shell already has them.
Step 2: Verify the kernel and initramfs pair
uname -r
ls /boot | grep "$(uname -r | cut -d- -f1-2)" | grep -E 'vmlinuz|initrd'
The first command shows the running kernel. The second lists the corresponding vmlinuz and initrd files. On a healthy system you should see something like:
vmlinuz-6.6.0-raspi
initrd.img-6.6.0-raspi
If the initrd file is missing or the names don’t match the kernel, that’s the culprit.
Step 3: Re‑install the kernel package
The simplest way to rebuild the initramfs is to reinstall the kernel package. This triggers update-initramfs automatically.
apt-get update
apt-get install --reinstall raspberrypi-kernel
During the reinstall you’ll see messages like:
Generating initramfs image /boot/initrd.img-6.6.0-raspi
If the reinstall fails, check /var/log/apt/term.log for errors. A common failure is a missing raspi-config dependency, which can be fixed by:
apt-get install -f
Step 4: Force a fresh initramfs (if reinstall didn’t help)
Sometimes the package install doesn’t rebuild the initramfs because the file already exists. Force a rebuild with:
update-initramfs -u -k $(uname -r)
The -u flag updates the existing initramfs; -k specifies the kernel version. If you want to rebuild for all installed kernels, use -k all.
Step 5: Check the bootloader configuration
The Pi’s bootloader reads /boot/cmdline.txt. It should contain a line similar to:
root=PARTUUID=xxxx-xxxx rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Make sure the root= entry points to the correct partition (mmcblk0p2 on most setups). If you accidentally edited cmdline.txt during troubleshooting, revert the changes.
Step 6: Reboot and verify
reboot
If everything went well, the Pi should boot normally. If it still drops into emergency mode, you’re dealing with a deeper issue—perhaps a corrupted root filesystem or a bad SD card. In that case, run:
fsck -f /dev/mmcblk0p2
from the emergency shell. A full filesystem check can fix inode corruption that prevents the kernel from mounting /.
Common pitfalls and how to avoid them
| Pitfall | Why it happens | Fix |
|---|---|---|
Using apt-get dist-upgrade without apt-get update |
Out‑of‑date package lists cause broken dependencies | Run apt-get update first |
Manually editing /boot/initrd.img-* |
Overwrites the archive with a corrupted file | Never edit the initramfs directly |
| Forgetting to remount root read‑write | Commands fail silently | mount -o remount,rw / |
Using an older kernel in cmdline.txt after a new update |
Mismatch between kernel and initramfs | Update cmdline.txt or use raspi-config to switch kernels |
A quick “what if” checklist
- Kernel version mismatch:
uname -rvs.ls /boot | grep vmlinuz. - Missing initramfs:
ls /boot | grep initrd. - Corrupted root partition:
fsck -f /dev/mmcblk0p2. - Bootloader pointing to wrong partition:
cat /boot/cmdline.txt. - Package database corruption:
dpkg --configure -aandapt-get install -f.
If you hit another hiccup, just try the steps above in order. Usually one of them clears the issue.
#TAGS raspberry-pi emergency-mode kernel-update initramfs
See also
- How I added ionice ‑c3 to my nightly rsync backup and finally stopped my laptop from overheating
- Running a nightly backup script after logout with systemd user units – no nohup needed
- I lost SSH access to my home server after accidentally setting /home/user to 777 – how I restored it with a live USB
- When pulseaudio turns your laptop into a CPU hamster: how to reduce its load with a simple configuration tweak
- Pulling the top 10 HTTP status codes from an Nginx access log with awk