- Set up a workplace
mkdir /tmp/unpack
cd /tmp/unpack
|
- Grab something to work with
cp /mnt/cdrom/images/boot.img .
|
- Dig into the disk (any of boot.img, bootnet.img, drivers.ing, etc...)
mkdir disk.dir
mount boot.img disk.dir -o loop
|
- Grab a copy of the initrd and uncompress it
cp disk.dir/initrd.img initrd.img.gz
gunzip initrd.img.gz
|
- Dig into the initrd
mkdir initrd.dir
mount initrd.img initrd.dir -o loop
|
- What is important in the initrd
Initrd calls /linuxrc which then loads drivers from the modules.cgz file which resides in the /modules directory (in the same initrd file). If all you are doing is adding in modules for different hardware into one of the default Red Hat boot disks, then you only need to modify the files that exist in the /modules directory. Files of interest in the /modules directory are module-info, modules.dep, pcitable, and modules.cgz.
- Dig into the modules.cgz file
cd /tmp/unpack
mkdir modules
cd modules
zcat ../initrd.dir/modules/modules.cgz | cpio -idvm
cd ..
|
- Modifying modules.cgz
- Add and subtract modules to and from modules.cgz as necessary.
- You may grab modules from one of the other boot disks available (boot.img, bootnet.img, drivers.img, drvblock.img, drvnet.img, etc).
- Remember to keep track of how much space you are using inside modules.cgz, or your initrd may not fit back on the boot disk.
- If the module you need is not present on one of these disk images then you will need to build the module. Building the module is easy
- Use my kernel page (kernel.html) as a guide. Here is a summary:
cd /usr/src/linux-2.4.7-10
make mrproper
make clean
cp configs/kernel-source-2.4.7-i386-BOOT.config .config
|
Use the kernel-source-2.4.x-i386-BOOT.config as a starting guideline.
Change the extraversion line to read -10BOOT for RH72 (RH72 uses a 2.4.7-10 kernel)
Use "make xconfig" to make sure that your driver is turned on as a module, then save and exit.
make dep modules modules_install
|
You should end up with the 2.4.7-10BOOT modules residing in /lib/modules/2.4.7-10BOOT. If you get any errors don't worry, just check if your module has been created yet or not
If you have a ".o" file for your driver, then you're done. Take that .o file with you back to your /tmp/unpack/modules/2.4.7-10BOOT directory.
- Modifying module-info
- Follow the same format that exists in module-info
- First see if there is an existing entry you can copy over from where you are getting the driver (such as from a different boot disk or from one of the drivers disks)
- Second, see if you have an entry in your systems /boot/module-info that you can use
- Otherwise create your own multi-line entry, such as:
sym53c8xx
scsi
"Symbios 53C896"
- Modifying modules.dep
- Follow the existing format in the file.
- First, try to get a copy from where you got the driver (such as a boot disk or drivers disk).
- Second, if you made your own driver then check in your systems /lib/modules/2.4.7-10/modules.dep. Please note that you should convert the format if you use information from your systems modules.dep - specifically your system will have a full path listed, please strip off this full path and only leave the drivername - further please remove all ".o" extensions.
Sample:
usb-storage: usbcore scsi_mod
usb-ohci: usbcore
usb-uhci: usbcore
vfat: fat
- Modifying pcitable
See if you have an existing entry for pcitable from wherever you copied the driver from. If you don't have an entry, don't worry, things may work without modifying this file.
- Repacking modules.cgz
cd /tmp/unpack/modules
find 2.4.7-2BOOT/ | grep -v "BOOT/$" | cpio -o -H crc >modules.cpio
gzip -9 -n modules.cpio
mv modules.cpio.gz modules.cgz
|
- Repacking initrd.img
Before moving modules.cgz back into the initrd, make sure that it is the same size or smaller than the original one.
cd /tmp/unpack
ls -ltr initrd.dir/modules/modules.cgz modules/modules.cgz
|
If the new modules.cgz is bigger than the original modules.cgz, then you will most likely get the modules.cgz back into the initrd.img; however, the initrd.img, will then probably be too big for the boot floppy. Consider throwing drivers you don't need out of modules.cgz such as SCSI or Network Cards you don't have or don't plan on using. Even though there is plenty of space available in the initrd.img, there is only so much space available in the boot disk - and gzip is expecting much of the initrd.img file to be blank.
Do the same kind of check on any of the other files you modified, such as modules.cgz, modules.dep, module-info, and pcitable, etc.
cd /tmp/unpack
for X in modules.dep, modules.cgz, module-info, pcitable; do \
ls -ltr modules/$X initrd.dir/modules/$X; done
|
Once you have compared the sizes of the various files then place them back into the initrd.dir.
cd /tmp/unpack
mv modules/modules.cgz initrd.dir/modules/modules.cgz
mv modules/modules.dep initrd.dir/modules/modules.dep
mv modules/module-info initrd.dir/modules/module-info
mv modules/pcitable initrd.dir/modules/pcitable
|
We need to blank out the unused portions of initrd - this is needed so gzip doesn't try to compress data that we have already deleted out.
cd /tmp/unpack
dd if=/dez/zero of=initrd.dir/zero
rm initrd.dir/zero
|
Unmount initrd.dir
(This action finishes writing any cached information out to initrd.img, then it disconnects initrd.img from the initrd.dir directory. This behavior is just the same as working with a floppy under Linux - mount the floppy, work with it, unmount it - unmounting the floppy finishes writing any leftover information to the floppy, then returns to the prompt).
cd /tmp/unpack
umount initrd.dir
|
Now gzip up initrd.img
Note: The "file" utility can tell you if a file is compressed or not.
cd /tmp/unpack
gzip -9 -n initrd.img
mv initrd.img.gz initrd.img
|
- Repacking the Disk
Before moving the initrd.img back into the disk image, make sure that it is the same size or smaller than the original one.
cd /tmp/unpack
ls -ltr initrd.img disk.dir/initrd.img
|
If you need more space in the disk image, you are able to remove all the disk.dir/*.msg files, but that is just about all the extra space you can get.
Place the initrd.img back into the disk image
cd /tmp/unpack
mv initrd.img disk.dir/initrd.img
|
Unmount the disk image - see note above on unmounting initrd.img for an understanding of why it is necessary to unmount the disk image.
cd /tmp/unpack
umount disk.dir
|
- Troubleshooting steps if initrd.img no longer fits on the boot disk
- Try unpacking the initrd.gz, moving out your modules/* files, blanking the empty space with "dd if=/dev/zero of=initrd.dir/zero; rm initrd.dir/zero", then move your modules back into your initrd.dir, then repack initrd. Try putting it back onto your boot disk.
- Thin out unneeded drivers from modules.cgz.
- Make sure you are using maximum compression and leaving out unnecessary details:
find 2.4.7-10BOOT/ | grep -v "BOOT/$" | cpio -o -H crc >modules.cpio
gzip -9 -n modules.cpio
gzip -9 -n initrd.img
|
- Notes on initrd
Important parts of an initrd are as follows:
When initrd boots, it immediately runs /linuxrc
SCSI modules are located in the /lib directory
bin
insmod
sash
dev
console (5,1)
null (1,3)
ram (1,1)
systty (4,0)
tty1 (4,1)
tty2 (4,2)
tty3 (4,3)
tty4 (4,4)
etc
lib
ncr53c8xx.o
linuxrc
loopfs
Contents of linuxrc
#!/bin/sash
aliasall
echo "Loading ncr53c8xx module"
insmod /lib/ncr53c8xx.o
pcitable contains information similar to "lspci" and "lspci -n"