Simple Hardware Switch For OS Dualbooting, Thanks To RP2040

The TinyPICO board and the rocker switch soldered together showing a complete device, shown being held in the air by a crocodile clip

Dualbooting your computer can be a chore, the more switching between OSes you have to do – which is why virtualization or having separate computers are the go-to for many. Failing that, we have no choice but to smooth over our dualbooting experience with various workarounds and helpers. [William Somsky] shares one such helper tool with us – an elegant device made with a RP2040-sporting TinyPICO board and a three-way rocker switch, directing GRUB to boot into either Windows or Linux automatically, or leave us with the usual boot menu. This way, you can just flip the switch, hit “reboot” and walk away, coming back to your PC booted into OS of your choice, instead of timing your presence just so that you can catch the boot menu on time.

All you need to do is to solder a rocker switch to your RP2040 board of choice, then flash the RP2040 with code that detects the state of the switch, and creates a mass storage device hosting a file setting a Grub variable to either one of the 0, 1 or 2. [William] describes his journey, fighting mysterious caching problems, but tells us he got it working in the end. Sadly, [William] hasn’t shared the RP2040-side code with us, but he has at least put the Grub’s custom.cfg file in the ‘Files’ section of the Hackaday.io project.

Readily accessible microcontrollers with mass storage functions sure help make such hacks simple – earlier, we’ve seen dualboot switching like this done by modifying assembly code of the MBR. Dualbooting is a hacker’s rite of passage, and certain OSes of late can make it harder than other ones. Even if you don’t want to dualboot your PC, however, you sure can dualboot an Arduino!

