# What boot loader should I use on a USB pen drive?

## DingbatCA

I have built up a USB boot pen drive that boot a few different OS's, from Gentoo to Knoppix and all my other favorite tools in the middle.  The drive is formatted in FAT32 and I have been using grub for years.  But grub only work about 90% of the time.  On some systems I get grub error 17, or 5, on others I get "invalid boot media."   I think it is time for a new boot loader. 

Any advise?

----------

## creaker

I think syslinux will be suitable for your goals

----------

## DingbatCA

Thanks!  I will give it a try.

----------

## srs5694

Unfortunately, today is a difficult time for creating a universal boot medium. The reason is the switch from BIOS to the newer Extensible Firmware Interface (EFI; aka Unified EFI, or UEFI). Depending on the configuration, some computers will boot nothing but BIOS boot loaders, others will boot nothing but EFI boot loaders, and some will boot both. Worse, some EFI-booting computers are set to require Secure Boot, so if you want to cater to them, you'll need to jump through extra hoops. Further complicating matters is the fact that some USB flash drives just can't be made bootable on some computers for hardware compatibility reasons. (At least, that's been my experience, and I've seen a few posts from others who've come to the same conclusion.)

It is possible to create a USB flash drive that will boot on a wide variety of hardware -- the Fedora developers seem to have gone to extreme lengths to do so, for instance. (IMHO, they've gone too far, creating a Frankenstein's-monster type of boot image that plays so "fast and loose" with various standards that it's scary.) This is a very esoteric subject, though, and if you don't need CD-R/DVD compatibility, you don't need to cover all these extremes.

For BIOS-mode booting, GRUB Legacy or GRUB 2 is likely to be the way to go. (My suspicion is that the boot errors you report are related to computers set to boot only in EFI mode.) I don't really have much to say about this.

For EFI-mode booting, see my Web page on EFI boot loaders. IMHO, ELILO and GRUB Legacy are likely to be easier to set up than GRUB 2 for this, and using one of these will have the advantage of not creating any conflicts with the BIOS-mode GRUB. Alternatively, if all your kernels are 3.3.0 or later (with the EFI stub loader), you could use gummiboot or rEFInd.

Note that BIOS-mode and EFI-mode boot loaders can coexist on one boot medium.

----------

## DingbatCA

I have run into the USB pen drive problem before.  It is really a pain to find a good USB pen drive. 

The invalid boot medium is almost always a Dell issue.  It is caused by how the Dell BIOS reads partition tables...

Almost all the computers I am playing with are old and don't have EFI.

Bummer that EFI and BIOS-mode cant coexist.  That might snag me in a few years when my "old hardware" is not so old.

For now I will play with syslinux.  Lets see If this can boot all my test systems.

----------

## NeddySeagoon

DingbatCA,

Grub should be OK. On FAT32 symlinks are not supported so you may not use a menu.lst -> grub.conf symlink a boot -> . and so on.

Other issues are usually related to the kernel trying to mount root before USB is started.

As /boot can be anywhere and the EUFI system partition needs to be FAT32, provided you take care to avoid symlinks, /boot and the EUFI system partition could be the same place.

----------

## srs5694

 *DingbatCA wrote:*   

> The invalid boot medium is almost always a Dell issue.  It is caused by how the Dell BIOS reads partition tables...

 

A true BIOS does not read partition tables -- or at least, it has no need to do so. The BIOS boot procedure is that the BIOS reads the boot medium's boot sector (the MBR, or first sector, in the case of a hard disk) and executes the code it contains. This code (the first-stage boot loader) then does whatever it does, which in the case of a Microsoft-style boot loader is to interpret the partition table that's also contained in the MBR and execute the boot code from a partition that's marked as bootable. (Other boot loaders can do other things. GRUB and LILO both execute code whose location is hard-coded by sector number without using the partition table, for instance.) Note that it's the boot loader, not the BIOS, that interprets the partition table.

That said, recent firmware, most of which is either EFI firmware or at least uses some EFI-influenced components, may read the partition table and use that in helping to determine the boot mode. For instance, some implementations require that the MBR contain at least one partition that's marked with a boot/active flag in order to boot in BIOS mode. In most cases, these implementations switch to an EFI-mode boot if that condition isn't met. Unfortunately, many implementations use some pretty brain-dead algorithms to determine the boot mode, and the algorithms used vary from one EFI to another, which makes it difficult to create a disk that's guaranteed to be bootable on all recent computers.

 *Quote:*   

> Bummer that EFI and BIOS-mode cant coexist.  That might snag me in a few years when my "old hardware" is not so old.

 

That's explicitly the opposite of what I wrote. You can make a boot medium that holds both EFI-mode and BIOS-mode boot loaders and that works with both. There is the caveat that the variability in how different EFIs handle the decision of which mode to use can create incompatibilities with certain specific computers, though.

----------

## NeddySeagoon

srs5694,

Some brain dead BIOSes assume that an MSDOS partition table will be present on LBA 0 and check the bootable flags.

They produce a no operating system found error it the check fails.

----------

## DingbatCA

HA! thanks for the correction Srs5694.

I have used legacy grub (0.97) for many years. I am scared away by grub2's complexity.

My goal is to make a more flexible bootable USB pen drive.  Currently using grub 0.97 which has caused me some problems.

My requirements are simple.  fat32 file system... maximizing the forward (EFI) and backward compatibility.

My normal setup process is:

```

dd if=/dev/zero of=/dev/sdt bs=512 count=128

fdisk /dev/sdt < fdisk.txt

fdisk -l /dev/sdt

Disk /dev/sdt: 16.1 GB, 16173236224 bytes

64 heads, 32 sectors/track, 15424 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sdt1   *           1       15424    15794172    c  W95 FAT32 (LBA)

mkfs.vfat -F 32 /dev/sdt1

mount /dev/sdt1 /mnt/pen

cd ~/pendrive_gold

rsync -a . /mnt/pen/

sync

umount /mnt/pen

grub

device (hd0) /dev/sdt

root (hd0,0)

setup (hd0)

quit

```

I am not doing anything complicated with the setup.  Just wipe out the current partition table and the first few blocks. Make a new partition taking up the whole drive. Making sure to set the active flag and ID of partition 1.  Copy the files over and setup grub.

Things I dont know.  Disk offset?  Should I be setting the start of my partition to 2048 (512, 1024...), to make sure the file system starts at the beginning of a block?  Will this cause booting on some poorly coded BIOS'es to fail?

Is legacy grub 0.97 still the best option?  Is there something better?

----------

## NeddySeagoon

DingbatCA,

Can you post the output of fdisk in blccks, rather than cylinders please?

The switch is on the eXpert menu.

Its not clear where your partition starts and this may be important to grub as it needs about 10k after the MBR for its stage1.5

The stage1.5 is not essential but grub becomes fragile without it.

----------

## DingbatCA

Is this what you are looking for?

```

Command (m for help): x

Expert command (m for help): p

Disk /dev/sdt: 64 heads, 32 sectors, 15424 cylinders

Nr AF  Hd Sec  Cyl  Hd Sec  Cyl     Start      Size ID

 1 80   0   9    0  63  32 1023          8   31588344 0c

 2 00   0   0    0   0   0    0          0          0 00

 3 00   0   0    0   0   0    0          0          0 00

 4 00   0   0    0   0   0    0          0          0 00

```

----------

## NeddySeagoon

DingbatCA,

Yes.  Your partition starts at sector 8.

When you install grub to the MBR, you should get a message about embedding stage1.5 failed ... this is not fatal.

Start the partition at sector 2048, which is the new default although, 64 would be good too.

The old traditional 63 came about by accident based on the C/H/S addressing scheme, which has been a fiction for a long time now, since 4G HDD anyway.

----------

## DingbatCA

I always wondered about the default of 63.  The 2048 makes good sense to me.

Is grub (0.97) still the best option?

----------

## NeddySeagoon

DingbatCA,

It's what I would use but syslinux may be more flexible.  Thats what System Rescue CD uses

----------

## DingbatCA

I will play with both.  

I have 3 systems that have issues with my current setup of grub.  A Dell, a mini-ITX board, and a Mac Book Pro.  If I can get a solution to boot all 3, I will be happy.

Thanks so much every one!

----------

## DingbatCA

Just wanted to give an update.

I have two (Ignoring the Mac, for now) fussy system that would not boot with grub (0.97).  I switched over to syslinux 6.02 hopping this would boot all my systems.

The Dell Inspiron 530 would not even recognize the pen drive as a bootable device with grub.  With Syslinux I get "boot error."  I guess this is progress?

The other system is a first generation Nvidia ION mini-ITX board.  With grub, I was getting a grub error 17.  With Syslinux it hangs at updating DMI.

I upgraded the BIOS on both systems trying to get them to boot...  No love.  Well, I tried.

----------

