3 # mkboot 2.0 - make boot floppy, make root device bootable, etc.
7 echo "Usage: $0 [bootable | hdboot [minix or image] | fdboot [device]]" >&2
13 set -- `ls -t "$base_dir"`
17 # Not much there, do not remove a thing.
20 # Remove the third-newest $hdboot_t in /boot/$hdboot_t, but
21 # only if there's an older one (which is kept).
22 echo "rm $root:$base_dir/$3"
28 trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
30 mdec
=/usr
/mdec
# bootstraps
34 1:bootable |
2:hdboot |
[12]:fdboot
)
35 action
=$1 dev
=$2 size
=$3
40 if [ "$1" = "hdboot" ]
42 if [ "$2" != "image" -a "$2" != "minix" ]
48 # Get the device table.
51 if grep -q "Poor man" $FSTAB
53 else root
="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
56 # The real root device may be the RAM disk.
57 realroot
=`printroot -r`
59 # If it's an initial fstab, pretend root is real root
60 if [ "$root" = "/dev/ROOT" -o -z "$root" ]
66 # We need the root device.
68 if [ $realroot = $root ]
72 umount
$root 2>/dev
/null
73 mount
$root /mnt ||
exit
80 # Install a new image on the root device.
81 if [ -e $rootdir/boot
/$hdboot_t -a ! -d $rootdir/boot
/$hdboot_t ]
83 # /boot/$hdboot_t is not yet a directory! Fix it.
85 "exec mv $rootdir/boot/$hdboot_t /M"
86 install -d $rootdir/boot
/$hdboot_t
88 "exec mv $rootdir/M $rootdir/boot/$hdboot_t/`uname -r`"
91 sh tell_config OS_RELEASE . OS_VERSION
>/tmp
/mkb.$$
92 version
=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
94 # Retrieve the git revision; this only succeeds
95 # if git is available, it's a git checkout, *and*
96 # there are no uncommitted changes.
97 if git
diff --quiet 2>/dev
/null
98 then gitrev
="-`git describe --always`"
101 revision
=`cat revision 2>/dev/null`
103 if [ -z "$revision" ]
106 else rrevision
=r
$revision
111 if [ -z "$revision" ]
116 revision
=`expr $revision + 1`
120 target
="${version}${rrevision}${gitrev}"
122 rotate_oldest
"$rootdir/boot/$hdboot_t"
124 # rotate system processes. We assume latest ones are in
125 # /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
126 if [ "$hdboot_t" = "minix" ]
128 [ -d /boot
/minix
/.temp
] ||
exit 1
129 rm -rf /boot
/minix
/"$target"/
130 mv /boot
/minix
/.temp
/boot
/minix
/"$target"
131 rm -f /boot
/minix_latest
132 ln -s minix
/"$target" /boot
/minix_latest
134 # Install the new image.
135 echo "install $hdboot_t $root:/boot/$hdboot_t/$target"
136 install -o root
-m 600 $hdboot_t $rootdir/boot
/$hdboot_t/$target ||
exit 1
138 # Tell bootloader which image is newest
139 ln -f $rootdir/boot
/$hdboot_t/$target $rootdir/boot
/${hdboot_t}_latest
142 # Save the revision number.
143 test "$revision" != "$oldrev" && echo $revision >revision
145 test $realroot != $root && umount
$root