2023-02-08 21:01:48 +00:00
|
|
|
#!/bin/bash
|
2017-07-12 04:17:45 +00:00
|
|
|
# Launches kexec from saved configuration entries
|
|
|
|
set -e -o pipefail
|
2018-12-06 23:24:28 +00:00
|
|
|
. /tmp/config
|
2017-04-29 17:40:34 +00:00
|
|
|
. /etc/functions
|
|
|
|
|
2023-02-20 16:01:17 +00:00
|
|
|
TRACE "Under /bin/kexec-boot"
|
2023-02-18 17:58:43 +00:00
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
dryrun="n"
|
2017-07-12 04:17:45 +00:00
|
|
|
printfiles="n"
|
|
|
|
printinitrd="n"
|
|
|
|
while getopts "b:e:r:a:o:fi" arg; do
|
2017-04-29 17:40:34 +00:00
|
|
|
case $arg in
|
|
|
|
b) bootdir="$OPTARG" ;;
|
|
|
|
e) entry="$OPTARG" ;;
|
|
|
|
r) cmdremove="$OPTARG" ;;
|
|
|
|
a) cmdadd="$OPTARG" ;;
|
2017-07-12 04:17:45 +00:00
|
|
|
o) override_initrd="$OPTARG" ;;
|
|
|
|
f) dryrun="y"; printfiles="y" ;;
|
|
|
|
i) dryrun="y"; printinitrd="y" ;;
|
2017-04-29 17:40:34 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2017-07-12 04:17:45 +00:00
|
|
|
if [ -z "$bootdir" -o -z "$entry" ]; then
|
2017-07-17 16:43:14 +00:00
|
|
|
die "Usage: $0 -b /boot -e 'kexec params|...|...'"
|
2017-07-12 04:17:45 +00:00
|
|
|
fi
|
|
|
|
|
2017-07-22 18:25:39 +00:00
|
|
|
bootdir="${bootdir%%/}"
|
2017-07-12 04:17:45 +00:00
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
kexectype=`echo $entry | cut -d\| -f2`
|
|
|
|
kexecparams=`echo $entry | cut -d\| -f3- | tr '|' '\n'`
|
|
|
|
kexeccmd="kexec"
|
|
|
|
|
2017-07-30 21:33:26 +00:00
|
|
|
cmdadd="$CONFIG_BOOT_KERNEL_ADD $cmdadd"
|
|
|
|
cmdremove="$CONFIG_BOOT_KERNEL_REMOVE $cmdremove"
|
2017-07-03 03:01:04 +00:00
|
|
|
|
2022-01-07 19:30:57 +00:00
|
|
|
if [ "$(load_config_value CONFIG_USE_BLOB_JAIL)" = "y" ]; then
|
|
|
|
cmdadd="$cmdadd firmware_class.path=/run/firmware/"
|
|
|
|
fi
|
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
fix_file_path() {
|
2017-07-12 04:17:45 +00:00
|
|
|
if [ "$printfiles" = "y" ]; then
|
|
|
|
# output file relative to local boot directory
|
|
|
|
echo ".$firstval"
|
|
|
|
fi
|
|
|
|
|
|
|
|
filepath="$bootdir$firstval"
|
2017-07-04 23:49:14 +00:00
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
if ! [ -r $filepath ]; then
|
2017-07-12 04:17:45 +00:00
|
|
|
die "Failed to find file $firstval"
|
2017-04-29 17:40:34 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-07-13 04:33:49 +00:00
|
|
|
adjusted_cmd_line="n"
|
2017-04-29 17:40:34 +00:00
|
|
|
adjust_cmd_line() {
|
|
|
|
if [ -n "$cmdremove" ]; then
|
|
|
|
for i in $cmdremove; do
|
2021-10-15 18:38:24 +00:00
|
|
|
cmdline=$(echo $cmdline | sed "s/\b$i\b//g")
|
2017-04-29 17:40:34 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$cmdadd" ]; then
|
|
|
|
cmdline="$cmdline $cmdadd"
|
|
|
|
fi
|
2017-07-13 04:33:49 +00:00
|
|
|
adjusted_cmd_line="y"
|
2017-04-29 17:40:34 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 20:11:59 +00:00
|
|
|
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ];then
|
|
|
|
#If expecting debug output, have kexec load (-l) output debug info
|
|
|
|
kexeccmd="$kexeccmd -d"
|
|
|
|
fi
|
|
|
|
|
2017-07-12 04:17:45 +00:00
|
|
|
module_number="1"
|
2017-04-29 17:40:34 +00:00
|
|
|
while read line
|
|
|
|
do
|
|
|
|
key=`echo $line | cut -d\ -f1`
|
|
|
|
firstval=`echo $line | cut -d\ -f2`
|
|
|
|
restval=`echo $line | cut -d\ -f3-`
|
|
|
|
if [ "$key" = "kernel" ]; then
|
2018-03-10 23:40:07 +00:00
|
|
|
fix_file_path
|
2017-07-04 23:49:14 +00:00
|
|
|
if [ "$kexectype" = "xen" ]; then
|
2018-03-10 23:40:07 +00:00
|
|
|
# always use xen with custom arguments
|
|
|
|
kexeccmd="$kexeccmd -l $filepath"
|
2019-03-17 23:33:55 +00:00
|
|
|
kexeccmd="$kexeccmd --command-line \"$restval no-real-mode reboot=no vga=current\""
|
2017-07-04 23:49:14 +00:00
|
|
|
elif [ "$kexectype" = "multiboot" ]; then
|
|
|
|
kexeccmd="$kexeccmd -l $filepath"
|
|
|
|
kexeccmd="$kexeccmd --command-line \"$restval\""
|
2023-04-17 20:11:59 +00:00
|
|
|
elif [ "$kexectype" = "elf" ]; then
|
|
|
|
DEBUG "kexectype= $kexectype"
|
|
|
|
DEBUG "restval= $restval"
|
|
|
|
DEBUG "filepath= $filepath"
|
|
|
|
kexeccmd="$kexeccmd -l $filepath"
|
|
|
|
DEBUG "kexeccmd= $kexeccmd"
|
2017-07-02 18:27:02 +00:00
|
|
|
else
|
2023-04-17 20:11:59 +00:00
|
|
|
DEBUG "unknown kexectype!!!!"
|
2017-07-02 18:27:02 +00:00
|
|
|
kexeccmd="$kexeccmd -l $filepath"
|
2017-04-29 17:40:34 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ "$key" = "module" ]; then
|
|
|
|
fix_file_path
|
2017-07-02 18:27:02 +00:00
|
|
|
cmdline="$restval"
|
2017-07-12 04:17:45 +00:00
|
|
|
if [ "$kexectype" = "xen" ]; then
|
|
|
|
if [ "$module_number" -eq 1 ]; then
|
|
|
|
adjust_cmd_line
|
|
|
|
elif [ "$module_number" -eq 2 ]; then
|
|
|
|
if [ "$printinitrd" = "y" ]; then
|
|
|
|
# output the current path to initrd
|
|
|
|
echo $filepath
|
|
|
|
fi
|
|
|
|
if [ -n "$override_initrd" ]; then
|
|
|
|
filepath="$override_initrd"
|
|
|
|
fi
|
|
|
|
fi
|
2017-07-02 18:27:02 +00:00
|
|
|
fi
|
2017-07-12 04:17:45 +00:00
|
|
|
module_number=`expr $module_number + 1`
|
2017-07-02 18:27:02 +00:00
|
|
|
kexeccmd="$kexeccmd --module \"$filepath $cmdline\""
|
2017-04-29 17:40:34 +00:00
|
|
|
fi
|
|
|
|
if [ "$key" = "initrd" ]; then
|
|
|
|
fix_file_path
|
2017-07-12 04:17:45 +00:00
|
|
|
if [ "$printinitrd" = "y" ]; then
|
|
|
|
# output the current path to initrd
|
|
|
|
echo $filepath
|
|
|
|
fi
|
|
|
|
if [ -n "$override_initrd" ]; then
|
|
|
|
filepath="$override_initrd"
|
|
|
|
fi
|
2022-01-07 19:30:57 +00:00
|
|
|
firmware_initrd="$(inject_firmware.sh "$filepath" || true)"
|
|
|
|
if [ -n "$firmware_initrd" ]; then
|
|
|
|
filepath="$firmware_initrd"
|
|
|
|
fi
|
2017-04-29 17:40:34 +00:00
|
|
|
kexeccmd="$kexeccmd --initrd=$filepath"
|
|
|
|
fi
|
|
|
|
if [ "$key" = "append" ]; then
|
|
|
|
cmdline="$firstval $restval"
|
|
|
|
adjust_cmd_line
|
|
|
|
kexeccmd="$kexeccmd --append=\"$cmdline\""
|
|
|
|
fi
|
|
|
|
done << EOF
|
|
|
|
$kexecparams
|
|
|
|
EOF
|
|
|
|
|
2017-07-13 04:33:49 +00:00
|
|
|
if [ "$adjusted_cmd_line" = "n" ]; then
|
|
|
|
if [ "$kexectype" = "elf" ]; then
|
|
|
|
kexeccmd="$kexeccmd --append=\"$cmdadd\""
|
|
|
|
else
|
|
|
|
die "Failed to add required kernel commands: $cmdadd"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
if [ "$dryrun" = "y" ]; then exit 0; fi
|
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
echo "Loading the new kernel:"
|
|
|
|
echo "$kexeccmd"
|
|
|
|
eval "$kexeccmd" \
|
|
|
|
|| die "Failed to load the new kernel"
|
|
|
|
|
2023-02-27 21:42:01 +00:00
|
|
|
if [ "$CONFIG_TPM" = "y" ]; then
|
|
|
|
tpmr kexec_finalize
|
2022-08-25 18:43:31 +00:00
|
|
|
fi
|
|
|
|
|
2023-06-20 16:40:00 +00:00
|
|
|
if [ -x /bin/io386 -a "$CONFIG_FINALIZE_PLATFORM_LOCKING_PRESKYLAKE" = "y" ]; then
|
2023-04-12 19:04:05 +00:00
|
|
|
lock_chip
|
|
|
|
fi
|
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
echo "Starting the new kernel"
|
|
|
|
exec kexec -e
|