Skip to content

Instantly share code, notes, and snippets.

@schuerg
Created January 27, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schuerg/e095b42d397f3bc9e1136ca91a9057a4 to your computer and use it in GitHub Desktop.
Save schuerg/e095b42d397f3bc9e1136ca91a9057a4 to your computer and use it in GitHub Desktop.
[Reboot to specific OS] Reboot the machine to a specific boot target (Grub entry) #linux #bash #grub #interactive
#!/usr/bin/env bash
# Reboot the machine to a specific boot target (Grub entry).
# The boot target is interactivly selected with fzf.
#
# Simon Schürg
# Search for grub.cfg
GRUB_CFG=$(find /boot -name grub.cfg 2> /dev/null)
if [[ -z ${GRUB_CFG} ]]; then
echo "No grub.cfg found under /boot. Try as root."
exit 1
elif [[ ! -r ${GRUB_CFG} ]]; then
echo "${GRUB_CFG} is not readable. Try as root."
exit 1
fi
GRUB_MENUENTRY=$(awk -F\' '/menuentry / {print $2}' ${GRUB_CFG} | fzf)
# Set boot target for next boot
grub2-reboot "${GRUB_MENUENTRY}"
# Seconds to sleep before reboot
SLEEP=5
echo -ne "Rebooting to ${GRUB_MENUENTRY} in ${SLEEP} seconds "
for i in $(seq 1 ${SLEEP}); do
echo -ne "."
sleep 1
done
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment