2017-04-29 17:40:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
. /etc/functions
|
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
dryrun="n"
|
|
|
|
while getopts "b:e:r:a:d" 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-04 23:49:14 +00:00
|
|
|
d) dryrun="y" ;;
|
2017-04-29 17:40:34 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
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-04 23:49:14 +00:00
|
|
|
if [ "$dryrun" = "y" ]; then echo ".$firstval"; fi
|
|
|
|
|
2017-04-29 17:40:34 +00:00
|
|
|
filepath=`find $bootdir -path "*$firstval" | tail -1`
|
|
|
|
if ! [ -r $filepath ]; then
|
|
|
|
die "failed to find file $firstval"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02 18:27:02 +00:00
|
|
|
first_module=y
|
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"
|
|
|
|
kexeccmd="$kexeccmd --command-line \"no-real-mode reboot=no\""
|
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-04 23:49:14 +00:00
|
|
|
if [ -n "$first_module" ]; then
|
2017-07-02 18:27:02 +00:00
|
|
|
adjust_cmd_line
|
|
|
|
unset first_module
|
|
|
|
fi
|
|
|
|
kexeccmd="$kexeccmd --module \"$filepath $cmdline\""
|
2017-04-29 17:40:34 +00:00
|
|
|
fi
|
|
|
|
if [ "$key" = "initrd" ]; then
|
|
|
|
fix_file_path
|
|
|
|
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-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
|