The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available. It is necessary to rebuild the Initrd images in following scenarios to include the proper kernel modules, files, and configuration directives
If adding new hardware to a system that may be used very early in the boot process.
If changing configuration files that may be used very early in the boot process
If changing the options on a kernel module.
The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available. The initrd is bound to the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system.
initrd provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root (from initrd) is then moved to a directory and can be subsequently unmounted.
Rebuilding the initrd (RHEL 3, 4, 5)
mkinitrd utility can be used to recreate the initrd image . mkinitrd creates an initial image used by the kernel for preloading the block device modules (such as IDE, SCSI or RAID) which are needed to access the root filesystem. mkinitrd automatically loads filesystem modules (such as ext3 and jbd), IDE modules, all scsi_hostadapter entries in /etc/modprobe.conf, and raid modules if the systems root partition is on raid, which makes it simple to build and use kernels using modular device drivers.
Steps:
1.It is recommended you make a backup copy of the initrd in case the new version has an unexpected problem:
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
dracut utility can be used in RHEL 6 to rebuild the initrams image ,It creates an initial image used by the kernel for preloading the block device modules (such as IDE, SCSI or RAID) which are needed to access the root filesystem.
It is recommended you make a backup copy of the initrd in case the new version has an unexpected problem:
Now rebuild the initramfs for the current kernel version:
# dracut -f
Note:
If you are in a kernel version different to the initrd we are building (including if you are in Rescue Mode) We must specify the full kernel version, including architecture:
If any error occurred with the new inird/initramfs image, we can boot from the backup initrd image by using below steps.
We can create a separate entry in 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
If first step is not done , we can enter edit-mode in grub and choose the old initrd by below steps .
a.If grub is secured with a password, pressp and enter the password
b.Use the arrow keys to highlight the entry for the kernel you wish to boot
c.Presse for edit
d.Highlight the initrd line and press e again
e.Change the path for the initrd to the backup copy you made (such as/initrd-2.6.18-274.el5.img.bak)
f.Press Enter to temporarily save the changes you have made
g.Pressb for boot
Note: This procedure did not actually make any persistent change. The next boot will continue to use the original grub.conf configuration unless it is updated.
How initrd works
initrd provides the capability to load a RAM disk by the bootloader. This RAM disk can then be mounted as the root fileystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. Theprevious root (from initrd) is then moved to a directory andcan be subsequently unmounted. initrd is mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and where additional modules are loaded from initrd.
When using initrd, the system typically boots as follows:
1.The boot loader loads the kernel and the initial RAM disk
2.The kernel converts initrd into a "normal" RAM disk and frees the memory used by initrd
3. initrd is mounted read-write as root
4. /linuxrc is executed (this can be any valid executable, including shell scripts; it is run with uid 0 and can do
basically everything init can do)
5. linuxrc mounts the "real" root file system
6. linuxrc places the root file system at the root directory using the pivot_root system call
7. The usual boot sequence (e.g. invocation of /sbin/init) is performed on the root file system