How to install grub on usb flash drive?

I was wondering if I could make an os-selecting-hardware-key or something like that.

I'm currently using a dual boot system (ubuntu 10.10 + win7) and i want to use an usb drive to specify the OS I want to boot. So if the usb key is plugged in during the boot, it will start one operating system, if it isn't, it will boot the other one.

I want to edit my currently installed grub to recognize only one OS, and install a second grub to the usb key, with the other OS in it. After that I just need to set up booting from the usb key in the BIOS. I may be completely wrong about it, but mainly I need some advices how to install grub(2) on the usb key.


Open a terminal, and type sudo fdisk -l (your USB flash drive should show up in the list if it is inserted). Now, type sudo grub-install /dev/<insert flash drive name here> to install it on your flash drive.

for example:

sudo grub-install /dev/cookies

Be careful with these commands (don't mess up) or you could damage your system. Make sure you are installing to the flash drive and not something else.

I'm not completely sure that this will allow you to boot your system as you wish, but if it doesn't you can edit your grub configuration on the flash drive to find your built in hard drives.