[HOWTO] Install Grub to a USB drive

Here you can post about non-standard installation methods
(for example when using grub4dos).
Post Reply
User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

[HOWTO] Install Grub to a USB drive

Post#1 by Ahau » 10 Jan 2011, 20:25

Note, this HOWTO relates to Grub (legacy), not Grub2 or Grub4dos.

I found this thread useful:
http://ubuntuforums.org/showthread.php?t=1163686

I used 2 USB drives to accomplish this (all commands were used on the first drive, running Porteus, to install grub on the second drive), but this could also be accomplished from a linux OS running on a hard drive. Steps 1 and 2 are not necessary if you are installing from a linux system that already uses Grub, as these files should already be on your system.

1) Download the grub .txz package, here:
http://pkgs.org/slackware-13.1/slackwar ... 9.txz.html
I placed this file on my KDE desktop.

2) Right click on the .txz package you downloaded, and select “install”. This will install all of the necessary grub files to the system you are running, but it will not overwrite the MBR of the active drive (it will continue to boot as usual).

3) Insert the second USB drive, and mount it. I mounted mine like this:

Code: Select all

mkdir /mnt/sdc1
mount /dev/sdc1 /mnt/sdc1
Replace sdc1 with whatever partition you are installing to. In my case, sdb1 was my active Porteus USB drive (which was already mounted), and sdc1 was the target drive.

4) Create a new directory to hold grub on the target drive:

Code: Select all

mkdir /mnt/sdc1/boot/grub
5) Copy all of the files from /usr/lib/grub/i386-pc to /mnt/sdc1/boot/grub.

6) In your terminal, type ‘grub’ and hit enter. This will open a grub shell.

7) Enter the following into the grub shell:

Code: Select all

find /boot/grub/stage1
This searches all partitions on your system, and will return a list of each instance where this file was found along the path /boot/grub. In my case, two entries were returned:

Code: Select all

(hd 1,0)
(hd 2,0)
It is very important that you know which of these drives is the target drive. Note that Grub starts counting from 0, not one for both drives and partitions. In my case, I knew that hd 0,0 was my hard drive, with windows installed (it was not shown, because it does not contain the /boot/grub/stage1 file). The second drive (hd 1,0) was the USB drive running porteus, and the third drive (hd2,0) was the target drive.

8 ) enter the following:

Code: Select all

root (hd1,0)

but replace hd1,0 with the device/partition to which you want to install grub. This tells grub to look in this partition (your target partition) for the files necessary to boot. On my first install, I didn't include this, and grub would hang on boot-up, because it was looking for the files on another device.

9) enter the following:

Code: Select all

setup (hd1)
Again, replace hd1 with the device to which you want to install grub. This will overwrite the MBR of this device, so again, it is highly important that you know which device you are dealing with, or you could mess up your ability to boot your computer! Note--if you are looking to install grub to the bootsector of a partition (rather than to the MBR), enter, for example, 'setup (hd1,1) to install to the second partition of the second drive.

If you receive an error message from the setup command, try running it again, with the same parameters.

10) create a file in /mnt/sdc1/boot/grub named menu.lst (MENU.LST, not MENU.1ST)
This file will direct grub to boot your OS. Ignore this step if you already have a menu.lst file here.

11) copy (or replace) the following into menu.lst:

Code: Select all

# This is a sample menu.lst file. You should make some changes to it.
# The old install method of booting via the stage-files has been removed.
# Please install GRLDR boot strap code to MBR with the bootlace.com
# utility under DOS/Win9x or Linux.

color blue/green yellow/red white/magenta white/magenta
timeout 30
default /default

title Porteus, no changes, copy to RAM
root (hd0,0)
kernel /boot/vmlinuz copy2ram autoexec=xconf;startx
initrd /boot/initrd.xz

title Porteus w/changes
root (hd0,0)
kernel /boot/vmlinuz changes=/porteus/ autoexec=xconf;startx
initrd /boot/initrd.lz

title commandline
commandline

title floppy (fd0)
chainloader (fd0)+1
rootnoverify (fd0)

title back to dos
quit

title reboot
reboot

title halt
halt
You can make additional entries to the menu.lst to boot from other partitions, iso image files, etc. for example:

Code: Select all

title Slax remix v0.9 i486
map (hd0,0)/ISO/slax-remix-v09-i486.iso (hd33)
map --hook
chainloader (hd33)
boot
Thanks to Ponce, for helping me with the menu.lst entries!

12) I already had slax-remix installed to this drive, so /boot and /slax were already in place. If you've already upgraded to Porteus v09, you'll need to adjust your menu.lst entries to point to the appropriate directories, as their names may be different.

Now, reboot and see if you get into grub!

I’ve not yet sorted out bootsplash images, etc. I was just trying to get grub installed so that I could see how it works, in case we use it as a bootloader in v1.

Thanks, and if you see any errors in the above, feel free to let me know and I'll correct them. I'm not exactly a grub expert :D
Please take a look at our online documentation, here. Suggestions are welcome!

User avatar
fanthom
Site Admin
Site Admin
Posts: 4620
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

Re: [HOWTO] Install Grub to a USB drive

Post#2 by fanthom » 11 Jan 2011, 06:00

Moved from 'HOW TO's & Resources' to 'Installation methods' as all installation related tutorials should be placed in this separated category to be easy to find by newcomers.
Please add [Solved] to your thread title if the solution was found.

Post Reply