summaryrefslogtreecommitdiffstats
path: root/scripts/genhdimg
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2006-11-22 14:52:48 +0000
committerSascha Hauer <s.hauer@pengutronix.de>2006-11-22 14:52:48 +0000
commit1e1e63cc5f27b9714c273b9dc28eff2a3f354eee (patch)
treed14ba41f418dab17d8178c9ac7ca53724236cbd9 /scripts/genhdimg
parente7e3ca7c4a481170ceb7f884dcb56d3844a44fd5 (diff)
downloadptxdist-1e1e63cc5f27b9714c273b9dc28eff2a3f354eee.tar.gz
ptxdist-1e1e63cc5f27b9714c273b9dc28eff2a3f354eee.tar.xz
almost rewritten
git-svn-id: https://svn.pengutronix.de/svn/ptxdist/trunks/ptxdist-trunk@6361 33e552b5-05e3-0310-8538-816dae2090ed
Diffstat (limited to 'scripts/genhdimg')
-rwxr-xr-xscripts/genhdimg96
1 files changed, 25 insertions, 71 deletions
diff --git a/scripts/genhdimg b/scripts/genhdimg
index 281ac28be..f6a20d017 100755
--- a/scripts/genhdimg
+++ b/scripts/genhdimg
@@ -1,100 +1,54 @@
#!/bin/bash
-# Create a bootable harddisk (or compact flash) image based upon a geometry
-# given in cylinders, heads and sectors
+# Create a bootable harddisk (or compact flash) image
Usage() {
cat <<-EOF
Usage: `basename "$0"` OPTIONS <svn rep>
- -h this help
- -C <CYL> set cylinders
- -H <HEAD> set heads
- -S <SEC> set sectors
- -m <stage1> path to grub stage1
- -n <stafe2> path to grub stage2
- -r <dir> path to root dir
- -f <file> read options from file
+ -h this help
+ -m <stage1> path to grub stage1
+ -n <stafe2> path to grub stage2
+ -o <hdimg file> resulting hd image
+ -i <img file> filesystem image
+ -p <size> partition size in kilobytes
EOF
}
-while getopts "hC:H:S:m:n:r:i:f:" OPT
+while getopts "hm:n:i:o:p:" OPT
do
case "$OPT" in
h) Usage
exit 1
;;
- C) CYLINDERS="$OPTARG"
- ;;
- H) HEADS="$OPTARG"
- ;;
- S) SECTORS="$OPTARG"
- ;;
m) STAGE1="$OPTARG"
;;
n) STAGE2="$OPTARG"
;;
- r) ROOTDIR="$OPTARG"
+ o) IMAGEFILE="$OPTARG"
;;
- i) IMAGEDIR="$OPTARG"
+ i) FSIMAGE="$OPTARG"
;;
- f) source "$OPTARG"
+ p) PARTSIZE=$(($OPTARG * 2))
;;
esac
done
-echo $IMAGEDIR
-# sanity checks
-if [ $(($HEADS)) = 0 ] || [ $((CYLINDERS)) = 0 ] || [ $((SECTORS)) = 0 ]
-then
- echo "set cylinders, heads and sectors"
- exit 1
-fi
-
-if [ ! -f "$STAGE1" ]; then
- echo "stage1 file \"$STAGE1\" not found"
- exit 1
-fi
-
-if [ ! -f "$STAGE2" ]; then
- echo "stage2 file \"$STAGE2\" not found"
- exit 1
-fi
-
-# Size of whole hd image, in bytes
-IMGSIZE=$(($HEADS * $CYLINDERS * $SECTORS * 512))
-
-# size of one unit, in bytes
-UNITSIZE=$(( $SECTORS * $HEADS * 512 ))
+# get the first 446 bytes of stage1
+dd if=$STAGE1 bs=446 count=1 > $IMAGEFILE
-# Offset for first partition in bytes
-PART1OFFSET=$(( $(echo $PART1 | awk -F "," '{print $1}') * $UNITSIZE))
+# 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
-# Size of the root partition in bytes
-PART1SIZE=$(($(echo $PART1 | awk -F "," '{print $2}') * $UNITSIZE))
+# append stage2 padded to 299 blocks
+cat $STAGE2 /dev/zero | dd bs=512 count=299 >> $IMAGEFILE
-echo ofs: $PART1OFFSET
-echo size: $PART1SIZE
-
-# cat grub stages together, pad with zeros to offset of first partition
-cat $STAGE1 $STAGE2 /dev/zero | \
- dd bs=1 count=$PART1OFFSET > $IMAGEDIR/hd.img.loader
-
-# generate a ext2 filesystem
-genext2fs -b $(($PART1SIZE/1024)) -d $ROOTDIR $IMAGEDIR/root.ext2
-
-# put the pieces together
-cat $IMAGEDIR/hd.img.loader $IMAGEDIR/root.ext2 > $IMAGEDIR/hd.img
-
-rm -f $IMAGEDIR/root.ext2 $IMAGEDIR/hd.img.loader
-
-TMPFILE=`mktemp /tmp/ptxdist.XXXXXX`
-
-# generate a partition table
-sfdisk -x -C $CYLINDERS -H $HEADS -S $SECTORS $IMAGEDIR/hd.img << EOF
-$PART1
-$PART2
-$PART3
-$PART4
-EOF
+# append the ext2 image padded to PARTSIZE blocks
+cat $FSIMAGE /dev/zero | dd bs=512 count=$(($PARTSIZE - 300)) >> $IMAGEFILE