I accidentally deleted the initrd image on my system. How do I restore it?
3 Answers
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
-
But how do I make it
initrd.img
likeinitrd.img-3.2.0-15-generic-pae
? Mar 16, 2012 at 23:20 -
I'm trying to use initrd from a livecd on my ubuntu install. Deleted it accidently. Mar 16, 2012 at 23:26
-
-
@bodhi.zazen but how to repack this : askubuntu.com/questions/777260/how-to-repack-initrd-img ?– EdiDMay 25, 2016 at 10:45
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.)
-
when there is no existing initrd, the verbose of this command is nothing to be done (13.10)– mchidFeb 14, 2014 at 23:05
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
:
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 likelsblk
,blkid
etc. to find the correct partition.[Optional] If you have a separate boot partition mount that next:
mount -t ext4 /dev/sdY /mnt/boot
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/procNow switch to the
/mnt
folder and run themkinitramfs
command as described above.