Created
January 27, 2019 22:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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