Changing your Linux Boot Diskette Image

Occassionally you may need to change the boot image on your Linux boot diskette. For example, you may need to add a driver that is required to get a minimal system running. In my case I required a RAID driver so the disks could be seen. This procedure is based on the RedHat disribution but should work for any distribution.

  1. Use dd to make a copy of your boot diskette

  2. mount the new diskette

  3. Uncompress the boot image to disk, cd mountpoint; gzip -dc initrd.img > /tmp/initrd.ext2

  4. mkdir /mnt/initrd

  5. The boot image is actually an ext2 filesystem, so mount this, mount -o loop /tmp/initrd.ext2 /mnt/initrd

  6. Uncompress the boot image modules file to disk, cd /mnt/initrd; gzip -dc modules/modules.cgz > /tmp/modules.cpio

  7. mkdir /tmp/Modules; cd /tmp/Modules

  8. The modules file is actually a cpio image so you need to extract this to add more modules, cpio -idumv < /tmp/modules.cpio

  9. Copy your extract modules into /tmp/Modules (NOTE: At this point you may want to also remove any unnecessary drivers as space is often an issue with the boot images).

  10. Recreate the CPIO image, cd /tmp/Modules; find . | cpio -ov > /tmp/modules

  11. Compress the image, cd /tmp; gzip -S .cgz modules

  12. Copy the image back, cp modules.cgz /mnt/initrd/modules

  13. umount /mnt/initrd

  14. gzip -c /tmp/initrd.ext2 > /tmp/initrd.img

  15. cp /tmp/initrd.img /mnt/floppy (assuming /mnt/floppy was were you originally mounted your floppy)

At this point you may well find that your new initrd.img won’t fit on the diskette. If you have this problem, you’ll need to create a new smaller image file as follows:

  1. Create an empty file of a defined size (the count controls the size so adjust this to the size you need), dd if=/dev/zero of=filename bs=1024 count=1400

  2. Format the empty file as a filesystem, mke2fs filename

  3. Mount it, mount -t ext2 -o loop filename /mnt/mountpoint

  4. Remount your amended image, mount -o loop /tmp/initrd.ext2 /mnt/initrd

  5. Copy the amended image to the newly created image file, cd /mnt/initrd; find . | cpio -dumpv /mnt/mountpoint

  6. umount /mnt/mountpoint

  7. gzip -c filename > initrd.img

  8. cp initrd.img /mnt/floppy