How to modify an initrd

This pages describes how to modify the initrds aka ramdisks of the linkstations/terastations/kuroboxes.

ppc-based boxes
BEWARE: this info is for the original firmimg.bins which were burned to flash. If you flash uboot as a replacement for the stock bootloader you can place the initrd + kernel also to /boot/ instead.

the kernel and the initrd both are inside the firmimg.bin-files which are inside the firmware-update-packages.

so we need to extract both from the firmimg.bin first. some smart japanese guys wrote a tool called firmimgtool.

sourcecode: http://downloads.nas-central.org/ALL_LS_KB_PPC/DevelopmentTools/Flash/Utilities/firmimgtool.c

here you have all the tools you need compiled for ppc: http://downloads.nas-central.org/ALL_LS_KB_PPC/DevelopmentTools/Flash/Utilities/flash_dev_tools_ppc.tar.gz

Usage: ./firmimgtool [-icmkr]  -i : show firmimg_file information -c : cut out from firmimg_file -m : merge into firmimg_file -k : kernel image filename -r : ramdisk image filename -f : copy headers from file -h : show this help message

Now we extract kernel.gz and the initrd.gz: ./firmimgtool -c -k kernel.gz -r initrd.gz firmimg.bin

afterwards you should have a kernel.gz and a initrd.gz in the same folder.

unpack initrd.gz gunzip initrd.gz and loop mount it mkdir INITRD mount -o loop initrd INITRD now you can change everything you want by changing it in the folder INITRD....if you unmount it all changes are saved.

After applying the changes you need to reassemble the firmimg.bin... this works that way: umount INITRD gzip initrd ./firmimgtool -m -k kernel.gz -r initrd.gz firmimg.bin -f firmimg.bin.103 and voila, the new firmimg.bin is ready for flashing.

mipsel-based
the firmimg.bin is encrypted unfortunately. LNI knows how to do this, but he hasn`t published this.

arm9-based boxes
All these boxes feature UBoot as the stock bootloader. The uboot bootloader loads initrd.buffalo from /dev/sda1.

The initrd.buffalo is named initrd.img in the firmware-update-packages. initrd.img is (like the hddrootfs) a password protected zip-file.

just unzip it and supply the right password.

unzip initrd.img Archive: initrd.img [initrd.img] initrd.buffalo password:

try one of these (source of passwords) 1NIf_2yUOlRDpYZUVNqboRpMBoZwT4PzoUvOPUp6l aAhvlM1Yp7_2VSm6BhgkmTOrCN1JyE0C5Q6cB3oBB YvSInIQopeipx66t_DCdfEvfP47qeVPhNhAuSYmA4 IeY8omJwGlGkIbJm2FH_MV4fLsXE8ieu0gNYwE6Ty

for the LS Pro it is YvSInIQopeipx66t_DCdfEvfP47qeVPhNhAuSYmA4 for example.

the initrd.buffalo still is not the real initrd....as it is booted from uboot is has a 64 byte long header. We use dd to get rid of the header, unzip the resulting image.gz and loop-mount the file

dd if=initrd.buffalo of=initrd.gz ibs=64 skip=1 gunzip initrd.gz mkdir INITRD mount -t ext2 -o loop initrd INITRD

there we are...in the folder INITRD you now have loop-mounted the initrd...make your changes as you want.

after making your changes do do this to get the initrd in a bootable condition again: umount INITRD rmdir INITRD mv initrd.buffalo initrd.stock [backup just in case] gzip initrd mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz initrd.buffalo

Links

 * Examine ARM9 Firmware without Updating