Rotate kernels/images/modules.

Kernels and system services are stored in a single directory in the
/boot/minix/ and rotated like /boot/images. /boot/minix_latest slink
is created automatically.
System serives are prefixed by "modNN_" to allow to easily load them
using "mod*" pattern.
This commit is contained in:
Evgeniy Ivanov
2012-01-30 16:27:23 +04:00
committed by Ben Gras
parent 60a2ce010a
commit 8979450631
3 changed files with 67 additions and 32 deletions

View File

@@ -3,19 +3,48 @@
# mkboot 2.0 - make boot floppy, make root device bootable, etc.
# Author: Kees J. Bot
usage() {
echo "Usage: $0 [bootable | hdboot [minix or image] | fdboot [device]]" >&2
exit 1
}
rotate_oldest() {
base_dir="$1"
set -- `ls -t "$base_dir"`
case $# in
0|1|2|3)
# Not much there, do not remove a thing.
;;
*)
# Remove the third-newest $hdboot_t in /boot/$hdboot_t, but
# only if there's an older one (which is kept).
echo "rm $root:$base_dir/$3"
rm -rf "$base_dir/$3"
esac
}
trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
mdec=/usr/mdec # bootstraps
# Check arguments.
case "$#:$1" in
1:bootable | 1:hdboot | [12]:fdboot )
1:bootable | 2:hdboot | [12]:fdboot )
action=$1 dev=$2 size=$3
;;
*) echo "Usage: $0 [bootable | hdboot | fdboot [device]]" >&2
exit 1
*) usage
esac
if [ "$1" = "hdboot" ]
then
if [ "$2" != "image" -a "$2" != "minix" ]
then usage
fi
hdboot_t="$2"
fi
# Get the device table.
FSTAB=/etc/fstab
touch $FSTAB
@@ -56,14 +85,14 @@ bootable)
;;
hdboot)
# Install a new image on the root device.
if [ ! -d $rootdir/boot/image ]
if [ -e $rootdir/boot/$hdboot_t -a ! -d $rootdir/boot/$hdboot_t ]
then
# /boot/image is not yet a directory! Fix it.
# /boot/$hdboot_t is not yet a directory! Fix it.
su root -c \
"exec mv $rootdir/boot/image /M"
install -d $rootdir/boot/image
"exec mv $rootdir/boot/$hdboot_t /M"
install -d $rootdir/boot/$hdboot_t
su root -c \
"exec mv $rootdir/M $rootdir/boot/image/`uname -r`"
"exec mv $rootdir/M $rootdir/boot/$hdboot_t/`uname -r`"
fi
sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
@@ -97,30 +126,24 @@ hdboot)
target="${version}${rrevision}${gitrev}"
set -- `ls -t $rootdir/boot/image`
rotate_oldest "$rootdir/boot/$hdboot_t"
case $# in
0|1|2|3)
# Not much there, do not remove a thing.
;;
*)
# 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"
esac
# rotate system processes. We assume latest ones are in
# /boot/modules/.temp and we maintain /boot/modules/ by ourselves.
if [ "$hdboot_t" = "minix" ]
then
[ -d /boot/minix/.temp ] || exit 1
mv /boot/minix/.temp /boot/minix/"$target"
rm -f /boot/minix_latest
ln -s /boot/minix/"$target" /boot/minix_latest
else
# Install the new image.
echo "install $hdboot_t $root:/boot/$hdboot_t/$target"
install -o root -m 600 $hdboot_t $rootdir/boot/$hdboot_t/$target || exit 1
# Install the new image.
echo "install image $root:/boot/image/$target"
install -o root -m 600 image $rootdir/boot/image/$target || exit
# 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
# Tell bootloader which image is newest
ln -f $rootdir/boot/$hdboot_t/$target $rootdir/boot/${hdboot_t}_latest
fi
ln -f $image_latest $rootdir/boot/image_latest
# Save the revision number.
test "$revision" != "$oldrev" && echo $revision >revision