booting ubuntu with usb-memory stick

Asked by PJ. DE VUYST

I installed Ubuntu 10.10 on a usb-memory stick (as recommended during the installation).
Booting sequence runs fine, but i forgot today to introduce the stick in the computer and only got the message that the usb device is not recognized followed by 'grub rescue' with the command prompt. What command is available in order to force booting from Windows 7 (and not losing the whole computer should the usb-stick really fail in the future (instead of not being introduced)).

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu grub2 Edit question
Assignee:
No assignee Edit question
Solved by:
Ubfan
Solved:
Last query:
Last reply:
Revision history for this message
Ubfan (ubfan1) said :
#1

Looks like you replaced the Windows master boot block with grub, and put the grub files on the usb stick. If your pc can boot off usb (check your bios boot settings to see if usb is an available boot choice), you can install grub to the usb stick. To fix your hard disk, you can either restore the MBR using your Windows install media (not the vendor recovery disks if that's all you have), or install the grub files somewhere visible on the hard disk -- unfortunately the NTFS filesystem is not a visible place for the grub files, so you need a FAT recovery partition or FAT tools partition. The grub files are not that large and will fit on these small partitions. In the FAT partition you choose, make a directory named boot, and install grub to that partition. Of course, you can do all this from the CD install media too, so don't worry about being stuck if the usb stick goes bad.

Revision history for this message
PJ. DE VUYST (pierre-de-vuyst) said :
#2

I was afraid of a too long explanation. What happened is as follows: i have a desktop with Windows7 pre-installed. At the moment of installation of Ubuntu (from cd), an usb-stick (with pictures) remained plugged in by inadvertence. During the installation proces, Ubuntu proposed the choice between erasing the whole HD (I suppose due to an excessive number of primary partitions used by Windows7) and..installing Ubuntu on the by chance detected usb-stick. The first option being excluded, i re-started the installation procedure with another (larger and empty) usb-stick. The whole installation succeeded and i can boot Windows or Ubuntu from the grub. At one condition: the usb-stick must be plugged in, otherwise the grub does not appear at all, leaving only a message that the (usb) device was not found, followed by "grub rescue>(command prompt)". I'm not a specialist in command prompts and did not know what to do. Naturally, the solution is to have the usb-stick permanently plugged in, even if i only want to start the computer on Windows. But what will happen if the usb-stick becomes corrupted in the future? In that case the computer start-up ends with an nearly empty screen and the command prompt. How can i then force the computer in the Windows-Mode? It is somewhat strange (for me) that a boot manager (i.e. the grub) fails to appear if one of the possible boot devices is not present, giving no opportunity to boot with another device. The grub is certainly located in the Windows boot sector: when using the bios boot menu and choosing the HD-drive, the grub appears (with the same inconvenience if the usb-stick is not plugged in, this makes this method also useless).
Is there any line command (at the above mentioned command prompt) that permits the resurrection of the grub on the screen?

Revision history for this message
Best Ubfan (ubfan1) said :
#3

Sorry I wasn't clearer. I understood what you did, having done it myself. I know of no quick fix. You have replaced the Windows boot loader with a partial grub boot loader, with the other part of grub being on the usb stick. You would like the windows pc to boot windows when the usb stick is not present -- to do this you need to fix the boot loader. There are two ways to fix the bootloader:
1) Use the windows install media to run a recovery console and at the command line, run fixmbr (maybe fixboot too).
2)Fix the grub install on the hard disk -- grub needs a directory of files to complete its boot. grub can read these files it needs off of a FAT filesystem, but not an NTFS filesystem. IF your windows disk includes some small FAT partitions for recovery or tools, you may put the grub files there. If your windows disk does not have any FAT partitions, you are probably better off borrowing the windows install media to fix the bootloader.

From the Ubuntu system, start a terminal Crtl-Alt-t
type the following command to list your partitions on the hard disk (and usb) (the -l is a small L):
sudo fdisk -l

the hard disk will probably be sda, so your windows partitions will be sda1, sda2, etc. Are any of them of type FAT (at the end of the line)? If any are, you may use option 2, if not, you only have option 1.

What to do if you have a FAT partition:
From Windows, on the FAT partition (probably called D:) make a directory named "boot".
Reboot to Ubuntu, and install grub to the windows disk using the FAT partition (sda2 or whatever yours is).
sudo mkdir /mnt/tmp
sudo mount -tvfat /mnt/tmp /dev/sda2
sudo grub-install --root-directory=/mnt/tmp /dev/sda

That should fix the windows boot without the usb stick, but will leave you with the ubuntu option which of course will not boot without the stick. You may manually edit the d:\boot\grub\grub.cfg file to remove the ubuntu section if you want.

Before you fix with option 1, you should reinstall grub onto the usb stick boot block so you can still boot Ubuntu with the stick. Actually, it won't hurt to just fix it in any case.
From a terminal in Ubuntu (assuming sdb1 is your usb Ubuntu root partition):
sudo grub-install /dev/sdb1

Revision history for this message
PJ. DE VUYST (pierre-de-vuyst) said :
#4

Thanks Ubfan, that solved my question.