forked from vivekp/minix-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkboot
More file actions
executable file
·184 lines (160 loc) · 4.68 KB
/
Copy pathmkboot
File metadata and controls
executable file
·184 lines (160 loc) · 4.68 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
#
# mkboot 2.0 - make boot floppy, make root device bootable, etc.
# Author: Kees J. Bot
trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
mdec=/usr/mdec # bootstraps
# Check arguments.
case "$#:$1" in
1:bootable | 1:hdboot | [12]:fdboot | 1:cdfdboot )
action=$1 dev=$2
;;
*) echo "Usage: $0 [bootable | hdboot | cdfdboot | fdboot [device]]" >&2
exit 1
esac
# Get the device table.
. /etc/fstab
# The real root device may be the RAM disk.
realroot=`printroot -r`
# If it's an initial fstab, pretend root is real root
if [ $root = "/dev/ROOT" ]
then root=$realroot
fi
case $action in
bootable | hdboot)
# We need the root device.
if [ $realroot = $root ]
then
rootdir=
else
umount $root 2>/dev/null
mount $root /mnt || exit
rootdir=/mnt
fi
esac
case $action in
bootable)
# Install the boot monitor on the root device and make it bootable.
install -cs -m 644 $mdec/boot $rootdir/boot/boot || exit
sync
installboot -device $root $mdec/bootblock /boot/boot || exit
test $realroot != $root && umount $root
;;
hdboot)
# Install a new image on the root device.
if [ ! -d $rootdir/boot/image ]
then
/boot/image is not yet a directory! Fix it.
su root -c \
"exec mv $rootdir/boot/image /M"
install -d $rootdir/boot/image
su root -c \
"exec mv $rootdir/M $rootdir/boot/image/`uname -r`.`uname -v`"
fi
sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
revision=`cat revision 2>/dev/null`
oldrev=$revision
target="${version}r${revision}"
if [ -z "$revision" ]
then
target="${version}"
revision=0
elif [ -f $rootdir/boot/image/$target ]
then
if [ $rootdir/boot/image/$target -newer image ]
then
echo "$root:/boot/image/$target is up to date"
test $realroot != $root && umount $root
exit 0
fi
revision=`expr $revision + 1`
target="${version}r${revision}"
fi
set -- `ls -t $rootdir/boot/image`
case $# in
0|1|2|3)
# Not much there, do not remove a thing.
;;
*)
# Remove the third-newest image in /boot/image, but
# only if there's an older one (which is kept).
echo "rm $root:/boot/image/$3"
rm -f "$rootdir/boot/image/$3"
esac
# Install the new image.
echo "install image $root:/boot/image/$target"
install -o root -m 600 image $rootdir/boot/image/$target || exit
# Save the revision number.
test "$revision" != "$oldrev" && echo $revision >revision
test $realroot != $root && umount $root
echo "Done."
;;
fdboot)
# fdboot: Make a boot floppy.
if [ -z "$dev" ]
then
echo -n \
"Finish the name of the floppy device to write (by default 'fd0'): /dev/";
read dev
case "$dev" in
'') dev=/dev/fd0
;;
/dev/*)
;;
*) dev=/dev/$dev
esac
fi
# Make a file system.
umount $dev 2>/dev/null
if mkfs -B 1024 -i 512 $dev
then :
else
echo "mkfs of $dev failed."
exit 1;
fi
# Install /dev, /boot/boot and /boot/image.
mount $dev /mnt || exit
mkdir -p /mnt/boot/image || exit
cpdir /dev /mnt/dev || exit
cp -p $mdec/boot /mnt/boot/boot || exit
cp -p image /mnt/boot/image/ || exit
umount $dev || exit
# Make bootable and copy the boot parameters.
installboot -d $dev $mdec/bootblock /boot/boot || exit
pfile=fdbootparams
if [ -f $pfile ]
then echo "Using floppy boot parameters from file $pfile."
edparams $dev "`cat $pfile`" || exit
else echo "Copying floppy boot parameters from $root."
dd if=$root of=$dev skip=1 seek=1 count=1 conv=silent || exit
fi
edparams $dev 'main(){delay 2000;boot}; save' || exit
echo "Test kernel installed on $dev"
;;
cdfdboot)
# cdfdboot: Make a boot floppy image to go on a CD for booting from.
dev=/dev/ram
umount $dev 2>/dev/null
if mkfs -B 1024 -b 1440 -i 512 $dev || exit 1
then :
else
echo "mkfs of $dev failed."
exit 1;
fi
# Install /dev, /boot
mount $dev /mnt || exit 1
mkdir /mnt/dev
mkdir /mnt/boot
mkdir /mnt/boot/image
( cd /mnt/dev && /usr/src/commands/scripts/MAKEDEV.sh std )
cp -p image image_* /mnt/boot/image || exit 1
cp -p ../boot/boot /mnt/boot/boot || exit 1
umount $dev || exit 1
installboot -d $dev ../boot/bootblock boot/boot || exit 1
edparams $dev 'unset bootopts; unset servers; disable=inet; image=/boot/image/image_big; bootbig(1, Regular MINIX 3 (requires at least 16 MB RAM)) { image=/boot/image/image ; boot } bootsmall(2, Small MINIX 3 (intended for 8 MB systems)) { image=/boot/image/image_small ; boot } cdproberoot=1; unset rootdev; unset leader; leader() { echo \n--- Welcome to MINIX 3. This is the boot monitor. ---\n\nChoose an option from the menu or press ESC if you need to do anything special.\nOtherwise I will boot with my defaults in 10 seconds.\n\n }; bootcd=1; main(){trap 10000 boot; menu; }; save' || exit
# copy image
dd if=$dev of=cdfdimage bs=8192 count=180
esac
sync
exit 0