Rebuild the initial ramdisk image in Red Hat Enterprise Linux

How to rebuild the initial ramdisk image in Red Hat Enterprise Linux

 SOLUTION VERIFIED - Updated  - 

Environment

  • Red Hat Enterprise Linux (RHEL) 3
  • Red Hat Enterprise Linux (RHEL) 4
  • Red Hat Enterprise Linux (RHEL) 5
  • Red Hat Enterprise Linux (RHEL) 6
  • Red Hat Enterprise Linux (RHEL) 7
  • initrd / initramfs image

Issue

  • How to rebuild the initial ramdisk image in Red Hat Enterprise Linux
  • How to remake or recreate the initrd or initramfs
  • The /etc/lvm/lvm.conf and root file system resides on a logical volume. How to ensure the changes are applied upon rebooting?
  • The /etc/multipath.conf and my root file system resides on a multipath device. How to ensure the changes are applied upon rebooting?
  • The module options in /etc/modprobe.conf or /etc/modprobe.d/ have been modified. How to ensure the changes are applied upon rebooting?

Resolution

When adding new hardware to a system, or after changing configuration files that may be used very early 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.
If you are adding a new module in the initrd, first follow the instructions in How can I ensure certain modules are included in the initrd or initramfs in RHEL?, or if it is a configuration change then make that change now.
Once the necessary modifications have been made, it is time to rebuild the initrd. This process differs based on the version of RHEL. In these examples 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. If you are working with a version of the kernel other than what is currently running, then replace $(uname -r) with the actual kernel version, such as 2.6.18-274.el5.
  1. Rebuilding the initrd (RHEL 3, 4, 5)
  2. Rebuilding the initramfs (RHEL 6, 7)
  3. Working with backups (All RHEL versions)

Rebuilding the initrd (RHEL 3, 4, 5)

It is recommended you make a backup copy of the initrd in case the new version has an unexpected problem:
$ cp /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.$(date +%m-%d-%H%M%S).bak
Now build the initrd:
$ mkinitrd -f -v /boot/initrd-$(uname -r).img $(uname -r)
  • The -v verbose flag causes mkinitrd to display the names of all the modules it is including in the initial ramdisk.
  • The -f option will force an overwrite of any existing initial ramdisk image at the path you have specified
If you are in a kernel version different to the initrd you are building (including if you are in Rescue Mode) you must specify the full kernel version, without architecture:
$ mkinitrd -f -v /boot/initrd-2.6.18-348.2.1.el5.img 2.6.18-348.2.1.el5

Rebuilding the initramfs (RHEL 6, 7)

It is recommended you make a backup copy of the initramfs in case the new version has an unexpected problem:
$ cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.$(date +%m-%d-%H%M%S).bak
Now rebuild the initramfs for the current kernel version:
$ dracut -f -v
If you are in a kernel version different to the initrd you are building (including if you are in Rescue Mode) you must specify the full kernel version, including architecture:
$ dracut -f /boot/initramfs-2.6.32-220.7.1.el6.x86_64.img 2.6.32-220.7.1.el6.x86_64

Working with backups (All RHEL Versions)

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 desired, 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 5 (2.6.18-274.el5)
     root (hd0,0)
     kernel /vmlinuz-2.6.18-274.el5 ro root=LABEL=/ 
     initrd /initrd-2.6.18-274.el5.img
title Red Hat Enterprise Linux 5 w/ old initrd (2.6.18-274.el5)
     root (hd0,0)
     kernel /vmlinuz-2.6.18-274.el5 ro root=LABEL=/ 
     initrd /initrd-2.6.18-274.el5.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 /initrd-2.6.18-274.el5.img.bak)
  • Press Enter to temporarily save the changes you have made
  • Press b for boot
Note: This procedure does not actually make the change persistent. The next boot will continue to use the original grub.conf configuration unless it is updated.

Comments

Popular posts from this blog

[SOLVED]* Please wait for the system Event Notification service

Python reference Interview questions