Monday, January 28, 2019

CentOS / RHEL 6 : How to rebuild initrd Initial Ramdisk Image

Procedure

1. It is recommended you make a backup copy of the initrd in case the new version has an unexpected problem:
# cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
# ll /boot/initramfs-$(uname -r).img*
-rw-r--r--. 1 root root 16209434 Oct 11 14:43 /boot/initramfs-2.6.32-358.el6.x86_64.img
-rw-r--r--. 1 root root 16209434 Apr  9 07:38 /boot/initramfs-2.6.32-358.el6.x86_64.img.bak
2. Now rebuild the initramfs for the current kernel version:
# dracut -f
3. If you are in a kernel version different to the initrd you are building (also if you are in Rescue Mode) you must specify the full kernel version, including architecture:
# dracut -f /boot/initramfs-2.6.39-400.17.1.el6.x86_64.img 2.6.39-400.17.1.el6uek.x86_64
The -f option will force an overwrite of any existing initial ramdisk image at the path you have specified

Working with Backups

As mentioned previously, it is recommended that you take a backup of the previous initrd in case something goes wrong with the new one. If required, it is possible to create a separate entry in /boot/grub/grub.conf for the backup initial ramdisk image, to conveniently choose the old version at boot time without needing to restore the backup. This example configuration allows selection of either the new or old initial ramdisk image from the grub menu :
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=LABEL=/ 
initrd /initramfs-2.6.32-358.el6.x86_64.img
title Red Hat Enterprise Linux w/ old initrd (2.6.32-358.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=LABEL=/ 
initrd /initramfs-2.6.32-358.el6.x86_64.img.bak
Alternatively, you can enter edit-mode in grub if you need to choose the old initrd and did not make a separate entry in grub.conf before rebooting. To do so:
– If grub is secured with a password, press p and enter the password.
– Use the arrow keys to highlight the entry for the kernel you wish to boot.
– Press e for edit.
– Highlight the initrd line and press e again.
– Change the path for the initrd to the backup copy you made (such as /initramfs-2.6.32-358.el6.x86_64.img.bak)
– Press Enter to temporarily save the changes you have made
– Press b for boot

No comments:

Post a Comment