Search:  
Gentoo Wiki

HOWTO_Install_grub_on_a_usb_pendrive


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Required packages

grub dosfstools e2fstools

Step 1: Emerge Grub

Install Grub by running

# emerge grub

Step 3(optional): Partition you USB pendrive

This optional step allows you to use a large pendrive as a windows compatible data storage device as well as your boot device, because windows will only acknowledge the first partition on a usb drive we will create this partition first, and make it the total size of the drive minus about 30 megabytes for the grub partition. So work out the size of the partition from the drive size in magebytes minus 30.

First backup any data your currently have on your pendrive (if necessary):

mkdir /mnt/pendrive /pendrive
mount /dev/sdx (replace with your pendrive device) /mnt/pendrive
cp -rf /mnt/pendrive/* /pendrive
umount /dev/sdx

Now we can edit the partition table:

fdisk /dev/sdx (replace with your pendrive device)
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
 e   extended
 p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3876): (Hit Enter)
Last cylinder or +size or +sizeM or +sizeK (1-3876):  (take the size worked out above prepend + and append M) e.g +990M (for a 1GB (1024MB) stick)
Command (m for help): n
Command action
 e   extended
 p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (3556-3876): (Hit Enter)
Last cylinder or +size or +sizeM or +sizeK (3557-3876): (Hit Enter)
Command (m for help): w

Now we need to format the partition we just made: N.B you will need to emerge the dosfstools and e2fsprogs packages if you haven't already.

mkdosfs -F32 /dev/sdx1
mke2fs /dev/sdx2

And restore your backed up data (if any):

mount /dev/sdx1 /mnt/pendrive
cp -rf /pendrive/* /mnt/pendrive
umount /dev/sdx1

Now your drive is ready to have grub installed on it.

Alternative Step 3: Use your pendrive just for booting

If you have a small pendrive you wish to devote entirely to the process and not use it for anything else simply run:

mke2fs /dev/sdx1

N.B you will lose all the data on the drive.

Step 4: Install grub onto the pendrive

Thankfully there is a grub-install script to make this easy:

mount /dev/sdx2 /mnt/pendrive
grub-install --no-floppy --root-directory=/mnt/pendrive/ /dev/sdx

Step 5: Configure grub

Now you need to create a grub.conf file to be edited:

cd /mnt/pendrive/boot/grub
touch grub.conf
ln -sf grub.conf menu.lst

And that's it. Just configure your grub.conf file according to your needs and you are in business.

Actually configuring the grub file is beyond the scope of this howto, please check out the Gentoo Handbook for grub configuration instructions.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Install_grub_on_a_usb_pendrive"

Last modified: Mon, 04 Feb 2008 03:56:00 +0000 Hits: 3,080