forked from haiku/haiku
-
Notifications
You must be signed in to change notification settings - Fork 2
/
makehaikufloppy
124 lines (109 loc) · 2.91 KB
/
makehaikufloppy
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
usage() {
echo "Usage: makebootfloppy [-cd] [-base <directory>] [-preserve] [-image <target>]"
echo "-cd : Creates a boot floppy capable of booting to a CD."
echo " If not specified, the boot floppy will only be able to boot"
echo " systems from hard drives."
echo "-base : Specifies the base directory of the system you wish to make"
echo " a boot floppy from. Defaults to /boot"
echo "-preserve : Leaves a copy of the floppy image in /tmp (only valid when"
echo " used with the -cd option)."
echo "-image : writes the floppy image to the specified file - this implies"
echo " the -cd option."
exit $1
}
BASE=/boot
CD=0
PRESERVE=0
IMAGE=/dev/disk/floppy/raw
while [ "x$1" != "x" ] ; do
if [ "$1" = "-help" ] || [ "$1" = "--help" ] ; then
usage 0
elif [ "$1" = "-cd" ] ; then
CD=1
elif [ "$1" = "-preserve" ] ; then
PRESERVE=1
elif [ "$1" = "-image" ] ; then
shift
IMAGE=$1
CD=1
if [ "x$1" = "x" ] ; then
echo "-image requires an argument."
usage 1
fi
elif [ "$1" = "-base" ] ; then
shift
BASE=$1
if [ "x$1" = "x" ] || [ ! -d $BASE ] ; then
echo "-base requires a directory argument."
usage 1
fi
else
echo "Invalid option: $1"
usage 1
fi
shift
done
if [ $CD = 1 ] ; then
rm -f /tmp/boot.tgz /tmp/boot.img
echo "Creating boot image..."
mkdir -p /tmp/system
cp $BASE/system/kernel_x86 /tmp/system/
oldCWD=$(pwd)
cd /tmp
tar chf /tmp/boot.tar system/kernel_x86
rm -r /tmp/system
cd $oldCWD
cd $BASE
pwd
tar rvhf /tmp/boot.tar \
system/add-ons/kernel/busses/ide \
system/add-ons/kernel/bus_managers \
system/add-ons/kernel/file_systems/bfs \
system/add-ons/kernel/generic \
system/add-ons/kernel/partitioning_systems \
system/add-ons/kernel/drivers/disk/scsi/scsi* \
system/add-ons/kernel/file_systems/bfs \
> /dev/null
# system/add-ons/kernel/boot \
gzip -c /tmp/boot.tar > /tmp/boot.tgz
rm /tmp/boot.tar
cd $oldCWD
if [ $? != 0 ] ; then
echo "Error creating boot floppy"
exit 1
fi
dd if=/dev/zero of=/tmp/boot.img bs=1k count=1440
if [ $? != 0 ] ; then
echo "Error creating temporary boot image"
exit 1
fi
dd if=$BASE/system/haiku_loader of=/tmp/boot.img conv=notrunc
dd if=/tmp/boot.tgz of=/tmp/boot.img bs=192k seek=1 conv=notrunc
echo "Writing boot image to "$IMAGE
dd if=/tmp/boot.img of=$IMAGE bs=72k
_retval=$?
if [ $PRESERVE = 0 ] ; then
rm -f /tmp/boot.tgz /tmp/boot.img
fi
if [ $_retval != 0 ] ; then
echo "Error creating boot floppy"
exit 1
fi
else
# non-CD mode (only writes the bare boot loader)
echo "Writing boot loader..."
dd if=$BASE/system/haiku_loader of=$IMAGE bs=18k
if [ $? != 0 ] ; then
echo "Error creating boot floppy"
exit 1
fi
echo "Erasing old boot drivers from the floppy..."
dd if=/dev/zero of=$IMAGE bs=512 conv=notrunc seek=384 count=1
if [ $? != 0 ] ; then
echo "Error creating boot floppy"
exit 1
fi
fi
echo "Done!"
exit 0