2005-04-21 16:53:53 +02:00
|
|
|
#!/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
|
2010-01-18 15:10:04 +01:00
|
|
|
1:bootable | 1:hdboot | [12]:fdboot )
|
2009-12-24 00:59:32 +01:00
|
|
|
action=$1 dev=$2 size=$3
|
2005-04-21 16:53:53 +02:00
|
|
|
;;
|
2010-01-18 15:10:04 +01:00
|
|
|
*) echo "Usage: $0 [bootable | hdboot | fdboot [device]]" >&2
|
2005-04-21 16:53:53 +02:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Get the device table.
|
2011-11-09 16:34:47 +01:00
|
|
|
FSTAB=/etc/fstab
|
|
|
|
touch $FSTAB
|
|
|
|
if grep -q "Poor man" $FSTAB
|
|
|
|
then . $FSTAB
|
|
|
|
else root="`awk <$FSTAB '{ if($2=="/") { print $1 } }'`"
|
|
|
|
fi
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
# The real root device may be the RAM disk.
|
|
|
|
realroot=`printroot -r`
|
|
|
|
|
2005-05-03 10:54:36 +02:00
|
|
|
# If it's an initial fstab, pretend root is real root
|
2011-11-09 16:34:47 +01:00
|
|
|
if [ "$root" = "/dev/ROOT" -o -z "$root" ]
|
2005-05-03 10:54:36 +02:00
|
|
|
then root=$realroot
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
case $action in
|
|
|
|
bootable | hdboot)
|
|
|
|
# We need the root device.
|
2005-05-03 10:54:36 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
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
|
2012-01-10 10:45:46 +01:00
|
|
|
installboot_minix -device $root $mdec/bootblock /boot/boot || exit
|
2005-04-21 16:53:53 +02:00
|
|
|
test $realroot != $root && umount $root
|
|
|
|
;;
|
|
|
|
hdboot)
|
|
|
|
# Install a new image on the root device.
|
|
|
|
if [ ! -d $rootdir/boot/image ]
|
|
|
|
then
|
2010-03-15 11:42:51 +01:00
|
|
|
# /boot/image is not yet a directory! Fix it.
|
2005-04-21 16:53:53 +02:00
|
|
|
su root -c \
|
|
|
|
"exec mv $rootdir/boot/image /M"
|
|
|
|
install -d $rootdir/boot/image
|
|
|
|
su root -c \
|
2010-07-21 16:23:52 +02:00
|
|
|
"exec mv $rootdir/M $rootdir/boot/image/`uname -r`"
|
2005-04-21 16:53:53 +02:00
|
|
|
fi
|
|
|
|
|
2005-05-03 17:37:34 +02:00
|
|
|
sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
|
2005-04-21 16:53:53 +02:00
|
|
|
version=`sed 's/[" ]//g;/^$/d' </tmp/mkb.$$`
|
|
|
|
|
2010-11-25 16:25:17 +01:00
|
|
|
# Retrieve the git revision; this only succeeds
|
|
|
|
# if git is available, it's a git checkout, *and*
|
|
|
|
# there are no uncommitted changes.
|
|
|
|
if git diff --quiet 2>/dev/null
|
|
|
|
then gitrev="-`git describe --always`"
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
revision=`cat revision 2>/dev/null`
|
2006-01-18 14:26:50 +01:00
|
|
|
|
|
|
|
if [ -z "$revision" ]
|
|
|
|
then rrevision=""
|
2010-11-25 16:25:17 +01:00
|
|
|
gitrev=""
|
2006-01-18 14:26:50 +01:00
|
|
|
else rrevision=r$revision
|
|
|
|
fi
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
oldrev=$revision
|
2006-01-18 14:26:50 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
if [ -z "$revision" ]
|
|
|
|
then
|
|
|
|
revision=0
|
2006-01-18 13:37:45 +01:00
|
|
|
rrevision=""
|
2010-11-25 16:25:17 +01:00
|
|
|
else
|
2005-04-21 16:53:53 +02:00
|
|
|
revision=`expr $revision + 1`
|
2006-01-18 14:26:50 +01:00
|
|
|
rrevision=r$revision
|
2005-04-21 16:53:53 +02:00
|
|
|
fi
|
2010-11-25 16:25:17 +01:00
|
|
|
|
|
|
|
target="${version}${rrevision}${gitrev}"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
set -- `ls -t $rootdir/boot/image`
|
|
|
|
|
|
|
|
case $# in
|
2005-07-22 20:36:19 +02:00
|
|
|
0|1|2|3)
|
2005-04-21 16:53:53 +02:00
|
|
|
# Not much there, do not remove a thing.
|
|
|
|
;;
|
|
|
|
*)
|
2005-07-22 20:36:19 +02:00
|
|
|
# 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"
|
2005-04-21 16:53:53 +02:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Install the new image.
|
2005-05-04 15:47:05 +02:00
|
|
|
echo "install image $root:/boot/image/$target"
|
|
|
|
install -o root -m 600 image $rootdir/boot/image/$target || exit
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2010-07-23 16:24:34 +02:00
|
|
|
# Tell GRUB which image is newest
|
|
|
|
image_latest="`ls -t $rootdir/boot/image | head -n 1`"
|
|
|
|
if [ -f "$rootdir/boot/image/$image_latest" ]
|
|
|
|
then image_latest="/boot/image/$image_latest"
|
|
|
|
else image_latest=/boot/image_big
|
|
|
|
fi
|
|
|
|
ln -f $image_latest $rootdir/boot/image_latest
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
# 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
|
2005-06-29 14:04:10 +02:00
|
|
|
if mkfs -B 1024 -i 512 $dev
|
|
|
|
then :
|
|
|
|
else
|
|
|
|
echo "mkfs of $dev failed."
|
|
|
|
exit 1;
|
|
|
|
fi
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
# Install /dev, /boot/boot and /boot/image.
|
|
|
|
mount $dev /mnt || exit
|
2005-05-12 18:07:31 +02:00
|
|
|
mkdir -p /mnt/boot/image || exit
|
2005-04-21 16:53:53 +02:00
|
|
|
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.
|
2012-01-10 10:45:46 +01:00
|
|
|
installboot_minix -d $dev $mdec/bootblock /boot/boot || exit
|
2005-05-13 14:27:42 +02:00
|
|
|
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
|
2005-04-21 16:53:53 +02:00
|
|
|
edparams $dev 'main(){delay 2000;boot}; save' || exit
|
2005-05-13 14:27:42 +02:00
|
|
|
echo "Test kernel installed on $dev"
|
2005-04-21 16:53:53 +02:00
|
|
|
;;
|
|
|
|
esac
|
2005-05-24 14:03:42 +02:00
|
|
|
sync
|
2005-04-21 16:53:53 +02:00
|
|
|
exit 0
|