2017-04-29 17:40:34 +00:00
|
|
|
#!/bin/sh
|
2017-07-12 04:17:45 +00:00
|
|
|
# Launches kexec from saved configuration entries
|
|
|
|
set -e -o pipefail
|
2017-04-29 17:40:34 +00:00
|
|
|
. /etc/functions
|
|
|
|
|
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-03 03:01:04 +00:00
|
|
|
# TODO: make this configurable
|
|
|
|
cmdadd="intel_iommu=on $cmdadd"
|
|
|
|
cmdremove="quiet $cmdremove"
|
|
|
|
|
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
|
|
|
|
cmdline="${cmdline//$i/}"
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
2017-07-04 23:49:14 +00:00
|
|
|
if [ "$kexectype" = "xen" ]; then
|
2017-07-02 18:27:02 +00:00
|
|
|
# always overload xen and with custom arguments
|
|
|
|
kexeccmd="$kexeccmd -l /bin/xen.gz"
|
2017-07-18 17:31:08 +00:00
|
|
|
kexeccmd="$kexeccmd --command-line \"no-real-mode reboot=no vga=current\""
|
2017-07-04 23:49:14 +00:00
|
|
|
elif [ "$kexectype" = "multiboot" ]; then
|
|
|
|
fix_file_path
|
|
|
|
kexeccmd="$kexeccmd -l $filepath"
|
|
|
|
kexeccmd="$kexeccmd --command-line \"$restval\""
|
2017-07-02 18:27:02 +00:00
|
|
|
else
|
2017-07-04 23:49:14 +00:00
|
|
|
fix_file_path
|
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
|
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"
|
|
|
|
|
|
|
|
echo "Starting the new kernel"
|
|
|
|
exec kexec -e
|