Skip to content

Instantly share code, notes, and snippets.

@BHSPitMonkey
Created February 27, 2016 05:51
Show Gist options
  • Save BHSPitMonkey/1672c2dc9c36d6020419 to your computer and use it in GitHub Desktop.
Save BHSPitMonkey/1672c2dc9c36d6020419 to your computer and use it in GitHub Desktop.
Graphical reboot-into-OS chooser for GRUB2
#!/bin/bash
#
# Show a list of GRUB2 menu entries, and reboot into the chosen one.
#
# Your /etc/default/grub MUST have GRUB_DEFAULT set to "saved".
# If you make this change, run update-grub as root to apply it.
# To learn more, read: https://wiki.debian.org/GrubReboot
#
# Requirements:
# * zenity
# * grub2
# Build list of menu entries into zenity command
cmd='zenity --list --title="Reboot into specific OS" --column="Menu Entry" --width=400 --height=400'
while read e
do
echo "Adding $e"
cmd="$cmd \"$e\""
done <<< "$(grep -oP "^menuentry '[A-Za-z0-9()/ \-\.+,]+'" /boot/grub/grub.cfg | cut -c 12- | rev | cut -c 2- | rev)"
# Display list prompt using zenity
choice=$(eval "$cmd")
# Reboot into selection
if [ -n "$choice" ] # Check if there actually is a selection
then
gksudo grub-reboot "$choice" && reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment