Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlueDrink9/b30ede93396c23a50cc563eaf18fb5bc to your computer and use it in GitHub Desktop.
Save BlueDrink9/b30ede93396c23a50cc563eaf18fb5bc to your computer and use it in GitHub Desktop.
Always reboot to Windows instead of Linux during a Windows update (systemd-boot)

Motivation

Say you dual boot Windows and Linux, and use the simple and light-weight systemd-boot to switch OS. Say you boot to Linux by default. However, this causes headaches when Windows updates and needs to restart as part of the process, especially if it has to do so multiple times (for example major feature updates).

You could change the default right before you boot

Automatically set Windows as next boot when restarting as part of an Update

Create a script %windir%\System32\update\run\precommit.cmd with the following contents:

powershell.exe "C:\Scripts\set-windows-next-reboot.ps1"

This precommit.cmd script will be run by Windows prior to the feature update being applied and the system rebooting..

Install the powershell module uefi2. Create the second script, "C:\Scripts\set-windows-next-reboot.ps1" with the following contents:

Import-Module UEFIv2 -ErrorAction Stop
$guid="{4a67b082-0a4c-41cf-b6c7-440b29bb8c4f}"  # namespace for LoaderEntryDefault, LoaderEntryOneShot
# Bytes spell out the value "a u t o - w i n d o w s".
[byte[]] $bytes = 97,0,117,0,116,0,111,0,45,0,119,0,105,0,110,0,100,0,111,0,119,0,115,0,0,0
Set-UEFIVariable -namespace $guid -VariableName "LoaderEntryOneShot" -ByteArray $bytes
# Set-UEFIVariable -namespace $guid -VariableName "LoaderEntryOneShot" -Value "a u t o - w i n d o w s"

This sets a UEFI variable, LoaderEntryOneShot, that tells systemd-boot to boot Windows on the next update.

Side effects and limitations

This method does not check whether the update in question requires a restart, but will set the next boot to Windows regardless. The Microsoft documentation is unclear whether the script runs only on updates with restarts, nor whether it runs for each restart within an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment