Sungju's Slow Life

Personal journal


Rebuild init ramdisk for your own usage.

Basically when you update your kernel whether or not compiled by yourself, related init-ramdisk copied to the boot directory as well.

This init-ramdisk built at the end of the stage in kernel building. This ramdisk includes several modules which is necessary during the boot processing.

Sometimes, a user wants to include several customized modules into the init-ramdisk, so do work at the initial stage. There are several ways to include modules into the init-ramdisk.

One of easiest way is, during the making stage, provides option parameter with the module name as shown following command.

mkinitrd –preload=ext4 /boot/initrd-`uname -r`.img `uname -r`

This is easy method but sometimes we also want to tune some parameters and steps before and after loading modules into the kernel. In that case, you should dig into the ramdisk itself.

Following is the steps you need to watch and edit init-ramdisk.

mkinitrd initrd-`uname -r`.img `uname -r`

mkdir ramdisk_dir
cd ramdisk_dir
gunzip -c ../initrd-`uname -r`.img | cpio -idv
ls -lR

You can see several directories and files. At the root directory of the ramdisk image, you will see the ‘init’ file. This file will be executed during the boot process and load some modules into the kernel.

If you want to add some modules or modify behavior of this ramdisk, you are only necessary to modify this ‘init’ file.

Following diff file shows example of modified ‘init’. In there, I specified to download the ram-based root filesystem and mount it into the ramdisk.

— init.old    2008-09-17 10:44:30.000000000 +0900
+++ init    2008-09-17 10:45:54.000000000 +0900
@@ -83,7 +83,8 @@
lvm vgchange -ay –ignorelockingfailure  VolGroup00
resume /dev/VolGroup00/LogVol01
echo Creating root device.
-mkrootdev -t ext3 -o defaults,ro /dev/VolGroup00/LogVol00
+mount -t tmpfs /dev/shm /sysroot
+wget http://192.168.0.5/tmp/root_ramdisk.tar.gz
echo Mounting root filesystem.
mount /sysroot
echo Setting up other filesystems.

If you finished all your necessary steps into this ramdisk directory, it is time to pack this again as a init-ramdisk image file as shown following block.

find . | cpio –quiet -c -o > ../initrd-new-`uname -r`.img && gzip ../initrd-new-`uname -r`.img

The final step is, of course, move this ramdisk image into the /boot directory and modify ‘grub.conf’ or ‘lilo.conf’ to specify ‘initrd=’ parameter. That is all!!! Now it’s time reboot the machine.



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

A software engineer who loves any technologies that makes life easier. That’s why I love Linux and Mac at the same time.

Newsletter

%d bloggers like this: