How to modify a ramdisk aka initrd

From NAS-Central Main Wiki
Jump to: navigation, search

Nearly all NAS devices use a ramdisk aka initrd while booting. Most of the older boxes which were sold with the hdds used them for some sort of emergency mode which the user only got to when something went severely wrong and the box did not boot anymore properly. The newer BYOD-NAS-Devices actually totally depend on them even for normal booting. This article should explain how to mount the ramdisk on a linux workstation so you can modify it.

Get access to the ramdisk

For example the older buffalo boxes had a custom file called firmimg.bin which contained a header, the gzipped kernel and the gzipped initrd. If you really have bad luck then it is somehow encrypted, like a password protected zip or with a custom algorithm. In case something like that is the case you know that you have to deal with that first.

Mount the ramdisk

Ok, i assume you have a gzipped ramdisk now as this is the common form. A ramdisk normally is stored in flash of the NAS-device and while bootup of the box the bootloader unzips the kernel and the ramdisk and loads both into ram. They are gzipped most of the time as flash memory costs money and thats the way to reduce the needed space.

Ok, so this are the steps to mount rc.tgz:

gzip -d rd.gz
mkdir INITRD-MOUNT
mount -t ext2 -o loop rd INITRD-MOUNT

(remember that you need root-permissions. That means that you might have to use "sudo") ext2 is the most common filesystem in ramdisks, so there is a good chance that your ramdisk is also using it.

Everything you change in the ramdisk as long as it is loop mounted will be automatically changed in the ramdisk afterwards. This means you do not have to save it or anything, just apply the changes and then unmount it again. So apply your changes now.

Then unmount and gzip the ramdisk again:

umount INITRD-MOUNT
gzip -9 rd

(you again might need "sudo").

Links