Editing initrd (Initial ramdisk)

Editing an initrd is often simpler than creating one.

I needed to create a new node for the system md device because while working on the system RAID1 md after a power failure under linux rescue, the minor device number changed. init was throwing the error “mount: could not find filesystem /dev/root
The following steps are what I did to fix it…

Here is how to unpack it:

  1. cd /boot
  2. cp initrd-<release>.img initrd-<release>.img.bak
  3. mkdir initrd
  4. gzip -d -c -S ""  ../initrd-2.6.18-308.8.1.el5.img >
  5. # file initrd-2.6.18-308.8.1.el5
    initrd-2.6.18-308.8.1.el5: ASCII cpio archive (SVR4 with no CRC)
  6. cpio -i < initrd-2.6.18-308.8.1.el5
  7. rm -f initrd-2.6.18-308.8.1.el5
  8. # ls
    bin dev etc init lib proc sbin sys sysroot

Here is what I did to make the new device node:

  1. cd dev
  2. rm -f md3
  3. mknod -m 640 md127 b 9 127
  4. cd ..

The old node was md3. The major number for an md device is 9 (for /dev/sd<a-z> it is 8). While I was working on the md with mdadm, the preferred minor changed to 127.

I then edited the init script to change the occurrences of md3 to md127. (don’t forget this step!)

This is what you do to repack the dirs:

  1. cd initrd
  2. find | cpio -o -H newc -o | gzip > ../initrd<release>.img
  3. cd ..
  4. rm -rf initrd

That’s it. I did all of this after booting the server from a CentOS flash drive. After booting into a shell, all I had to do was type mdadm -A --scan to assemble and run the md devices. Although I couldn’t boot to the system md after the power failure, I was obviously able to assemble it here and then I ‘failed’ and ‘removed’ the sd device that was damaged.

After these steps, I was able to bring the server up with the degraded md device.

Leave a Reply

Your email address will not be published. Required fields are marked *