While there are always the syslinux or extlinux (or even LILO etc.) bootloaders for your flash drive, nothing beats the great flexibility (use almost any type of formatting) and sometimes just familiarity of having GRUB on your flash drive. That is, of course, assuming that you want to run multiple operating systems on your flash drive, but I'll just assume that's why you're here.
To start off, familiarize yourself with the 'grub shell' and its commands. It has a very limited set of commands. This is one of my biggest problems with it. I wish you could use the mount and umount commands in it, but that is for another post. What you can do in it, however, is set the root partition, search for files, install GRUB, and setup GRUB, to name a few (most).
First:
$ cd /media/disk
assuming that that's where your flash drive is mounted
$ sudo mkdir -p ./boot/grub
$ sudo cp /boot/grub/* ./boot/grub
This will setup your GRUB on your flash drive just like how it is on your computer, assuming that you are working from the partition on which you booted from or if you have a shared /boot partition.
Before entering the GRUB shell, make a file to help you locate which drive is your flash drive.
$ touch ./boot/grub/here.txt
Now enter the GRUB shell.
$ sudo grub
Find your drive...
> find /boot/grub/here.txt
(Below should appear your drive)
> root (hd1,0)
or whatever was the result of the above
> setup (hd1)
Use the first part of the above. (hd2) etc.
> exit
That's it!
While this technically completes your simplified installation of GRUB, let me take a minute to explain the output of the setup command. If you encountered an error here, this may help you troubleshoot.
A healthy message returned from setup on a flash drive formatted in FAT (as most are) will look like this:
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/fat_stage1_5" exists... yes
Running "embed /boot/grub/fat_stage1_5 (hd1)"... 18 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd1) (hd1)1+18 p (hd1,0)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.
If the LiveCD you've copied your OS for USB booting from already has a /boot/grub directory, you may want to keep what files are already in there. If so, don't copy your hard drive's menu.lst file and simply edit the one that's already there. Also, if there is a file called stage2_eltorito, you can delete it (then copy the stage2 from your HDD), keep it, or even rename stage2 and use it instead, it makes no difference in the end.
If you don't have either a stage 1 or stage 2 file, setup will fail, so that's why you need to copy stage 1 over. Also, there is a file for each partition format type, which you need to have the correct one in order for GRUB to setup correctly. In this case, that was fat_stage1_5. Stage 1.5 is just a transition from 1 to 2. 1 is very short and 2 does all the work, but as for how GRUB works beyond this, you can look up for yourself.
Of course there are plenty of other things you want to do to make your flash drive work as you want it to. To start off, you want to customize the menu.lst file that is on your flash drive. Currently it won't work at all.
If you just want it to boot the operating systems on your home computer, for example, just change all the root lines from (hd0,X) to (hd1,X), since your flash drive will become (hd0) when booted from.
If you want to boot OS's on your flash drive from GRUB - and this is the true beauty of GRUB - just search google for the normal grub menu.lst file for that specific OS and copy and paste that. Then you can delete the root entry line and change the kernel and initrd lines to give whatever location vmlinuz and initrd are actually stored.
Here's a good example.
The regular GRUB entry for Puppy Linux would be:
title Puppy Linux 4.12
root (hd0,0)
kernel /pup412/vmlinuz PMEDIA=idehd psubdir=pup412
initrd /pup412/initrd.gz
If you have Puppy stored in a folder called "puppy" in the root of your flash drive, just change it to:
title Puppy Linux 4.12
kernel /puppy/vmlinuz root=/dev/ram0 PMEDIA=usbflash
initrd /puppy/initrd.gz
I changed a few other things, but even if you hadn't, it most likely would have worked well enough. Always check for specific USB configurations in OS documentation.
Now you have a working dual-purpose OS-booting/file-storing amazing chimera of a flash drive; all without formatting or partitioning it, I may add.
(By the way, I chose Puppy Linux because it can easily be stored in a folder and booted from there. Most operating systems are not this convenient, so my next post will mostly address this problem.)
0 comments:
Subscribe to:
Post Comments (Atom)
Post a Comment