When adding new hardware to a system, or after changing configuration files that may be used earlier in the boot process, or when changing the options on a kernel module, it may be necessary to rebuild the initial ramdisk (also known as initrd or initramfs) to include the proper kernel modules, files, and configuration directives. In the examples below you will see the usage of $(uname -r), which is a way to pass the current kernel version into a command without actually typing it out.
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