Skip to content

Instantly share code, notes, and snippets.

@isaaclw
Created November 22, 2019 16:37
Show Gist options
  • Save isaaclw/a9d0bb9f2510737c30af4196245bb8da to your computer and use it in GitHub Desktop.
Save isaaclw/a9d0bb9f2510737c30af4196245bb8da to your computer and use it in GitHub Desktop.
Reboot Grup to the specific OS you specify #grub #bash
#!/bin/bash
if ! grep "GRUB_DEFAULT=saved" /etc/default/grub > /dev/null; then
sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub
fi
echo
echo "== SELECT WHICH OS TO BOOT =="
echo
sudo cat /boot/grub/grub.cfg | grep -oE "^menuentry '[^']+'" | awk -F\" '{print N++,$(NF-1)}'
echo
read -p "Enter number (q to abort) and press ENTER: " CHOICE
if [ "$CHOICE" != "q" ] ; then
sudo grub-reboot $CHOICE
sudo shutdown -r now
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment