How to Fix a Broken Initrd Image in Linux

Today, we'll show you how you can fix your broken or accidentally deleted Initrd Image ie. Linux Kernel Image and GRUB Loader in your Ubuntu installed machine.  It should also work for Ubuntu derivatives as well as other distribution.

Initrd is a scheme for loading a temporary root file system into memory in the boot process of the Linux kernel. It is a cpio archive of the initial file system that gets loaded into memory during the Linux startup process. The Kernel mounts it as root file system and starts the init process from it.

The Initrd image may be broken or corrupt if the kernel you installed was corrupted or due to some modifications made on the system's kernel or the boot process which in results the system crash :(


As we know,  "When there is will there is way". Yes, we can fix or rebuild the initrd image. In my case I will be showing you with my Ubuntu 13.10 Operating System.

Here are easy step wise steps below with screenshots which will help us rebuild our corrupted Kernel Image (Initrd)

1. Boot your machine with a Live Media

You can use your Ubuntu CD/DVD or USB stick to boot live into your machine. If you don't have one, there are a lot of ways to create bootable media. You can download the latest Ubuntu Distribution from their official site ie. and burn the image to a Blank DVD or use unetbootin to create your USB Stick bootable.

2. Open a terminal console and get partitions path

You can easily run a terminal console by pressing Ctrl+ Alt +T in Ubuntu or you can switch to tty1 by pressing Ctrl+ Alt+f1. What we need to do is, we need to mount our the filesystem from our Hard Disk. For that, we need to know the device path. To get the device path you the need to run:

$ sudo fdisk -l

Here, from above result, in my case, sda1 is the one I need to mount.

3. Mount the filesystems

The filesystem we need to mount the hard disk's partitions such as / (root), /boot, /var and should mount bind  /sys, /proc and /dev under a directory /mnt. So, that can be done by steps below:

$ sudo mount /dev/sdaX /mnt

Note: Here in /dev/sdaX, X refers to the partition number 1 in my case,  which we got from step 2.

$ sudo mount --bind /dev /mnt/dev

$ sudo mount --bind /proc /mnt/proc

$ sudo mount --bind /sys /mnt/sys

4. Chroot /mnt and creating a Backup of the initrd image

Now, we need to chroot /mnt so that we can setup chrooted environment for the Hard Disk's partition.

$ sudo chroot /mnt

After Chroot is done, we will be backing up the image file of initrd, you can see the image files under /boot.

# ls /boot/*initrd*

# ls /lib/modules/

You will be able to get the version of the kernel you have currently in the system from the above command.

Consider replacing version with the own you got from above command.

# mv /boot/initrd.img- /boot/old-initrd.img-

Note: the file format of the initrd image may differ from Ubuntu to Fedora Based Systems.

If your initrd image has been deleted, you won't be able to run the above command hence, can't create its backup.

5. Building Initrd Image

Now, the real stuff is here. We are gonna build the initrd kernel image here using the command below:

# mkinitrd /boot/initrd.img-

The above command works for the other distributions like CentOS, Fedora, Hat,etc not for Ubuntu

For Ubuntu Based Distribution:

# update-initramfs -c -k

6. Finalizing Grub Loader and unmounting

We will go for unmounting the mounted path as:

If your system has Fedora, RHEL, CentOS installed, try this:

# grub2-mkconfig -o /boot/grub2/grub.cfg

If your system has Ubuntu and its derivative installed:

# update-grub

# exit

Now, we have successfully left our Chroot Environment.

$ sudo umount /dev

$ sudo umount /proc

$ sudo umount /sys

$ sudo umount /mnt

Hurray, Now, reboot your machine and eject your Bootable Media. We have done it successfully, boot your system back to the normal and enjoy Linux Computing.

9 Comments... add one

  1. I went through this but it does not help. The new initrd.img is exactly the same as the non-working one .
    The issue began when my kernel was updated. I get 'invalid magic number' when I try to boot the associated kernel. It would appear the initrd is responsible but I'm unsure what is wrong. The initrd format is different to that on my other system which is running Lubuntu 14.04. This one has Xubuntu 16.10.

  2. This method is really works! I restored my Ubuntu 18 with broken initrd image. Now it works Ok! My great respects to author!

  3. Really excellent guide!

    You really saved the day. I had accidentally removed a mounted extra drive while having an active snapshot in a cloud vmware environment. Somehow this crashed my initrd file which lead to kernel panic. Now I am up and running again...


Leave a Comment