LINUX AND WINDOWS HARDWARE BOOT SELECTION SWITCH

Summary of LINUX AND WINDOWS HARDWARE BOOT SELECTION SWITCH


Stephen Holdaway built a physical OS-selection switch labeled Linux and Windows that tells the PC which OS to boot by presenting a USB mass-storage device containing a dynamic file indicating the switch position. An STM32 microcontroller emulates a USB storage device and serves a file the BIOS/GRUB reads at boot, avoiding GRUB timeout juggling. The implementation requires presenting the USB mass-storage class descriptor and implementing a storage protocol (e.g., SCSI or ATA) so the firmware can interrogate and read the file.

Parts used in the OS selection switch:

  • STM32 microcontroller
  • USB connector/cable
  • Physical two-position switch labeled Linux and Windows
  • PCB or prototyping board to mount components
  • Power supply (from USB)
  • Optional enclosure to house switch and electronics

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:

LINUX AND WINDOWS HARDWARE BOOT SELECTION SWITCH

“ 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.

REad more: LINUX AND WINDOWS HARDWARE BOOT SELECTION SWITCH

Quick Solutions to Questions related to the OS selection switch:

  • How does the switch tell the PC which OS to boot?
    The STM32 emulates a USB mass-storage device that serves a file whose contents indicate the switch position, which the BIOS/GRUB reads at boot.
  • Can this be done without modifying GRUB?
    Yes. The device leverages the BIOS/GRUB ability to read attached storage, so no GRUB modification is required.
  • What role does the STM32 microcontroller play?
    It acts as a USB mass-storage device and serves the dynamic file representing the switch position.
  • Does the device need a custom USB interface?
    No. The project presents itself as standard USB storage rather than requiring a custom interface.
  • What storage protocols must be supported?
    The mass-storage class descriptor must indicate one of several storage protocols such as SCSI or ATA, and the chosen protocol must be implemented.
  • Why not just increase the GRUB timeout?
    The creator prefers to select the OS ahead of time and avoid waiting or needing to be present to change the GRUB selection.
  • Does the BIOS need special capabilities for this to work?
    No special capabilities beyond normal BIOS/GRUB access to attached storage are required.

About The Author

Muhammad Bilal

I am a 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.