remove 3 awk files - don't have generated files in svn.
[minix.git] / tools / mkboot
blob1f46e6fb194fa9a9a55297037155f973bb1c958b
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 )
13 action=$1 dev=$2 size=$3
15 *) echo "Usage: $0 [bootable | hdboot | fdboot [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"
164 esac
165 sync
166 exit 0