Remotely switching OS with rEFInd

I'm a strong independent woman who don't need no IPMI

I’ve recently been doing lots of switching between Linux (i run arch btw) and Windows on my home PC. However, I also do a lot of things remotely. This is fine when you’ve got a pure Linux box, but dual-booting on consumer hardware leaves much to be desired.

GRUB allows you to specify which boot option to select as default on your next boot (and only the next boot), which back-in-the-day I used to use to, in a slightly convoluted manner, reboot to Windows after defaulting to my Linux install. But I now use rEFInd as my bootloader, partly for the UEFI support, partly for the eye candy for the occassions that I am at my desk (or if someone else needs to use my PC, it’s much easier to get them to select the big Windows icon than scan through a list of boot options in the five second window they have before the default boots). rEFInd unfortunately doesn’t have this “next boot only” option.

I’ve recently come across an invaluable little github gist that gives a pair of scripts that will set the “PreviousBoot” EFI variable which rEFInd uses as the default boot option. So it’s simply a case of running these to reboot to the OS of your choice!

As the post suggests, the most difficult bit of this is to compile the C++ script on Windows.

I’ve also written a short powershell script to get the EFI variable change and the subsequent reboot into a single call:

1Write-Host "Setting refind parameters..."
2$Command = "C:\Scripts\refind-next-boot.exe"
3$Params = "`"linux`""
4& $Command $Params
5Write-Host "Done."
7Write-Host "Rebooting to Linux..."
8& shutdown -t 0 -r

Note the (frankly bizarre) way in which I needed to escape the quotes in the parameters being passed to the executable.

At some point in the future I hope this will become obsolete when I can totally virtualise my Windows install, but for now this is great.