GRUB on USB

Hi
I was wondering if there is any way to install GRUB on a memory stick, when installing openSuSE 11.0.
I usually install GRUB into the MBR Sector but everytime I wanted to reinstall Windows or SuSE I had to repair the MBR.
On SuSE 11.0 I tried to install GRUB into the root partition and into the boot partition but it didn’t work.
I tried to install it with my stick plugged in. I was able to see the stick into the partition list but I couldn’t select it as the default location for GRUB installation.
Windows started normaly after the 1st restart as if GRUB wasn’t installed.
What I want is to install GRUB on my USB stick so that I could just un-plug it when I want to boot into Windows and insert it when I want to boot into SuSE.
This is my 1st post so please go easy on me.

There may be some helpful reading here
Installing SuSE on External USB Drive - openSUSE

So your bios supports booting from the USB device, either reconfigured in setup/save to cmos, and possibly through an on-the-fly boot menu?

Yes it does. I bought the system this summer.
I have Asus Striker II Formula with the latest BIOS(made an update after I got it).

So if I understood correctly, you can get into openSUSE . . . open a terminal, switch to root, do the following and post back here:

cat /boot/grub/device.map
cat /boot/grub/menu.lst
cat /etc/grub.conf
cat /etc/fstab
fdisk -lu

No. I said my bios supports booting from the USB device, not that I can get into openSUSE. I don’t have openSUSE install right now. I want to find a way to install openSUSE and put GRUB on an external device(USB memory stick) because I don’t want to re-write the HDD MBR.
Is it possible to do it with a live cd like knoppix or openSUSE live CD?

It’s certainly possible as long as the USB device is seen and bootable by the bios and can be installed to, but can be a bit tricky. I’ll try to explain in detail; since this is not familiar, don’t hesitate to ask for any clarification or elaboration.

The easiest approach usually is to connect the USB but disconnect the internal disk drive and then boot the installation media. Is this possible for you to do? Generally speaking the DVD is better, but the LiveCD will probably work, too.

Here is the key: When both the internal disk and the USB are connected, any OS installation (incl Windows) will see both, will see the USB as the second storage device, and will see the internal disk as the boot device (this is the fundamental reason you had the difficulty you did before). So the OS installation on the USB must be forced to boot from the MBR on that device, plus the boot loader must be configured to think it is the first boot device (which it will be when you do the bios switch) plus the partition mounting must be configured to use a unique identifier of the USB device rather than the bios’s device sequencing. There is often an additional complication caused by what the bios puts in the hardware map it creates; there is no standard for this and this can result in the boot loader being confused.

Now, getting the boot loader re-installed and the OS configured as needed can be done after a normal installation, but that is what I referred to above as being a bit tricky; sometimes it’s a matter of trial-and-error. So what is easiest - and safest - is to just install to the USB after having taken the internal disk out of the equation (just pull the power plug). This is the recommended Step 1.

Step 2 is optional but significantly adds to the chance of success, so this is strongly advised. This involves two tasks, manually controlling how the partitioning and boot loader installation are done rather than taking the installer’s default recommendations. At the partitioning step, you must be sure that the root partition is on a “primary” partition (as opposed to a “logical” partition inside of an “extended primary”). The installer may recommend this already, so you may not have to do anything more here. But if it does not, you need to enter that dialog and specify it yourself (if it comes to that, we can provide detailed instructions).

Next, at the Boot Loader installation step, click on the section title to enter the gui setup dialog. Click on the Boot Loader Installation tab; the screen will change and you will see a column of choices under Boot Loader Location. Most likely “Boot from Master Boot Record” will be checked; uncheck it! Instead, check “Boot from Root Partition”. Then click on the Boot Loader Options button; again a new screen. In the upper-left there is a list. Check “Write generic boot code to MBR” and also “Set active flag in Partition Table for Boot Partition”. Click OK, click Finish. Back on the summary screen, confirm your selections.

Finish the installation, switch the bios to USB boot, and test that. If working as expected, then reconnect the internal drive and again boot from the USB to verify it still boots and mounts as expected. Since nothing was changed affecting the internal drive, switching the bios back to boot from it should work as before. If the USB drive has some problem booting or mounting once the internal is reconnected, we can use the LiveCD to tweak the configuration to solve that. But there is a very good chance everything will work. If you want the internal drive accessible from the USB, you may need another few easy steps to set that up.

Again, anything not absolutely clear, please ask.

Nice write up mingus.
Hey, why not add this as appropriate to: Installing SuSE on External USB Drive - openSUSE

Just an idea friend.

Thanks. I’ll consider doing that once this thread is closed out.

Interesting. But doesn’t this mean It will install the entire OS on the external drive?
Indeed, GRUB will be installed on the external drive,into the root partition, not into the MBR.But the OS will also be installed on the external drive since there is no internal drive connected.

Whoa! I’m sorry - and trying to wipe the egg from my face. :shame:

I misunderstood your question. I took it to mean that you wanted to install the OS on the USB device. You actually only want to put the boot loader on that device, and to plug/un-plug it to toggle between the OS’s.

