diff --git a/linbofs/init.sh b/linbofs/init.sh index 6228bf0..ada6f71 100755 --- a/linbofs/init.sh +++ b/linbofs/init.sh @@ -5,7 +5,7 @@ # License: GPL V2 # # thomas@linuxmuster.net -# 20211122 +# 20211129 # # If you don't have a "standalone shell" busybox, enable this: @@ -489,13 +489,15 @@ do_housekeeping(){ do_linbo_update(){ local server="$1" local rebootflag="/tmp/.linbo.reboot" + local cfg="/cache/boot/grub/custom.cfg" local cachedev="$(printcache)" + linbo_cmd mount "$cachedev" /cache + [ -e "${cfg}.reboot" ] && mv "${cfg}.reboot" "$cfg" # start linbo update linbo_cmd update "$server" "$cachedev" 2>&1 | tee /cache/update.log # initiate warm start - if [ -e "$rebootflag" -a "$warmstart" != "no" ]; then + if [ -e "$rebootflag" ]; then echo -n "Local LINBO/GRUB configuration was updated. Initiating linbo warmstart ..." - cd / /usr/bin/linbo_warmstart fi } diff --git a/linbofs/usr/bin/linbo_cmd b/linbofs/usr/bin/linbo_cmd index 44238ed..1e01482 100755 --- a/linbofs/usr/bin/linbo_cmd +++ b/linbofs/usr/bin/linbo_cmd @@ -1468,15 +1468,18 @@ start(){ local INITRD local APPEND local KERNEL="${3#/}" - local warmstart + local warmstart="no" local i local partition="$2" local label="$(print_partlabel "$partition")" local cachedev="$6" + local mntpnt="/mnt" + [ "$partition" = "$cachedev" ] && mntpnt="/cache" + [ -d /sys/firmware/efi/efivars ] && local efi="true" local startflag="/tmp/.start" touch "$startflag" - if mountpart "$partition" /mnt -w 2>> /tmp/linbo.log; then - if [ -e "/mnt/$KERNEL" ]; then + if mountpart "$partition" "$mntpnt" 2>> /tmp/linbo.log; then + if [ -e "$mntpnt/$KERNEL" ]; then echo "Found kernel $KERNEL on partition $partition." INITRD="${4#/}" APPEND="$5" @@ -1486,8 +1489,11 @@ start(){ else APPEND="root=$partition $APPEND" fi - # test for warmstart boot parameter - for i in `cat /proc/cmdline`; do case "$i" in warmstart=*) eval $i ;; esac; done + # test for warmstart boot parameter, if not linbo reboot and not efi + if [ "$partition" != "$cachedev" -a -z "$efi" ]; then + warmstart="yes" + for i in `cat /proc/cmdline`; do case "$i" in warmstart=*) eval $i ;; esac; done + fi # load kernel for later warmstart if [ "$warmstart" != "no" ]; then kexec --type="bzImage" --append="$APPEND" --initrd="/mnt/$INITRD" --load "/mnt/$KERNEL" && warmstart="yes" @@ -1499,7 +1505,7 @@ start(){ # install/update grub/efi stuff if cache is mounted if mountcache "$cachedev"; then # prepare reboot if no warmstart - [ "$warmstart" != "yes" ] && mk_boot "$partition" "$KERNEL" "$INITRD" "$APPEND" | tee -a /tmp/linbo.log + [ "$warmstart" = "no" ] && mk_boot "$partition" "$KERNEL" "$INITRD" "$APPEND" | tee -a /tmp/linbo.log # update linuxmuster-win scripts and install start tasks [ "$(fstype "$partition")" = "ntfs" -a -d /cache/linuxmuster-win ] && update_win "$partition" | tee -a /tmp/linbo.log fi @@ -1532,7 +1538,7 @@ start(){ umount /mnt 2>> /tmp/linbo.log sendlog # start os directly or reboot into it - if [ "$warmstart" = "yes" ]; then + if [ "$warmstart" != "no" ]; then kexec -e else reboot -f diff --git a/linbofs/usr/bin/linbo_warmstart b/linbofs/usr/bin/linbo_warmstart index 7070ecc..c86e109 100755 --- a/linbofs/usr/bin/linbo_warmstart +++ b/linbofs/usr/bin/linbo_warmstart @@ -1,47 +1,57 @@ #!/bin/sh # -# linbo_warmstart +# linbo_warmstart # thomas@linuxmuster.net -# 20211122 +# 20211129 # -KEXEC="/sbin/kexec" -LINBO="/cache/linbo64" -LINBOFS="/cache/linbofs64.lz" - -KERNEL="$1" -[ -z "$KERNEL" ] && KERNEL="$LINBO" -if [ ! -s "$KERNEL" ]; then - echo "Kernel $KERNEL not found!" - exit 1 +if [ -n "$1" ]; then + CACHE="$1" +else + CACHE="$(grep -iw ^cache /start.conf | tail -1 | awk -F\= '{print $2}' | awk '{print $1}' | awk -F\# '{print $1}' | awk '{print $1}')" fi -INITRD="$2" -[ -z "$INITRD" ] && INITRD="$LINBOFS" -if [ ! -s "$INITRD" ]; then - echo "Initrd $INITRD not found!" +if [ ! -b "$CACHE" ]; then + [ -z "$CACHE" ] && CACHE="" + echo "Cache $CACHE is not a blockdevice!" exit 1 fi -APPEND="$3" -if [ -z "$APPEND" -a "$KERNEL" = "$LINBO" -a "$INITRD" = "$LINBOFS" ]; then - APPEND="$(cat /proc/cmdline)" -fi -if [ -z "$APPEND" ]; then - echo "Kernel append string is empty. Check your parameters!" - exit 1 -fi +KEXEC="/sbin/kexec" +KERNEL="linbo64" +INITRD="linbofs64.lz" +APPEND="$(cat /proc/cmdline)" +CFG="/cache/boot/grub/custom.cfg" +TPL="/usr/share/linbo/warmstart.cfg" +[ -d /sys/firmware/efi/efivars ] && EFI="true" -# load linbo kernel -if ! $KEXEC --type="bzImage" --append="$APPEND" --initrd="$INITRD" --load "$KERNEL"; then - echo "Failed to load kernel!" - exit 1 +# test for warmstart boot parameter +warmstart="yes" +for i in $APPEND; do case "$i" in warmstart=*) eval $i ;; esac; done +if [ "$warmstart" = "no" ]; then + echo "Skipping kexec'd linbo warmstart, rebooting instead." fi -# execute linbo kernel -if ! $KEXEC -e; then - echo "Failed to execute kernel!" - exit 1 +cd / +linbo_cmd mount "$CACHE" /cache + +# cold reboot +if [ -n "$EFI" -o "$warmstart" = "no" ]; then + mv "$CFG" "$CFG".reboot || exit 1 + sed -e "s|@@kopts@@|$APPEND|" "$TPL" > "$CFG" || exit 1 + linbo_cmd start "" "$CACHE" "$KERNEL" "$INITRD" "$APPEND" "$CACHE" +# kexec boot +else + # load linbo kernel + if ! $KEXEC --type="bzImage" --append="$APPEND" --initrd="/cache/$INITRD" --load "/cache/$KERNEL"; then + echo "Failed to load kernel!" + exit 1 + fi + # execute linbo kernel + if ! $KEXEC -e; then + echo "Failed to execute kernel!" + exit 1 + fi fi exit 0 diff --git a/linbofs/usr/share/linbo/warmstart.cfg b/linbofs/usr/share/linbo/warmstart.cfg new file mode 100644 index 0000000..0da7ccc --- /dev/null +++ b/linbofs/usr/share/linbo/warmstart.cfg @@ -0,0 +1,42 @@ +# temporary grub.cfg template for linbo reboot +# thomas@linuxmuster.net +# 20211129 +# + +set default=0 +set timeout=0 + +set gfxmode=auto +set gfxpayload=keep + +insmod all_video +insmod png +insmod gfxterm +insmod gfxmenu +insmod minicmd +insmod progress + +terminal_output gfxterm + +background_color 42,68,87 + +set linbo_kernel=/linbo64 +set linbo_initrd=/linbofs64.lz + +# theme settings (modify for custom theme) +set theme=/boot/grub/themes/linbo/theme.txt +export theme + +clear + +# find linbo cache partition +search --file "$linbo_initrd" --set root + +menuentry 'LINBO' --class linbo { + echo -n "Loading $linbo_kernel ..." + linux $linbo_kernel @@kopts@@ + echo + echo -n "Loading $linbo_initrd ..." + initrd $linbo_initrd + boot +}