Booting from a USB pen drive – a few technical considerations
Many Linux users want to boot from a solid state USB memory device. There seems to be various problems of booting reported. I hope the following points may help to reduce the problems or at least clarify the type of problems.
(1) The motherboard (or mobo) must have the ability to boot from a USB device first.
Most mobo do this now. Very old mobo, say more than 5 or 7 years old may not support booting from a USB device. Some not-so-old mobo may do it if the "USB legacy support" is enabled in the Bios. The booting via the USB port is generic and does not restrict to the flash drive because it applies to any external USB hard disk as well. Once the USB device booting is supported and the Bios has been instructed to boot it first then it is only a matter to install a system or a boot loader in the USB device.
The simplest way to find out if the Bios supports the booting from a USB device is to plug one in and to boot up a Live CD that you can activate a Grub prompt and then issue the geometry statement, which lists out the partition details of the specified disk, repeatedly until all the disk devices have been exhausted
Grub counts from zero so (hd0) is the 1st disk, (hd1) is the 2nd disk and so on. Depending on how Grub has been installed not every Live CD can offer a Grub prompt. Here is a list of Live CD
with which you can activate a Grub prompt.
(2) Know how the disks are ordered in the Bios
This may be the biggest hurdle for most Linux newbies. Basically when the Bios has been instructed to boot a USB flash drive first then it has to regard it as the 1st disk. The original internal hard disk will be automatically relegated in the Bios to the 2nd disk. If the USB flash drive is removed then the internal hard disk will revert back to the 1st boot disk.
Before the introduction of a bootable USB flash drive the existing operating system in the hard disk would be by default working as the 1st boot disk and most likely has been installed as such. The insertion of the USB flash drive will "rob" its 1st boot disk status. Many OSes, especially MS Windows, cannot cope with such setting change. To overcome this problem a user must do something in the boot loader instructions to "re-map" the disk order temporary when such systems are booted.
The same goes with a Linux.
As an example a MS Windows originally installed in the 1st partition of the 1st hard disk this will be known as (hd0,0) to Grub. Grub can fire up the MS system by the commands
title MS Windows in 1st partition of 1st hard disk or (hd0,0)
However if a USB is introduced then it becomes the 1st boot disk (hd0) and the same MS Windows is in the 2nd disk (hd1) and it can only be booted by commands
title MS Windows installed in 1st partition of 1st hard disk or (hd0,0) now booted as (hd1,0)
map (hd0) (hd1)
map (hd1) (hd0)
The two map statements temporarily swap the disk order at the moment Windows is booted but revert to the original order once Windows exits.
The above applies to a Linux which will equally need the (hd0) reference changed to (hd1) in the booting instruction.
(3) There are two types of booting queues in the Bios
The first is the device booting queue with which a user can impose in any booting order for the booting devices of floppy, CD, hard disk and network. The Bios will try each one in turn until it finds one that boots.
The second booting queue is which one of the internal hard disks, external hard eSata disks, external USB hard disks, USB flash/pen drives (treated as a hard disk in most BIOS), Firewire hard disks and SCSI disks will be booted first. This is the booting queue “inside” the hard disk section of the first device booting queue.
There is a small complication here and the best way to explain is a user must think like a Bios and to react as things are presented to you.
The complication is the hard disks are detected in a pre-determined fashion by the mobo. So it assigns the 1st , 2nd , 3rd and so on disk numbers according to hardware ports in a sequence shipped from the factory. As a rule internal disks are detected before external disks.
As an example a mobo may by default assign the 1st disk sda to an internal Pata disk, a 2nd disk sdb to an internal Sata disk and a 3rd disk sdc to a USB flash drive. To boot from the USB flash drive first one imposed in the second booting queue sdc as the 1st disk, thereby making sda the 2nd disk and sdb the 3rd disk. This order is only executed if the CD is the first bootable device but there is no CD in the drive.
If there is a CD in the drive then the seconding boor disk order is not executed by the Bios, as it does manage to read this point and so the original factory-shipped detection disk order applies, in other word the USB flsh drive is the 3rd disk if booting from a CD but changes to 1st disk if the CD is removed.
The above effectively means when a Linux user boots up a Linux CD he automatically installs the Linux in sdc or the 3rd disk, known as (hd2) to Grub’s. When he withdraws the CD and boots the USB flash drive as the 1st disk the installed Linux will not work. It will work immediately if the user alters the (hd2) reference to (hd0) in Grub’s configuration file menu.lst. There is nothing to it but a user must think like the Bios.
(4) There are two types of installation in a USB flash drive.
The first one is the normal installation just like a hard disk. This is recommended if you want to use the USB regularly. All you need is a fast USB flash drive larger than 5Gb. Just treat the USB device exactly like a hard disk and install Linux inside.
The second installation, also called the Frugal install, is most common and it runs the Linux in the USB flash drive just like a Live CD. This effectively copies the entire content in the CD onto the USB drive and replaces its isolinux with Grub. Isolinux is the standard boot loader for booting from a CD while Grub or syslinux must be used on a USB drive. In this form many installers like to take over the entire disk for the one Linux installation and some distros simply use directly the factory-ship FAT filing system with the USB flash drive.
The difference between the two is that the first installation is about 4 to 5 times larger in the storage requirement. If the iso image is 700 Mb the installed version may be 3Gb. If the distro is installed normally in a partition inside a USB drive then it will behave no different to it being in any hard disk, except slower.
For the Frugal install, working as a Live CD, the Linux is the same size as the CD. In operation the distro is expanded and stored in the ram. As a rule the settings are not stored and the original image is read-only and not changed but re-used repeatedly in every booting. That is why and how a Linux can be installed, booted and work normally from a FAT partition.
The main disadvantage of a full installation in a USB drive is that it is painfully slow, especially with a slow pen drive. Flash memory is not efficient for consecutive read and write and ext3 should be avoided because the journalling activities can slow down the speed as well as shorten the life of the device. A solid state memory flash drive is guaranteed a fixed number of read/write cycles.
(5) While Grub can be put inside a flash drive a Linux "may" not
This means Grub can be booted up but not the Linux itself. Grub will find the flash drive as long the Bios has a record of it. Grub is therefore able to find the kernel and load it into memory. However when Grub pass the control to the kernel and ceases operation it is up to the kernel to find the USB device and its partitions. Some distros have been compiled with the USB support at boot time in the ramdisk file initrd but other do not. Thus booting a Linux distro from a USB flash drive is not universally possible. For example the Debian family distros like Debian, Knoppix, Ubuntu etc has no problem to boot from a USB device but the Suse family does not entertain the same thing.
To put Grub alone in a flash drive I have written this tutorial.
AFAIK Grub can be put into any flash drive as long as the Bios reports the booting from it.
In conclusion I think booting Grub or a Linux isn't a mystery as long as we are aware of the limitations. Nearly all of them are unrelated to Grub.