43 thoughts on “Simple Hardware Switch For OS Dualbooting, Thanks To RP2040

  1. Seriously? 25 years ago we would have just put a switch on the hard drive power plugs, but of course, that would have required multiple drives… this solution requires its own microcontroller?

    Kids these days! And hey, get off my lawn! I’m keeping your ball!

    1. Hey now, at least offer constructive criticism!

      If they figure out a way to read arbitrary signals from GRUB, then you don’t need the microcontroller to act as a USB storage device to hold a file, just read the switch state in hardware!

      You’d need to do a bit more work to implement all three states, but two values should he enough for anyone.

      1. I thought my description of the HD power switch was reasonably/technically a ‘constructive’ comment – I described an alternative clearly enough for anyone to implement it if they like.

        To be fair, I am aware how my post came across and I made some jokes at my expense!

          1. Back in the 1990s, I built two boot select switches, one for IDE, one for SCSI. In the former case, it was a dpdt and connected to the slave jumper on each of the drives. The SCSI changed the address of two drives. In both cases, both drives were accessible.

    2. Actually I do understand what you were saying. It was metaphorical. just saying you could implement hiding the drive like you can do with several pieces of software actually and most of the time, the free software that comes with the hard drive you purchase. I personally use easeus but that’s just me. but then I remember a time when all of that was neatly packaged in a program called system commander that I doubt anybody could even find that anymore. oh and before I forget, get of my lawn too. lol lol 😆

  2. Grab an old thumb drive
    Wire a switch into a Data lines or the power line
    Plug said drive into computer
    Set grub to detect thumb drive and boot into one OS or the other
    No firmware needed.

    Also works with older memory cards, if you have a compatible reader.

    Also, you can get USB extender cables that have a type-A male on one end and type-A female on the other. That way you can run the switch up to a convenient place on your desk.

  3. I have to turn it on anyhow, so waiting ten seconds when I want to boot something other than my main OS is not such a chore. Plus, not having Windows simplifies the job.

  4. The last time I dual booted I just told the bootloader to sit there at the selection screen until I told it which one I wanted, what does it matter if it took a little longer to get booted on the occasions I stepped away.

    1. Well I guess the time I dual booting a Pi4 also counts – where each install had its own LVM partition on the same drive and boot selection was done at time of reboot by a simple script from the currently running OS that changed the config files to the desired option..

  5. Pretty cool to see a hardware switch controlling boot selection, but a more practical approach would be by using “grub-reboot “.

    It tells GRUB to reboot to another OS for one boot only, so you can type “grub-reboot Windows; reboot” and archive the same effect. I use it quite often since Windows takes so damn long to boot, so I leave it doing it’s thing while I make myself a coffee.

  6. SSD’s are pretty cheap these days (Starting around EUR30) and the method I prefer is to just use one OS per SSD, and then use the BIOS function for selecting the boot disk.

    Usually you can set a default, but also press a key to select another boot device at startup.

    This also makes it easier because you do not have to shrink partitions or even change a single bit on your first boot disk.

    Another advantage is that you do not have to mess with grub or any other bootloader.
    If you’re finished with some other OS experiment, then just pull that disk out of your PC, and then use it for backups or something.

    1. With EFI, you can have multiple OS per SSD and still use the system boot select. It works pretty well, although systems that support this are usually fast enough that you might as well wait an extra two seconds for GRUB to pop up.

      I actually keep multiple operating systems in the same BTRFS filesystem (different subvolumes). Even here, the system boot select will work as long as each OS installs its own bootloader to the EFI partition.

    1. At this point the amount of time you would have to write still gives you years and years on a drive. Harddrives can physically fail if shaken at all. Always downsides to any drive, I’ll take the speed of a SSD over the harddrive and it is easier to duplicate SSD’S if I need too.

  7. Cool idea, but far more easily, you can just set the EFI next boot variable to boot into your OS of choice, and then include that in a bash/PowerShell/batch script that sets it and initiates a reboot.
    In Linux, I believe the utility for setting the EFI boot order is `efibootmgr`, and no doubt there will be *a* way to do it in Windows as well.

    1. I was gonna say just modify grubenv or similar to tell grub what to boot next time. But this sounds even simpler – maybe not permanent though.

      A switch sounds like a solution looking for a problem. But I guess RP2040 is the new “everything gets featured” tool.

    1. It says this about an earlier and different implementation of this idea. This version only uses the RP2040, and depends only on your usage of a specifically configured GRUB bootloader.

  8. I run kvm on the bare metal, passed the GPU & usb controllers to VM’s as PCIe devices and just select the OS I want to run.
    Macos, windows, linux, android, etc

    1. This, this so much. I used to do this 20 years ago with a bootloader on a floppy disk. Without is would boot just to Windows, with floppy inserted the bootloader for Linux would take over.

      These days I just run Linux as main OS. For anything Windows related I create a KVM machine with GPU and USB pass-through and run from within Linux. Virtualization has made life so much easier.

      Nice hack though, he probably learned a lot and it solved his specific problem. Props to him.

      1. So you use 2 GPUs, 1 for Linux host, one for Win VM, or are you disconnecting 1 GPU and attaching it to the Win VM as needed? I’ve tried the latter, can’t get the GPU to detach/reset in Linux to allow the Win VM to init the card properly (GTX 1070 and Fedora, for reference)

        1. It is technically possible as I did it somehow (no idea how anymore) to switch GPU over while running, I suspect your problem is that is a nvidia card, I don’t think their drivers work for it in some way.

          From memory you have to switch to another card/ the CPU inbuilt (or perhaps SSH to run headless) as the hosts desktop session will/did I think no matter the card need closing and if you have another gpu to bring it up on you can do so. But first you have actually pass through the VM’s card or at least bind it to vfio-pci so the new desktop session won’t know of its existence as a display output.

          Its a real PITA

          So I did keep it simple and just blacklist the card myself (at least for most of the time I ran the VM) – only needed the VM for gaming while Proton was barely existing if it existed, and the main host PC never needed to do anything super graphically intensive so used a low power passive cooled card most of that computers life – did end up with an older ‘real’ GPU not that long before the Mobo died as it was starting to be useful.

          I understand the virtgl hardware accelerated virtual guest gpu (uses the hosts GPU) to be getting pretty good, but I’ve not played with with a Windoze VM with it – may not have good/sufficient/any Windoze display driver for it.

      2. I do the same now. But you’re right, actually he probably learned a great deal and I remembered those days and still have the money. They’re not quite as inspired as I used to be. I’ll bet that he had a lot of fun. I’m with you man. Props to him.

  9. Sprite_tm did something similar around 20 years ago. His computer had two power buttons; one for Linux and one for the other os. One button pulled a line on the printer port high, the other did not. Then a patched lilo booted the selected os.

  10. You can use grub-reboot [number] in Linux to tell grub to boot into any entry you want on next boot.
    I am sure there’s a rather simple way to make this work from Windows, too.

    I’d also like to mention the criminally underrated iPXE: you could simply always boot into iPXE (over the network, on the disk, or even from you NIC ROM) and use it to smartly decide what to do next.

  11. I built one of these from stuff I had laying around. I reboot my PC twice a day to go back and forth between Windows (streaming video games every evening) and Manjaro (what I use for work). Waiting around for the GRUB menu isn’t hard, but it is annoying, this little switch is awesome.

  12. As people have said, there are other ways to do this. This just happens to be the way I approached this at the current time and thought it made a nice, tight package that I wanted to show off a bit.

  13. I wonder how hard it would br to expand this idea to support a triple position switch? With 3 positions you could have one position for booting windows, one for booting a non windows O/S & the final position would be for booting from a USB based device (FlashDrive, etc).

    1. Very easy. This article describes just that, except the third position is defined to just go to the normal GRUB menu. If you wanted a four position switch (or higher) you just need to add another GPIO pin and expand the logic a little bit. also trivial.

  14. I shared a computer with my brothers back in the late 90s / early 2000s. IDE had something called cable select, so master and slave would be determined by weather the drive would be connected to the middle or the end of the IDE cable. My brother just rewirded the responsible line to a (key-) switch that you could just flip to select the master drive and therefore the OS that was booting. The other disk would then just show up as a second drive. This was not to deny acces to anything, just to conveniently have my own OS that I could mess with and potentially destroy :D

Leave a Reply to DissyCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.