6

I accidentally deleted the initrd image on my system. How do I restore it?

3 Answers 3

6

This is the answer to the original question, how to extract the initrd.lz from the live CD, typically used if you are making a custom live CD.

copy the initrd.lz to a working directory ( ~)

cp /media/cdrom/initrd.lz ~

Make a directory to extract the contents to, I will use initrd, cd into the directory

mkdir ~/initrd
cd ~/initrd

Extract

lzma -dc -S .lz ../initrd.lz | cpio -imvd --no-absolute-filenames

Make any changes you might need, re-package

cd ~/initrd
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz

Your new initrd will be in your home directory and called cusotm.initrd.lz

4
  • But how do I make it initrd.img like initrd.img-3.2.0-15-generic-pae?
    – Binoy Babu
    Mar 16, 2012 at 23:20
  • I'm trying to use initrd from a livecd on my ubuntu install. Deleted it accidently.
    – Binoy Babu
    Mar 16, 2012 at 23:26
  • Well, that is the hard way ;) use mkinitramfs
    – Panther
    Mar 16, 2012 at 23:48
  • @bodhi.zazen but how to repack this : askubuntu.com/questions/777260/how-to-repack-initrd-img ?
    – EdiD
    May 25, 2016 at 10:45
5

The initrd image for each kernel is built at kernel installation time from the modules and applications on the machine. You can simply build a missing initrd using the command below:

update-initramfs -c -k <version>

(Do remember to subsitute in the appropriate version for your kernel.)

1
  • when there is no existing initrd, the verbose of this command is nothing to be done (13.10)
    – mchid
    Feb 14, 2014 at 23:05
4

This is a better way to solve the OP problem posted in the comments.

I'm trying to use initrd from a livecd on my ubuntu install. Deleted it accidently. – Binoy Babu

To make an initramfs, first boot an alternate kernel (older is fine).

Then run

sudo mkinitramfs 3.2.0-15-generic-pae -o /boot/initrd.img-3.2.0-15-generic-pae

I do not have the pae kernel installed, if "3.2.0-15-generic-pae" does not work, list the contents of /lib/modules to get the name:

ls /lib/modules

If you do not have an older kernel, you can boot a live CD and use chroot:

  1. Mount your root partition first: mount -t ext4 /dev/sdX /mnt. Make sure you use the correct partition name and type in this command. Use commands like lsblk, blkid etc. to find the correct partition.

  2. [Optional] If you have a separate boot partition mount that next: mount -t ext4 /dev/sdY /mnt/boot

  3. Next bind mount all the virtual file systems needed by the mkinitramfs command... mount --bind /proc /mnt/proc mount --bind /sys /mnt/sys mount --bind /dev /dev/proc

  4. Now switch to the /mnt folder and run the mkinitramfs command as described above.

1
  • This answer saved my bacon!
    – Autodidact
    Jun 19, 2018 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .