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:
cd /boot
cp initrd-<release>.img initrd-<release>.img.bak
mkdir initrd
gzip -d -c -S "" ../initrd-2.6.18-308.8.1.el5.img >
initrd-2.6.18-308.8.1.el5# file initrd-2.6.18-308.8.1.el5
initrd-2.6.18-308.8.1.el5: ASCII cpio archive (SVR4 with no CRC)cpio -i < initrd-2.6.18-308.8.1.el5
rm -f initrd-2.6.18-308.8.1.el5
- #
ls
bin dev etc init lib proc sbin sys sysroot
Here is what I did to make the new device node:
cd dev
rm -f md3
mknod -m 640 md127 b 9 127
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:
cd initrd
find | cpio -o -H newc -o | gzip > ../initrd<release>.img
cd ..
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.