Skip to content

Instantly share code, notes, and snippets.

@chocolatkey
Created June 2, 2017 23:07
Show Gist options
  • Save chocolatkey/4c8df70f03c2907435c06d7e8f431a11 to your computer and use it in GitHub Desktop.
Save chocolatkey/4c8df70f03c2907435c06d7e8f431a11 to your computer and use it in GitHub Desktop.
Change Grub2 default menu entry
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
echo "=================================="
echo "Grub2 selected menu entry changer"
echo "=================================="
cenvraw=$(grub2-editenv list)
cenv=${cenvraw#*=}
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
echo "Please choose one of the entries above [$cenv]: "
read nenv
if [[ -z "$nenv" ]]; then
printf '%s\n' "No new entry chosen!"
exit 1
else
grub2-set-default $nenv
echo "grub2 default entry now \"$nenv\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment