Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 operating systems installed. But I want the operating system that boots, to be dependant on whether there is a usb flash drive inserted or not.

If a flash drive is not inserted - boot Windows 7. If a flash drive is inserted - boot Ubuntu.

Both OS are already installed on hard disk. I have some ideas about this, I understand that I could have GRUB on stick and that it should have higher boot priority (in bios) than usual harddisk mbr, but I don't have skills nor enough knowledge to make that happen.

Is that even possible?

share|improve this question
Is the ubuntu on the usb stick? – richard Sep 13 '12 at 11:17
@richard "Both OS are already installed on hard disk." – the-lay Sep 13 '12 at 11:18
OK. you can do it as you say, but consider the security risk of some one inserting a different bootable usb stick. If it is not a portable computer, then you may have sufficient physical security. – richard Sep 13 '12 at 11:22
If security is an issue, then an alternate way is to program the grub configuration on the hard-disk, to detect the usb device. Can I also ask why? (Just in-case we are leading each other up the wrong path). – richard Sep 13 '12 at 11:28
@richard security isn't an issue, I would like it to work any possible way. And thanks for suggested edit! edit: because that's home computer that my family is also using, so when I need Ubuntu all I have to do is just insert usb stick, but my family members don't need to change/press anything (I'd like to keep it the simpliest way for them). – the-lay Sep 13 '12 at 11:30
up vote 1 down vote accepted

What you want is quite easy. Boot into your Linux and connect the usb drive. Run dmesg | tail, you should see something like:

New high speed USB device attached to /dev/sdb

It may be slightly different, I am not at my computer at the moment and this is from memory. In any case, there should be a line informing you that the USB drive you connected is at /dev/sdX.

You can now install GRUB on that drive (assumming it is sdb):

$ sudo update-grub
$ sudo grub-install /dev/sdb

Finally, in your BIOS settings, set your computer to boot from a USB stick first, then HDD. Now, if the stick is present, you will see its GRUB, otherwise it will boot straight from the HDD.

share|improve this answer

Another possible solution is: 1. Create a dual boot based on Windows 7 boot manager. 2. Hide Ubuntu from boot menu (delete from DisplayOrder in {bootmgr}) 3. Create a Custom action (boot-time keyboard shortcut) for Ubuntu loader.

So when system boots normally it would go directly to Windows. If the shortcut key (say ALT-U) is pressed on start-up system will boot Ubuntu.

How to create bootstrap custom actions.

How to create dual-boot Windows 7/Ubuntu.

Some notes:

To display boot menu there must be at least two entries and timeout say 10 secs. The second entry could be a dummy entry or you could have two identical entries for Windows 7.

If there is only one entry in DisplayOrder you have to type several times the custom actions key so it is not missed during startup.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.