“Pre-choose the OS to boot, even before turning on the computer by toggling a switch. Now you don’t have to wait to select the os.
Wandering Hackaday.io for projects, I stumbled upon this project(click) by Stephen Holdaway. In this project, he solved a frustrating task faced by every dual boot user, which is sitting and waiting to choose os (Windows) from the GRUB menu any time when we want to switch to windows. He was able to add a hardware switch to determine the OS to boot each time the computer is turned on.
He achieved this by configuring STM32 Microcontroller as a USB mass-storage device. He has documented his entire journey through the research and implementation of the project in hackaday post(click). Please go through his post to get a better understanding of the implementations.
In this project, I will show how I managed to port the changes to Raspberry Pi Pico. You can find my version in this GitHub Repo (Click).
GNU GRUB is a program that runs before any Operating Systems are loaded. Through this menu, we can select which OS to load. GRUB offers very limited modules to work with. This means it cannot read data from a microcontroller connected via USB. But it can read data from storage disks.
So we can trick GRUB to read data from the microcontroller, by enumerating our micro as a mass-storage device.
Hence we enumerate our raspberry pi pico as a mass-storage device, via tinyUSB library, which will be having a file switch.cfg file, to which pico will write the switch position i.e 1 for ON 0 for OFF.
We have to add a script in GRUB, that’s functions to read switch.cfg file and set the default to 0(Ubuntu )/2(Windows).
GRUB when loads, runs our custom scripts, which in turn searches for our device by its UUID identifiers, and if exits read the switch.cfg file. After getting the switch position it sets the default os selection respectively.
pico will configure itself as a mass-storage device.
grub menu calls our script and asks for the particular file.
Pico responds to the read request by adding the switch position in the switch.cfg file.
the script in grub extracts the info from the file and sets the default option from the extracted data.”