Obviously, disregard my previous. I’ll churn on the right question this time and get back to you.

Looking back at your original post, occurs to me that it might be better to get grub installed on a hard disk which permits the flexibility of doing reinstalls, etc. without inducing a grub problem. That is definitely doable. On the other hand, you asked for how to control the boot from a USB stick, and it is possible that other users may need to do something similar, so that’s the objective below.

Test case: Simple 1 disk setup, with Windows C on sda1 and openSUSE root on sda5. Grub is installed to the MBR. (The steps are essentially the same were there more disks, only the numbering would change throughout.) In openSUSE the grub installation disk alignment file - /boot/grub/device.map - is thus:

(hd0) /dev/sda

And in the grub boot control file - /boot/grub/menu.lst - there is a boot stanza like this:

root (hd0,4)
kernel /boot/vmlinuz . . . . 
initrd /boot/initrd  . . . .

In most cases the bios handles USB boot devices differently, preventing grub stage1 in the USB’s MBR from seeing the disks. Therefore, grub’s stage2 and the associated files must be put on the stick as well; this stage2 loader will be able to find the hard disk.

Step 1: Install grub to openSUSE root partition boot sector. Open terminal, switch to root, and (using above as example; change numbering as required):

grub
setup (hd0,4) (hd0,4)
quit

Step 2: Prep USB stick, install and configure grub on it. Boot into openSUSE. Insert stick; mounts automatically. Check device-name; in this example it is /dev/sdb, grub’s (hd1). Check there is a (FAT) filesystem on it; if necessary, reformat (must be dismounted first). Add new device to /boot/grub/device.map; so using above example, it is now:

(hd0) /dev/sda
(hd1) /dev/sdb

Copy contents of /boot/grub to USB stick. It will have one partition, and boot directory structure must be the same. In this example, it is mounted to /media. Now do the copy and grub install, in the terminal as root:

mkdirhier /media/boot/grub
cd /boot/grub
cp * /media/boot/grub

grub
setup (hd1) (hd1,0)
quit

Now use a text editor to modify the menu.lst on the stick to chainload to the sda5 boot sector. So press Alt-F2 and do:

kdesu kwrite /media/boot/grub/menu.lst

(In Gnome, use “gnomesu” instead.) Using this example (again change the grub numbering as required), you would edit the menu.lst file to this:

default 0
timeout 0

title USB chainload to openSUSE on sda5
rootnoverify (hd1,4)
chainloader (hd1,4)+1

Note that (hd0) has been changed to (hd1) because sda will be second, not first, in the bios sequence when booting from the stick.

Step 3: Modify openSUSE menu.lst for USB-stick boot. Because sda will now be (hd1), the openSUSE menu.lst must also change. Press Alt-F2, and do:

kdesu kwrite /boot/grub/menu.lst

And edit the boot stanza (compare with original above), also change the Windows boot stanza:

title openSUSE . . .
root (hd**1**,4)
kernel /boot/vmlinuz . . . . 
initrd /boot/initrd  . . . .

title Windows . . .
rootnoverify (hd1,0)
map (hd1) (hd0)
map (hd0) (hd1)
chainloader (hd1,0)+1

Step 4: Change bios boot order. Enter bios setup, and set boot disk order to boot from USB first, hard disk second; save and reboot with stick inserted.

Step 5: Reinstall Windows master boot code. Grub in the sda (in this example) MBR now needs to be replaced with Windows boot code. Boot from stick, from openSUSE menu select Windows, Windows boots; use free utility such as FixMbr to install Windows boot code to hard disk MBR. If you have the XP CD, you can boot from it into the Recovery Console to do this. Remove stick, reboot, test that Windows boots.

That’s it. Bios will boot from USB stick when it has been inserted, otherwise it will boot from hard disk.

Thanking to you I must,Wise Penguin. I’ll give it a try this weekend and I’ll post back here. Once again, thanks.

Sure, happy to help. Don’t be surprised if you run into some problem - as I posted above, your machine may have something a bit different, and this is all new to you, too. So be patient with yourself, and if you have any question, please do ask.

@daydr3am3r -

I just discovered an ugly little annoyance. In the above, we set the bios boot sequence as USB, then internal. If the USB is not found, the bios moves to the next choice, the internal. This is of course how it works with other devices, e.g., if the bios has floppy-cdrom-disk1 configured and nothing is in the floppy or CD drives, disk1 boots. Or if it is disk1-disk2-disk3, and disk1 and disk2 have no MBR, then disk3 boots. But . . .

Unfortunately, it appears that some bios’s do not follow this rule if the device is USB. (You may recall that at the front I said that bios’s handled USB boot differently, and there is no standard - well, this is an example of such.) I tested the approach above on 2 machines. On the first, worked exactly as expected. On the second, with the USB removed the bios hung; it did not move to the next boot device, i.e., the hard disk - it just stopped. Therefore, I cannot predict what your machine will do. Worst case, you would have to switch the bios boot setting.

Thanks for the info & sorry for the late reply. I didn’t have enouugh time to install openSuSE but I checked what you said and it seams everything is OK. If there is no USB device inserted it skips to the next boot device.