little more info in pagefault exception handler.
[minix.git] / tools / mkboot
blob7c6344ea4b9994c86001850ab68805b9f7b0bb3a
1 #!/bin/sh
3 # mkboot 2.0 - make boot floppy, make root device bootable, etc.
4 # Author: Kees J. Bot
6 trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
8 mdec=/usr/mdec # bootstraps
10 # Check arguments.
11 case "$#:$1" in
12 1:bootable | 1:hdboot | [12]:fdboot | [12]:cdfdboot )
13 action=$1 dev=$2
15 *) echo "Usage: $0 [bootable | hdboot | cdfdboot | fdboot [device]] | cdfdboot [device]" >&2
16 exit 1
17 esac
19 # Get the device table.
20 . /etc/fstab
22 # The real root device may be the RAM disk.
23 realroot=`printroot -r`
25 # If it's an initial fstab, pretend root is real root
26 if [ $root = "/dev/ROOT" ]
27 then root=$realroot
30 case $action in
31 bootable | hdboot)
32 # We need the root device.
34 if [ $realroot = $root ]
35 then
36 rootdir=
37 else
38 umount $root 2>/dev/null
39 mount $root /mnt || exit
40 rootdir=/mnt
42 esac
44 case $action in
45 bootable)
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
52 hdboot)
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`"
64 sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
65 version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
67 revision=`cat revision 2>/dev/null`
69 if [ -z "$revision" ]
70 then rrevision=""
71 else rrevision=r$revision
74 oldrev=$revision
76 target="${version}r${revision}"
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
90 revision=`expr $revision + 1`
91 rrevision=r$revision
93 target="${version}${rrevision}"
95 set -- `ls -t $rootdir/boot/image`
97 case $# in
98 0|1|2|3)
99 # Not much there, do not remove a thing.
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
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
112 # Save the revision number.
113 test "$revision" != "$oldrev" && echo $revision >revision
115 test $realroot != $root && umount $root
116 echo "Done."
118 fdboot)
119 # fdboot: Make a boot floppy.
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
129 /dev/*)
131 *) dev=/dev/$dev
132 esac
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;
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
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
161 edparams $dev 'main(){delay 2000;boot}; save' || exit
162 echo "Test kernel installed on $dev"
165 cdfdboot)
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
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;
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 /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 '
191 unset bootopts;
192 unset servers;
193 unset rootdev;
194 unset leader;
195 unset image;
196 disable=inet;
197 bootcd=1;
198 cdproberoot=1;
199 ata_id_timeout=2;
200 bootbig(1, Regular MINIX 3) { unset image; boot }
201 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 };
202 main(){trap 10000 boot; menu; };
203 save' || exit
205 # copy image
206 dd if=$dev of=cdfdimage bs=8192 count=180
207 esac
208 sync
209 exit 0