#!/bin/bash # Create a bootable harddisk (or compact flash) image Usage() { cat <<-EOF Usage: `basename "$0"` OPTIONS -h this help -m path to grub stage1 -n path to grub stage2 -o resulting hd image -i filesystem image -p partition size in kilobytes EOF } while getopts "hm:n:i:o:p:" OPT do case "$OPT" in h) Usage exit 1 ;; m) STAGE1="$OPTARG" ;; n) STAGE2="$OPTARG" ;; o) IMAGEFILE="$OPTARG" ;; i) FSIMAGE="$OPTARG" ;; p) PARTSIZE=$(($OPTARG * 2)) ;; esac done # get the first 446 bytes of stage1 dd if=$STAGE1 bs=446 count=1 > $IMAGEFILE # append a partition table to it. # We leave space of 299 blocks to # the first partition to put stage2 into # this space genpart -c -b 300 -s $PARTSIZE >> $IMAGEFILE genpart -b 0 -s 0 >> $IMAGEFILE genpart -b 0 -s 0 >> $IMAGEFILE genpart -b 0 -s 0 -m >> $IMAGEFILE # append stage2 padded to 299 blocks cat $STAGE2 /dev/zero | dd bs=512 count=299 >> $IMAGEFILE # append the ext2 image padded to PARTSIZE blocks cat $FSIMAGE /dev/zero | dd bs=512 count=$(($PARTSIZE - 300)) >> $IMAGEFILE