Regenerating the initramfs in RHEL Linux, including versions like RHEL 6.x/7.x/8/x/9/x and CentOS 7.x and CentOS 8.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 the initramfs images during the part of linux troubleshooting.
Steps to Regenerate initramfs in RHEL/CentOS Linux
Step
|
Description
|
Command/Action CentOS /
RHEL
|
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 initramfs file with cp
command
|
4
|
Regenerate the modules dependency
file
|
depmod -v or depmod -a $(uname -r)
|
5a
|
Regenerate initrd for the current
kernel
|
sudo dracut -f
|
5b
|
Regenerate initrd for a specific
kernel
|
dracut -f /boot/initramfs-$(uname -r).img $(uname -r)
|
5c
|
Regenerate initrd for a specific
kernel
|
dracut -vvv -f
/boot/initramfs-4.18.0-348.7.1.el8_5.x86_64.img 4.18.0-348.7.1.el8_5.x86_64
|
6
|
Regenerate initrd for the current
kernel
|
sudo grub2-mkconfig -o
/boot/grub2/grub.cfg
|
7
|
Regenerate initrd for a specific
kernel
|
sudo reboot
|
If you want add drives to the kernel while generating the initramfs , we can use below command
dracut -v --force --force-drivers hv_storvsc,hv_vmbus,lvm2 /boot/initrd-4.12.14-122.147-default 4.12.14-122.147-default
RHEL 8.x Initramfs re-generation
[root@RHEL8 boot]# cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.10 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.10"
[root@RHEL8 boot]# uname -a
Linux RHEL8 4.18.0-553.32.1.el8_10.x86_64 #1 SMP Mon Dec 2 06:32:20 EST 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@RHEL8 boot]# uptime
12:20:43 up 5:21, 2 users, load average: 0.07, 0.29, 0.17
[root@RHEL8 boot]#
I have nullified the initramfs-4.18.0-553.27.1.el8_10.x86_64.img and created it again.
[root@RHEL8 boot]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Adding boot menu entry for EFI firmware configuration
done
CentOS 7.x Initramfs re-generation with dracut
The VM is booted with 3.10.0-1160.80.1.el7.x86_64 and we have nullified the same initramfs file and created it again.
[root@cent7-1 boot]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
[root@cent7-1 boot]# dmidecode | grep -i manufacturer
Manufacturer: VMware, Inc.
Manufacturer: Intel Corporation
Manufacturer: No Enclosure
[root@cent7-1 boot]# ls -lrt initramfs-*
-rw-------. 1 root root 79684761 Nov 23 2020 initramfs-0-rescue-a30061ba6f384b7d92e5d8170209eda3.img
-rw-------. 1 root root 29303629 Nov 23 2020 initramfs-3.10.0-1160.el7.x86_64.img
-rw------- 1 root root 29241384 Nov 19 08:29 initramfs-3.10.0-1160.119.1.el7.x86_64.img
-rw------- 1 root root 29602509 Dec 14 13:28 initramfs-3.10.0-1160.80.1.el7.x86_64.img
[root@cent7-1 boot]# ls -lrt vmlinuz-*
-rwxr-xr-x. 1 root root 6769256 Oct 19 2020 vmlinuz-3.10.0-1160.el7.x86_64
-rwxr-xr-x. 1 root root 6769256 Nov 23 2020 vmlinuz-0-rescue-a30061ba6f384b7d92e5d8170209eda3
-rwxr-xr-x 1 root root 7047784 Nov 8 2022 vmlinuz-3.10.0-1160.80.1.el7.x86_64
-rwxr-xr-x 1 root root 7051880 Jun 4 2024 vmlinuz-3.10.0-1160.119.1.el7.x86_64
-rwxr-xr-x 1 root root 7699048 Jun 4 2024 vmlinuz-3.10.0-1160.119.1.el7.x86_64.debug
[root@cent7-1 boot]# uname -a
Linux cent7-1 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@cent7-1 boot]# uptime
07:25:56 up 5:25, 1 user, load average: 0.00, 0.01, 0.05
[root@cent7-1 boot]# > initramfs-3.10.0-1160.80.1.el7.x86_64.img
[root@cent7-1 boot]# du -sh initramfs-*
76M initramfs-0-rescue-a30061ba6f384b7d92e5d8170209eda3.img
28M initramfs-3.10.0-1160.119.1.el7.x86_64.img
0 initramfs-3.10.0-1160.80.1.el7.x86_64.img
28M initramfs-3.10.0-1160.el7.x86_64.img
[root@cent7-1 boot]# dracut -f -v
Executing: /sbin/dracut -f -v
......................
..................................
*** Including module: bash ***
*** Constructing GenuineIntel.bin ****
*** Constructing GenuineIntel.bin ****
*** Store current command line parameters ***
*** Creating image file ***
*** Creating microcode section ***
*** Created microcode section ***
*** Creating image file done ***
*** Creating initramfs image file '/boot/initramfs-3.10.0-1160.80.1.el7.x86_64.img' done ***
[root@cent7-1 boot]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.119.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.119.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.80.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.80.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.119.1.el7.x86_64.debug
Found initrd image: /boot/initramfs-3.10.0-1160.119.1.el7.x86_64.debug.img
Found linux image: /boot/vmlinuz-0-rescue-a30061ba6f384b7d92e5d8170209eda3
Found initrd image: /boot/initramfs-0-rescue-a30061ba6f384b7d92e5d8170209eda3.img
done
[root@cent7-1 boot]#
Now VM is rebooted and booted with same kernel
Post a Comment