Regenerating the initrd in Ubuntu Linux, including versions
like Ubuntu 20.x or 22.x or 24.x, can be necessary after making changes to the kernel
or its modules. Here’s a step-by-step guide to doing this:
We may need to re-install or fresh create the initrd files during the part of linux troubleshooting.
Steps to Regenerate initrd in Ubuntu
Step
|
Description
|
Command/Action
|
1
|
goto single/emergency/chroot mode if
VM is not booting
|
|
2
|
Identify the current kernel version
|
uname -r
|
3
|
Backup existing initrd (optional)
|
backup initrd file with cp
|
4A
|
Regenerate/update initrd for the current
kernel
|
sudo update-initramfs -u
|
4B
|
Regenerate/update initrd for a specific
kernel
|
sudo update-initramfs -u -k
KERNEL_VERSION
|
4C
|
Create a fresh initrd.img-* file for
your currently booted version of Ubuntu. Prefer to create a totally fresh
version by using the -c option, instead of just updating the existing file by
using the -u option.
|
sudo update-initramfs -c -k $(uname
-r)
|
4D
|
if you can't boot to the current
version of Ubuntu, you may have to modify this command, and by booting to an
older version of Ubuntu, you can do it this way. where the 5.11.0-22-generic
part should be replaced with the version of the desired boot kernel.
|
sudo update-initramfs -c -k
5.11.0-22-generic
|
4F
|
create all of the initrd.img-* files
(not recommended)
|
sudo update-initramfs -c -k all
|
4
|
Update GRUB (if necessary)
|
sudo update-grub
|
5
|
Reboot the system
|
sudo reboot
|
Installation in Ubuntu 24.04
root@ubuntu-1:~# dmidecode | grep -i manufacture
Manufacturer: VMware, Inc.
We have 2 kernels/initrd 6.8.0-48-generic and 6.8.0-49-generic in the current running VM
root@ubuntu-1:/boot# ls -lrt initrd.img*
lrwxrwxrwx 1 root root 27 Nov 10 06:00 initrd.img.old -> initrd.img-6.8.0-48-generic
-rw-r--r-- 1 root root 67075852 Nov 10 06:00 initrd.img-6.8.0-48-generic
lrwxrwxrwx 1 root root 27 Nov 24 15:00 initrd.img -> initrd.img-6.8.0-49-generic
-rw-r--r-- 1 root root 67094780 Dec 15 16:06 initrd.img-6.8.0-49-generic
root@ubuntu-1:/boot# ls -lrt vmlinuz*
-rw------- 1 root root 14952840 Sep 27 12:26 vmlinuz-6.8.0-48-generic
-rw------- 1 root root 14956936 Nov 1 11:41 vmlinuz-6.8.0-49-generic
lrwxrwxrwx 1 root root 24 Nov 10 06:00 vmlinuz.old -> vmlinuz-6.8.0-48-generic
lrwxrwxrwx 1 root root 24 Nov 24 15:00 vmlinuz -> vmlinuz-6.8.0-49-generic
root@ubuntu-1:/boot#
root@ubuntu-1:/boot# uname -r
6.8.0-49-generic
update the current running initrd file
root@ubuntu-1:/boot# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-6.8.0-49-generic
root@ubuntu-1:/boot# ls -lrt initrd.img*
lrwxrwxrwx 1 root root 27 Nov 10 06:00 initrd.img.old -> initrd.img-6.8.0-48-generic
-rw-r--r-- 1 root root 67075852 Nov 10 06:00 initrd.img-6.8.0-48-generic
lrwxrwxrwx 1 root root 27 Nov 24 15:00 initrd.img -> initrd.img-6.8.0-49-generic
-rw-r--r-- 1 root root 67094804 Dec 15 17:35 initrd.img-6.8.0-49-generic
root@ubuntu-1:/boot# date
Sun Dec 15 05:35:50 PM UTC 2024
root@ubuntu-1:/boot#
I have nullified the initrd.img-6.8.0-48-generic file and I am going to create new file with -c option
root@ubuntu-1:/boot# > initrd.img-6.8.0-48-generic
root@ubuntu-1:/boot# du -sh initrd.img-6.8.0-48-generic
0 initrd.img-6.8.0-48-generic
root@ubuntu-1:/boot# ls -lrt initrd.img*
lrwxrwxrwx 1 root root 27 Nov 10 06:00 initrd.img.old -> initrd.img-6.8.0-48-generic
lrwxrwxrwx 1 root root 27 Nov 24 15:00 initrd.img -> initrd.img-6.8.0-49-generic
-rw-r--r-- 1 root root 67094804 Dec 15 17:35 initrd.img-6.8.0-49-generic
-rw-r--r-- 1 root root 0 Dec 15 17:39 initrd.img-6.8.0-48-generic
root@ubuntu-1:/boot#
root@ubuntu-1:/boot# sudo update-initramfs -c -k 6.8.0-48-generic
Ref: https://manpages.ubuntu.com/manpages/focal/en/man8/update-initramfs.8.html
Post a Comment