From: Evgeniy Ivanov Date: Mon, 30 Jan 2012 12:27:23 +0000 (+0400) Subject: Rotate kernels/images/modules. X-Git-Tag: v3.2.0~67 X-Git-Url: http://zhaoyanbai.com/repos/nsupdate.html?a=commitdiff_plain;h=897945063173187d32109f8a6382eba07101ece7;p=minix.git 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. --- diff --git a/etc/mtree/minix.tree b/etc/mtree/minix.tree index a9b77af08..03653b63a 100644 --- a/etc/mtree/minix.tree +++ b/etc/mtree/minix.tree @@ -8,6 +8,7 @@ 755 root operator /etc/system.conf.d 755 root operator /boot 755 root operator /boot/image +755 root operator /boot/minix 555 root operator /mnt 555 root operator /proc 700 root operator /root diff --git a/tools/Makefile b/tools/Makefile index 3e7de5d1b..0e387adef 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -17,6 +17,7 @@ VFS= vfs PFS= pfs .endif KERNEL= kernel +# PROGRAMS are in the order they should be loaded by boot PROGRAMS= \ ../servers/ds/ds \ ../servers/rs/rs \ @@ -70,8 +71,7 @@ PAD_KERNEL_TEXT := padtext ../kernel/kernel kernel image: includes services ${PAD_KERNEL_TEXT} mkimage $(PROGRAMS) - cp ${KERNEL} ${PROGRAMS} /boot - strip -s ${KERNEL:T:S/^/\/boot\//} ${PROGRAMS:T:S/^/\/boot\//} + strip -s ${KERNEL} ${PROGRAMS} .else image: includes services ${PAD_KERNEL_TEXT} @@ -113,9 +113,20 @@ bootable: .if ${OBJECT_FMT} == "ELF" hdboot: image + rm -rf /boot/minix/.temp/ + mkdir -p /boot/minix/.temp +# mod_0 is used to make alphabetical order equal to the boot order + for i in ${PROGRAMS}; \ + do \ + let n=n+1 >/dev/null; \ + [ "$$n" -ge 10 ] && prefix="mod" || prefix="mod0"; \ + cp $$i /boot/minix/.temp/$${prefix}$${n}_`basename $$i`;\ + done + cp kernel /boot/minix/.temp/ + exec sh mkboot $@ minix .else hdboot: image - exec sh mkboot $@ + exec sh mkboot $@ image @sync .endif diff --git a/tools/mkboot b/tools/mkboot index ca2b67e19..9511dc3f6 100755 --- a/tools/mkboot +++ b/tools/mkboot @@ -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 - - # Install the new image. - echo "install image $root:/boot/image/$target" - install -o root -m 600 image $rootdir/boot/image/$target || exit + # 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 - # 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