#!/bin/sh
#
# linbo_warmstart
# thomas@linuxmuster.net
# 20250419
#

# get environment
source /usr/share/linbo/shell_functions
echo "### $timestamp $(basename "$0") ###"
source /conf/linbo || exit 1

KEXEC="/sbin/kexec"
KERNEL="/cache/linbo64"
INITRD="/cache/linbofs64"
TYPE="bzImage64"

linbo_mountcache &> /dev/null || exit 1

if [ ! -s "$KERNEL" -o ! -s "$INITRD" ]; then
  echo "Linbokernel not found in cache!"
  exit 1
fi

echo "Initiating linbo warmstart ..."

if warmstart; then

  # load linbo kernel
  $KEXEC --type="$TYPE" --append="$kerneloptions" --initrd="$INITRD" --load "$KERNEL" ; RC="$?"
  [ "$RC" = "0" ] || exit 1
  # execute linbo kernel
  $KEXEC -e ; RC="$?"
  [ "$RC" = "0" ] || exit 1

else

  # initiate reboot bypassing an existing grub menu
  FORCEGRUB="yes"
  mk_boot "$cache" "$(basename $KERNEL)" "$(basename $INITRD)" "$kerneloptions" ; RC="$?"
  [ "$RC" = "0" ] || exit 1
  /sbin/reboot -f

fi

sendlog