Notes for initrd (initial RAM disk): how to modify the initrd
The Linux initial RAM disk, for example, initrd-2.4.21-15.ELsmp.img, is a temporary root file system that is mounted during system boot to support the two-state boot process. The initrd contains various executables and drivers that permit the real root file system to be mounted, after which the initrd RAM disk is unmounted and its memory freed. In many embedded Linux systems, the initrd is the final root file system.
Recent, I had a chance to work on the Linux kernel a little bit, and in the process, I learned how to manipulate the ramdisk. As you know, lots of works are done in this stage, such as loading modules etc. This is why this note is from.
Before Fedora Core 3, the default initrd image is gzip-compressed ext2 image file.
If you want to examine or modify, use the following commands to set up and
mount a loopback device. Since the initrd image is named with the format like:
initrd-2.4.21-15.ELsmp.img, you have to mv the name to .gz file, and then gunzip
# mv initrd-2.4.21-15.ELsmp.img initrd-2.4.21-15.ELsmp.img.gz
After you have finished making any changes, use the following commands to unmount the loopback device and compress the initrd image:
# umount <mount_point> # gzip initrd-2.4.21-15.ELsmp.img # mv initrd-2.4.21-15.ELsmp.img.gz initrd-2.4.21-15.ELsmp.img
Also you can use the following commands to associate the ram disk to the loopback device:
# losetup /dev/loop0 initrd-2.4.21-15.ELsmp.img # mount /dev/loop0 /mnt/initrd
# umount /mnt/initrd # losetup -d /dev/loop0 #After you finish modification, then losetup -d
Beginning with Fedora Core 3, the default initrd image is a compressed cpio archive file.
Instead of mounting the file as a compressed image using the loop device, you can use a cpio archive. To inspect the contents of a cpio archive, use the following commands:
# fdisk -l /dev/sda
Reference: , or mirror