Stephen Holdaway has created a switch with “Linux” and “Windows” labels, enabling you to boot into the correct OS with ease. About the reason for creating the switch, he says:

Dual-booting Linux and Windows is a great way to get the best of both worlds, but there’s one thing that’s always bothered me. To boot into Linux, I simply press the power button and walk away. To boot into Windows on the other hand requires a tactical, precision-timed strike on the keyboard to change the selection when GRUB briefly reveals itself. Now I could just increase the GRUB selection timeout, or remove it entirely, but I’d still need to wait around to make an operating system selection. I could use the mode in GRUB that remembers the last OS selection, but I’d still need to be around to change it half the time. I could make a “reboot into Windows” action in Linux, but I’m just as often booting from a powered-off state as I am rebooting from Linux. Since I always know which operating system I want ahead of time, why not make a physical switch to select between Linux and Windows?

For the project, he uses an STM32 microcontroller to act as a USB mass-storage device, which serves up a dynamic file. The file can be loaded by the system’s boot configuration to change its boot behavior based on the physical input.

Instead of him making a custom USB interface, he leverages the fact that the BIOS already enables GRUB, with access to all attached storage devices. All he did was to present the device as storage, containing a file whose contents indicate the switch position. This looks simple. However, there are a few layers to it:

  • Provide the mass-storage class descriptor, indicating one of several storage protocols to use (SCSI, ATA).
  • Implement the chosen storage protocol. This is a set of commands to interrogate the storage device’s capabilities, capacity, layout and other metadata in addition to standard requests to read and write sectors.
  • Emulate a valid filesystem when read from, without actually having any storage medium.


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top