#!/bin/bash # 1. Download and install the new kernel-BOOT package. # 2. First, define some environment variables which will help us later export NEW_BOOT_KERNEL_VERSION="2.4.20-28.7BOOT" export BOOTROOT="/tmp/bootdisk" export CDROOT="/home/me/cddir-1.3.1/final" # where 'final' contains the nuggets of the cdrom unmountall() { umount $BOOTROOT/boot_image umount $BOOTROOT/initrd_image umount $BOOTROOT/stage2_image } fullcleanup() { unmountall rm -rf $BOOTROOT } checksum() { sum1=`md5sum $1 | awk '{print $1}'` sum2=`md5sum $2 | awk '{print $1}'` if [ $sum1 != $sum2 ]; then unmountall echo " " echo "Bailing because $1 and $2 are different" exit 1 fi } # 3. Make some directories in preparation for what we'll do later fullcleanup /bin/mkdir -p $BOOTROOT/boot_image $BOOTROOT/initrd_image $BOOTROOT/stage2_image # 4. Obtain copies of the boot.img and stage2.img files and copy them cd $BOOTROOT #/bin/cp $CDROOT/images/boot.img $BOOTROOT/ /bin/cp $CDROOT/../../stock-items/boot.img $BOOTROOT/ # 5. Now mount the images via loopback devices so we can work with them. /bin/mount -o loop $BOOTROOT/boot.img $BOOTROOT/boot_image /bin/gunzip < $BOOTROOT/boot_image/initrd.img > $BOOTROOT/initrd.img if [ $? -ne 0 ]; then echo "BAD INITRD image, can't decompress it" echo "cannot continue, exiting..." exit 1 fi /bin/mount -o loop $BOOTROOT/initrd.img $BOOTROOT/initrd_image # 6. Create a working directory for the initrd. # /bin/mkdir $BOOTROOT/initrd_tmp/ # /bin/cp -a $BOOTROOT/initrd_image/* $BOOTROOT/initrd_tmp/ /bin/cp -a $BOOTROOT/initrd_image $BOOTROOT/initrd_tmp /bin/rm -f $BOOTROOT/initrd_tmp/dev/cciss/c0d[56789]* /bin/rm -f $BOOTROOT/initrd_tmp/dev/cciss/c0d1[12345]* /bin/mkdir $BOOTROOT/initrd_tmp/$NEW_BOOT_KERNEL_VERSION # 7. Update the kernel modules found in the initrd. # The following code fragment works to do this, although it will seem to spew errors # about missing modules. Between the 2.4.9 kernel and the 2.4.18 kernel, some things # were compiled directly into the kernel which used to be modules -- a lot of the # USB stuff, the vfat and fat filesystems, and some other things. Plus, some things # have been deprecated. # these next two lines would unpack the modules in the cgz # we're starting with, but I don't care. I leave the line # here though as a reference for what COULD be done cd $BOOTROOT/initrd_tmp /bin/zcat modules/modules.cgz | cpio -ivd cd $BOOTROOT/initrd_tmp OldBootVersion=`zcat modules/modules.cgz | cpio -t |head -1 | awk -F / '{print $1}'` ModuleList=`ls $OldBootVersion` cd /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel for ModuleName in $ModuleList do NewModuleName=`find . -name $ModuleName` if [ "$NewModuleName" != "" ]; then echo " updating: $ModuleName" /bin/cp $NewModuleName $BOOTROOT/initrd_tmp/$NEW_BOOT_KERNEL_VERSION/$ModuleName else echo " REMOVING: $ModuleName" fi done # 8. Now use modules that we're interested in. cd $BOOTROOT/initrd_tmp/$NEW_BOOT_KERNEL_VERSION #/bin/rm *.o /bin/rm usb-storage.o #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/cciss.o . ##/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/cpqarray.o . ##/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/DAC960.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aic7xxx/aic7xxx.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aic7xxx/aic79xx.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aacraid/aacraid.o . ##/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/megaraid2.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/sr_mod.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/scsi_mod.o . ##/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/sym53c8xx.o . # do you compile these in? #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/ataraid.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/hptraid.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/medley.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/pdcraid.o . #/bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/silraid.o . # 9. Now to rebuild modules.cgz. cd $BOOTROOT/initrd_tmp/ find $NEW_BOOT_KERNEL_VERSION | cpio -ov -H crc | gzip -c9 >\ $BOOTROOT/initrd_tmp/modules/modules.cgz cd $BOOTROOT rm -rf $BOOTROOT/initrd_tmp/*BOOT # 10. Update some files in $BOOTROOT/initrd_tmp/modules: module-info, # pcitable and modules.dep For module-info, add these lines. Use tabs, # not spaces for the indent ## cciss ## block ## "Compaq Smart Array Controller" # For modules.dep, remove these lines: ## keybdev: input ## hid: usbcore input ## usb-ochi: usbcore ## usb-uchi: usbcore ## vfat: fat # For pcitable, we're going to steal from kudzu's /usr/share/kudzu/pcitable. I used kudzu-0.99.42.2.72-1 for this. ## grep e1000 /usr/share/kudzu/pcitable >> $BOOTROOT/initrd_tmp/modules/pcitable ## grep tg3 /usr/share/kudzu/pcitable >> $BOOTROOT/initrd_tmp/modules/pcitable # Now sort the file ## mv pcitable pcitable.orig ## sort pcitable.orig > pcitable ## rm pcitable.orig # of course, everything says these files are important # but I can only see that modules.dep has any value. Even with # that said, I can't say that modules.dep gets used by anything. #vi $BOOTROOT/initrd_tmp/modules/module-info #vi $BOOTROOT/initrd_tmp/modules/modules.dep #vi $BOOTROOT/initrd_tmp/modules/pcitable cp $CDROOT/../../stock-items/module-info $BOOTROOT/initrd_tmp/modules/module-info cp $CDROOT/../../stock-items/modules.dep $BOOTROOT/initrd_tmp/modules/modules.dep cp $CDROOT/../../stock-items/pcitable $BOOTROOT/initrd_tmp/modules/pcitable # 11. Rebuild the initrd. One of the webpages I referenced said: "If we don't # leave enough free space on the initrd image, then it won't be able to load # e.g. modules (+1000k free space worked for me so far). Remember that this is # the space that will be available once initrd has been uncompressed during the # boot process." So we're going to rebuild the initrd with a bigger filesystem. INITRD_SIZE=`du -k -s $BOOTROOT/initrd_tmp | awk '{print $1}'` let "NEW_INITRD_SIZE=$INITRD_SIZE + 1000" /bin/mkdir $BOOTROOT/initrd_new_image /bin/dd if=/dev/zero bs=1k count=$NEW_INITRD_SIZE of=$BOOTROOT/initrd_new.img /bin/echo "y" | /sbin/mke2fs $BOOTROOT/initrd_new.img > /dev/null /bin/mount -o loop $BOOTROOT/initrd_new.img $BOOTROOT/initrd_new_image /bin/cp -a $BOOTROOT/initrd_tmp/* $BOOTROOT/initrd_new_image/ sync # I'm not sure if this is really needed. umount $BOOTROOT/initrd_new_image umount $BOOTROOT/initrd_image gzip -9 $BOOTROOT/initrd_new.img /bin/cp $BOOTROOT/initrd_new.img.gz $BOOTROOT/boot_image/initrd.img checksum $BOOTROOT/initrd_new.img.gz $BOOTROOT/boot_image/initrd.img # 5. Edit syslinux.cfg: ## default ks ## prompt 0 ## label ks ## kernel vmlinuz ## append ks initrd=initrd.img lang= devfs=nomount ramdisk_size=16384 vga=788 # The ramdisk_size is important! It needs to be big to hold the stage # two ramdisk, which will grow in size by the time we're done with it. # 5b. Get the right kernel on the boot_image so the driver's have a chance # of actually loading at runtime: cd $BOOTROOT/boot_image if [ -f /boot/vmlinuz-$NEW_BOOT_KERNEL_VERSION -a -f vmlinuz ]; then /bin/cp /boot/vmlinuz-$NEW_BOOT_KERNEL_VERSION vmlinuz checksum /boot/vmlinuz-$NEW_BOOT_KERNEL_VERSION vmlinuz else echo "is $NEW_BOOT_KERNEL_VERSION really right? I can't find it in /boot" echo "exiting" exit -1 fi # 6. Finally, let's save this image! cd $BOOTROOT umount $BOOTROOT/boot_image /bin/cp $BOOTROOT/boot.img $CDROOT/images/boot.img #echo "exiting before stage2" #exit # 13. As for the stage two image, it's more of the same: #/bin/cp $CDROOT/RedHat/base/stage2.img $BOOTROOT/ /bin/cp $CDROOT/../../stock-items/stage2.img $BOOTROOT/ /bin/mount -o loop $BOOTROOT/stage2.img $BOOTROOT/stage2_image /bin/cp -a $BOOTROOT/stage2_image $BOOTROOT/stage2_copy umount $BOOTROOT/stage2_image cd $BOOTROOT/stage2_copy zcat $BOOTROOT/stage2_copy/modules/modules.cgz | cpio -ivd mkdir $BOOTROOT/stage2_copy/$NEW_BOOT_KERNEL_VERSION cd $BOOTROOT/stage2_copy OldBootVersion=`zcat modules/modules.cgz | cpio -t |head -1 | awk -F / '{print $1}'` ModuleList=`ls $OldBootVersion` cd /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel for ModuleName in $ModuleList do NewModuleName=`find . -name $ModuleName` if [ "$NewModuleName" != "" ]; then echo " updating: $ModuleName" /bin/cp $NewModuleName $BOOTROOT/stage2_copy/$NEW_BOOT_KERNEL_VERSION/$ModuleName else echo " REMOVING: $ModuleName" fi done cd $BOOTROOT/stage2_copy/$NEW_BOOT_KERNEL_VERSION /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/cciss.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/cpqarray.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/block/DAC960.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aic7xxx/aic7xxx.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aic7xxx/aic79xx.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/aacraid/aacraid.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/scsi/megaraid2.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/ataraid.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/hptraid.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/medley.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/pdcraid.o . /bin/cp -f /lib/modules/$NEW_BOOT_KERNEL_VERSION/kernel/drivers/ide/raid/silraid.o . cp $CDROOT/../../stock-items/module-info.stage2 $BOOTROOT/stage2_copy/modules/module-info cp $CDROOT/../../stock-items/modules.dep.stage2 $BOOTROOT/stage2_copy/modules/modules.dep cp $CDROOT/../../stock-items/pcitable.stage2 $BOOTROOT/stage2_copy/modules/pcitable cd $BOOTROOT/stage2_copy find $NEW_BOOT_KERNEL_VERSION | cpio -ov -H crc | gzip -c9 > \ $BOOTROOT/stage2_copy/modules/modules.cgz rm -rf $BOOTROOT/stage2_copy/*BOOT cd $BOOTROOT mkcramfs stage2_copy stage2.img # and copy this stage2.img over the old stage2.img in the RedHat directory. cp $BOOTROOT/stage2.img $CDROOT/RedHat/base/stage2.img