source: trunk/minix/tools/mkboot@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1#!/bin/sh
2#
3# mkboot 2.0 - make boot floppy, make root device bootable, etc.
4# Author: Kees J. Bot
5
6trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
7
8mdec=/usr/mdec # bootstraps
9
10# Check arguments.
11case "$#:$1" in
121:bootable | 1:hdboot | [12]:fdboot | [12]:cdfdboot )
13 action=$1 dev=$2
14 ;;
15*) echo "Usage: $0 [bootable | hdboot | cdfdboot | fdboot [device]] | cdfdboot [device]" >&2
16 exit 1
17esac
18
19# Get the device table.
20. /etc/fstab
21
22# The real root device may be the RAM disk.
23realroot=`printroot -r`
24
25# If it's an initial fstab, pretend root is real root
26if [ $root = "/dev/ROOT" ]
27then root=$realroot
28fi
29
30case $action in
31bootable | hdboot)
32 # We need the root device.
33
34 if [ $realroot = $root ]
35 then
36 rootdir=
37 else
38 umount $root 2>/dev/null
39 mount $root /mnt || exit
40 rootdir=/mnt
41 fi
42esac
43
44case $action in
45bootable)
46 # Install the boot monitor on the root device and make it bootable.
47 install -cs -m 644 $mdec/boot $rootdir/boot/boot || exit
48 sync
49 installboot -device $root $mdec/bootblock /boot/boot || exit
50 test $realroot != $root && umount $root
51 ;;
52hdboot)
53 # Install a new image on the root device.
54 if [ ! -d $rootdir/boot/image ]
55 then
56 /boot/image is not yet a directory! Fix it.
57 su root -c \
58 "exec mv $rootdir/boot/image /M"
59 install -d $rootdir/boot/image
60 su root -c \
61 "exec mv $rootdir/M $rootdir/boot/image/`uname -r`.`uname -v`"
62 fi
63
64 sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
65 version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
66
67 revision=`cat revision 2>/dev/null`
68
69 if [ -z "$revision" ]
70 then rrevision=""
71 else rrevision=r$revision
72 fi
73
74 oldrev=$revision
75
76 target="${version}r${revision}"
77
78 if [ -z "$revision" ]
79 then
80 revision=0
81 rrevision=""
82 elif [ -f $rootdir/boot/image/$target ]
83 then
84 if [ $rootdir/boot/image/$target -newer image ]
85 then
86 echo "$root:/boot/image/$target is up to date"
87 test $realroot != $root && umount $root
88 exit 0
89 fi
90 revision=`expr $revision + 1`
91 rrevision=r$revision
92 fi
93 target="${version}${rrevision}"
94
95 set -- `ls -t $rootdir/boot/image`
96
97 case $# in
98 0|1|2|3)
99 # Not much there, do not remove a thing.
100 ;;
101 *)
102 # Remove the third-newest image in /boot/image, but
103 # only if there's an older one (which is kept).
104 echo "rm $root:/boot/image/$3"
105 rm -f "$rootdir/boot/image/$3"
106 esac
107
108 # Install the new image.
109 echo "install image $root:/boot/image/$target"
110 install -o root -m 600 image $rootdir/boot/image/$target || exit
111
112 # Save the revision number.
113 test "$revision" != "$oldrev" && echo $revision >revision
114
115 test $realroot != $root && umount $root
116 echo "Done."
117 ;;
118fdboot)
119 # fdboot: Make a boot floppy.
120
121 if [ -z "$dev" ]
122 then
123 echo -n \
124"Finish the name of the floppy device to write (by default 'fd0'): /dev/";
125 read dev
126 case "$dev" in
127 '') dev=/dev/fd0
128 ;;
129 /dev/*)
130 ;;
131 *) dev=/dev/$dev
132 esac
133 fi
134
135 # Make a file system.
136 umount $dev 2>/dev/null
137 if mkfs -B 1024 -i 512 $dev
138 then :
139 else
140 echo "mkfs of $dev failed."
141 exit 1;
142 fi
143
144 # Install /dev, /boot/boot and /boot/image.
145 mount $dev /mnt || exit
146 mkdir -p /mnt/boot/image || exit
147 cpdir /dev /mnt/dev || exit
148 cp -p $mdec/boot /mnt/boot/boot || exit
149 cp -p image /mnt/boot/image/ || exit
150 umount $dev || exit
151
152 # Make bootable and copy the boot parameters.
153 installboot -d $dev $mdec/bootblock /boot/boot || exit
154 pfile=fdbootparams
155 if [ -f $pfile ]
156 then echo "Using floppy boot parameters from file $pfile."
157 edparams $dev "`cat $pfile`" || exit
158 else echo "Copying floppy boot parameters from $root."
159 dd if=$root of=$dev skip=1 seek=1 count=1 conv=silent || exit
160 fi
161 edparams $dev 'main(){delay 2000;boot}; save' || exit
162 echo "Test kernel installed on $dev"
163 ;;
164
165cdfdboot)
166 # cdfdboot: Make a boot floppy image to go on a CD for booting from.
167 if [ -z "$dev" ]
168 then
169 ramdisk `expr 1440 \* 1024` 2>/dev/null
170 dev=/dev/ram
171 fi
172 umount $dev 2>/dev/null
173 if mkfs -B 1024 -b 1440 -i 512 $dev || exit 1
174 then :
175 else
176 echo "mkfs of $dev failed."
177 exit 1;
178 fi
179
180 # Install /dev, /boot
181 mount $dev /mnt || exit 1
182 mkdir /mnt/dev
183 mkdir /mnt/boot
184 mkdir /mnt/boot/image
185 ( cd /mnt/dev && sh /usr/src/commands/scripts/MAKEDEV.sh std )
186 cp -p image image_* /mnt/boot/image || exit 1
187 cp -p ../boot/boot /mnt/boot/boot || exit 1
188 umount $dev || exit 1
189 installboot -d $dev ../boot/bootblock boot/boot || exit 1
190 edparams $dev 'unset bootopts; unset servers; disable=inet; image=/boot/image/image; 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
191
192 # copy image
193 dd if=$dev of=cdfdimage bs=8192 count=180
194esac
195sync
196exit 0
Note: See TracBrowser for help on using the repository browser.