initramfs unpacking failed: junk in gzip stream

initramfs Load Failure: Fix It When Your Linux Box Won't Boot

Your Linux machine boots into a busybox prompt because the initramfs is corrupted. Here's how to rebuild it and get back to work.

You restart your Linux box after a routine update or maybe a power outage, and instead of seeing a login prompt, you get a shell that looks like BusyBox v1.30.1 (built-in shell) enter 'help' for a list of built-in commands. You're staring at (initramfs). The error message on screen says something like initramfs unpacking failed: junk in gzip stream or Switch root: /sysroot is not valid.

This happened to me last month on a client's Ubuntu 22.04 server that ran a small office's file share. They'd run apt upgrade, the kernel updated, and the initramfs got mangled mid-write. Now the system can't find its root filesystem. Another common trigger: someone manually edited /etc/default/grub or ran update-grub while a package install was still copying initramfs files.

What's Actually Going On

The initramfs (initial RAM filesystem) is a compressed archive that the kernel loads into memory early in boot. It contains kernel modules and scripts needed to mount the real root filesystem. If it's corrupted — even by one bad byte — the kernel can't decompress it. It dumps you into a rescue shell.

The root cause is almost always one of three things:

  1. Partial write — the initramfs image was being written to disk when something died (power failure, kernel crash).
  2. Disk corruption — bad sectors or filesystem errors in the boot partition.
  3. Missing kernel modules — your initramfs doesn't have the driver for your storage controller (NVMe, SATA RAID, etc.).

Don't waste time trying to repair the broken initramfs file. You can't. The real fix is to rebuild it from the running kernel.

How to Rebuild initramfs and Boot Again

Step 1: Boot from a Live USB or Use an Existing Kernel

You need a way to run commands on your system's root filesystem. Grab a live USB of the same distro (Ubuntu 22.04 Live, Fedora Workstation Live, etc.). Boot from it, and open a terminal.

If you have another working kernel on the same system (unlikely if you only have one), you can select it from the GRUB menu at boot. But in my experience, most people have only one kernel installed.

Step 2: Mount Your Root Partition

sudo fdisk -l   # find your root partition, likely /dev/sda1 or /dev/nvme0n1p2
sudo mount /dev/sda1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

If you have a separate boot partition (common on older BIOS systems), mount that too:

sudo mount /dev/sda2 /mnt/boot

Step 3: Chroot into Your System

sudo chroot /mnt

Now you're inside your broken system. Good.

Step 4: Identify Which Kernel You Need

ls /boot/

Look for files like vmlinuz-5.15.0-91-generic and initrd.img-5.15.0-91-generic. The kernel version is in the filename. If you see multiple, use the latest one.

Step 5: Rebuild the initramfs

Different distros use different tools. Here's the command for each:

Ubuntu/Debian (update-initramfs)

update-initramfs -c -k 5.15.0-91-generic

Replace the version with yours. The -c flag creates a new initramfs from scratch.

Fedora/CentOS/RHEL (dracut)

dracut -f /boot/initramfs-5.14.0-284-generic.img 5.14.0-284-generic

The -f forces overwrite of the existing file.

Arch Linux (mkinitcpio)

mkinitcpio -p linux

This rebuilds the default preset. Adjust if you use a custom kernel.

Step 6: Update GRUB

After rebuilding the initramfs, update the bootloader so GRUB picks up the new image:

update-grub   # Ubuntu/Debian
grub2-mkconfig -o /boot/grub2/grub.cfg   # Fedora/CentOS

Step 7: Exit and Reboot

exit
sudo umount -R /mnt
sudo reboot

Pull the live USB when the system starts to reboot.

What to Check If It Still Fails

If you're back at the busybox prompt after following these steps, don't panic. Here are the things I've seen trip people up:

  • Wrong kernel version — double-check you built the initramfs for the exact kernel you're booting. Run uname -r from the live environment on the root partition to see what version it expects.
  • Missing root filesystem driver — if your root is on an NVMe SSD or a hardware RAID, the initramfs needs the nvme or megaraid_sas module. You might need to add it manually. On Ubuntu, run depmod -a then rebuild. On Fedora, dracut --add-drivers nvme.
  • GRUB configuration is wrong — sometimes the root= parameter in GRUB points to the wrong device. Boot into the live USB, mount your root, and check /mnt/boot/grub/grub.cfg. Look for root=UUID=... and make sure that UUID matches what blkid shows for your root partition.
  • Filesystem corruption — the initramfs file itself might be on a corrupted partition. Run fsck /dev/sda1 (or whatever your boot partition is) before rebuilding.

I had a client last month whose boot partition had a bad sector right where the initramfs lived. fsck fixed the file system, but the initramfs was still corrupted. Rebuilding it after fsck solved it.

One last thing: if you're using LUKS encryption or LVM, the initramfs needs to include those tools. dracut --hostonly usually handles it, but update-initramfs on Ubuntu needs the cryptsetup and lvm2 packages installed. If they're missing, you'll get the same failure. Install them from the live environment before rebuilding.

That's it. You're back in business. Next time, wait for the update to finish before hitting the power button.

Related Errors in Linux & Unix
Boot Partition UUID Mismatch: The Real Fix Bonding fails after reboot on RHEL 8 – fix ifcfg config Fix dpkg Interrupted Error: Run dpkg --configure -a disk quota exceeded Disk Quota Exceeded for User on Linux – Quick Fixes

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.