blob: abbd101e45ada37a332444e0ef467cb726539932 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/bin/bash
# Create a bootable harddisk (or compact flash) image based upon a geometry
# given in cylinders, heads and sectors
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
EOF
}
while getopts "hC:H:S:m:n:r:i:f:" 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"
;;
i) IMAGEDIR="$OPTARG"
;;
f) source "$OPTARG"
;;
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 ))
# Offset for first partition in bytes
PART1OFFSET=$(( $(echo $PART1 | awk -F "," '{print $1}') * $UNITSIZE))
# Size of the root partition in bytes
PART1SIZE=$(($(echo $PART1 | awk -F "," '{print $2}') * $UNITSIZE))
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`
# generate a partition table
sfdisk -x -C $CYLINDERS -H $HEADS -S $SECTORS $IMAGEDIR/hd.img << EOF
$PART1
$PART2
$PART3
$PART4
EOF
|