Last active
December 11, 2025 16:27
-
-
Save zargony/dd0fc80269369fb602cfe291eca8e2fe to your computer and use it in GitHub Desktop.
GRUB bootloader workaround to select OS without a keyboard
This file contains hidden or 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
| #! /bin/sh | |
| set -e | |
| # Install this script to /etc/grub.d/01_switch-default, chmod +x it and | |
| # run update-grub2. | |
| cat << EOF | |
| # Switch default boot entry when rebooting while GRUB menu is shown. This | |
| # workaround allows to select the OS without a keyboard attached (while GRUB | |
| # menu is shown: wait to boot current selection, reboot to select a different | |
| # entry) | |
| # | |
| # Use in conjunction with GRUB_DEFAULT=saved, GRUB_SAVEDEFAULT=true and | |
| # GRUB_TIMEOUT=x in /etc/default/grub. | |
| # | |
| # Info/updates: https://gist.github.com/zargony/dd0fc80269369fb602cfe291eca8e2fe | |
| # | |
| # How it works: switches the default boot entry when GRUB runs on power-up. If | |
| # the GRUB menu timeout is interrupted by rebooting, next time the new default | |
| # will be active. If the GRUB menu timeout boots the selected entry, GRUB will | |
| # save it as the default for next time. | |
| # | |
| if [ "\${default}" = "\${saved_entry}" ] ; then | |
| # Switch default entry on next boot between 0 (Ubuntu) and 4 (Windows). You | |
| # may want to adjust this to your needs. | |
| if [ "\${saved_entry}" = 0 ] ; then | |
| set saved_entry=4 | |
| #elif [ "\${saved_entry}" = 4 ] ; then | |
| # set saved_entry=5 | |
| else | |
| set saved_entry=0 | |
| fi | |
| save_env saved_entry | |
| fi | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment