Reboot to Windows Once from Linux
On a dual-boot machine, you may occasionally want to reboot into Windows from Linux for a specific task—such as using a Windows-only application—and then return to Linux afterward. While GRUB allows you to choose which OS to boot, it is more convenient to have a one-time reboot option that boots directly into Windows, then automatically returns to Linux as the default on subsequent boots. This can be accomplished using efibootmgr to set the next boot entry to Windows.
Show/Hide the code
| |
Here, <WindowsBootEntryNumber> is the boot entry number for Windows, which you can find by running efibootmgr without any arguments. The output will list all boot entries and their numbers. For example:
Show/Hide the code
| |
To set the next boot to Windows, run:
Show/Hide the code
| |
After executing this command, reboot your machine. It will boot into Windows for that session. On the next reboot, it will default back to Linux.
Creating a Shortcut Script
To streamline this process, create a simple script at /usr/local/bin/reboot2win:
Show/Hide the code
| |
Make it executable and set ownership to root for security:
Show/Hide the code
| |
Now you can run sudo reboot2win to reboot into Windows once.
Make It Even Easier with Polkit
To avoid typing sudo every time, you can create a polkit rule to allow your user to run the script without a password prompt. Create a file at /etc/polkit-1/rules.d/50-reboot2win.rules with the following content:
Show/Hide the code
| |
This rule allows users in the wheel group to execute the reboot2win script without a password prompt. Adjust the group name if your user belongs to a different group.
To apply the rule, restart the polkit service:
Show/Hide the code
| |
Now you can simply run the following command without sudo:
Show/Hide the code
| |
Finally, you can add an alias or a desktop shortcut for easier access. Also, to avoid accidentally running the command, you can use a confirmation prompt dialog such as kdialog or zenity. For example, using kdialog:
Show/Hide the code
| |
This will show a confirmation dialog before executing the reboot command.