Skip to content

Commit

Permalink
linbo warmstart improvements (#24).
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyBasher committed Nov 29, 2021
1 parent 0fdb660 commit a4e7d48
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 41 deletions.
8 changes: 5 additions & 3 deletions linbofs/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License: GPL V2
#
# [email protected]
# 20211122
# 20211129
#

# If you don't have a "standalone shell" busybox, enable this:
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 13 additions & 7 deletions linbofs/usr/bin/linbo_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
72 changes: 41 additions & 31 deletions linbofs/usr/bin/linbo_warmstart
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
#!/bin/sh
#
# linbo_warmstart <kernel> <initrd>
# linbo_warmstart <device>
# [email protected]
# 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="<None>"
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
42 changes: 42 additions & 0 deletions linbofs/usr/share/linbo/warmstart.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# temporary grub.cfg template for linbo reboot
# [email protected]
# 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
}

0 comments on commit a4e7d48

Please sign in to comment.