Skip to content

Instantly share code, notes, and snippets.

@ebirn
Last active Nov 15, 2017
Embed
What would you like to do?
kexec latest kernel on Centos 6
#!/bin/sh
VERSION=$(ls -t1 /boot/vmlinuz-* | cut -f 1 -d '-' --complement | head -1)
BOOT=/boot
KEXEC=/sbin/kexec
KERNEL=$BOOT/vmlinuz-$VERSION
INITRD=$BOOT/initramfs-$VERSION.img
COMMANDLINE=$(cat /proc/cmdline)
echo "detected values:"
echo " Kernel: $KERNEL"
echo " initrd: $INITRD"
echo "cmdline: $COMMANDLINE"
DOIT="$KEXEC -l $KERNEL --initrd=$INITRD --command-line=\"$COMMANDLINE\""
echo "ready to run:"
while true; do
read -p "Do you wish to load kernel $VERSION for kexec? (y/n): " yn
case $yn in
[Yy] ) break;;
[Nn]* ) echo "user cancelled."; exit;;
* ) echo "Please answer yes or no.";;
esac
done
# load the new kernel for real
echo $DOIT
$( "$DOIT" )
echo ""
echo "ready for action:"
while true; do
read -p "Do you wish to exec kernel $VERSION? 'execute' or no: " yn
case $yn in
execute ) echo "executing new kernel NOW"; $KEXEC -e; break;;
* ) $KEXEC -u; echo "aborted."; break;;
esac
done
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment