summaryrefslogtreecommitdiffstats
path: root/scripts/genhdimg
blob: f6a20d01786bc70c2f30a93bfc8cf53b2adfae7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash

# Create a bootable harddisk (or compact flash) image

Usage() {
cat <<-EOF

Usage: `basename "$0"` OPTIONS <svn rep>

    -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 "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