2/06/2011

Getting debian linux to boot from usb pendrive on an asrock amibios motherboard

I tried at least a dozen different methods to install debian/fedora/ubuntu/... on a pendrive, which all failed because grub could not find its stage 2 files on the ext2 partition. Note that i'm not talking about live-images but about a normal installation with the pendrive instead of a harddrive.
After some desparate googling, i found that it is a problem with the motherboard's bios (mine is an asrick k7s41gx) trying to emulate the usb pendrive as a floppy.
The problem with that is, that on booting only the first and only a fat16/fat32 partition is reported to the bootloader in the mbr.

How to do it simple:
1) Create a 64mb fat16 primary partition at the beginning of the pendrive
2) Install your linux in the second partition
3) Mount the pendrive in some livelinux or windows and install syslinux in the fat partition, writing the mbr (-m option)
4) Copy /boot/vmlinuz-* and initrd.img-* to the first partition
5) Create a simple syslinux.cfg, editing the root to your linux partition and the vmlinuz and initrd filenames as necessary
default foobar
label foobar
kernel vmlinuz-2.6.26-2-686
append root=/dev/sda2 initrd=initrd.img-2.6.26-2-686
How to do it elegantly:
Idon't know. symlinks won't work in the fat filesystem, so everytime the kernel image name changes, we'll have to update the config.
I didn't bother chainloading grub since its only a pendrive installation with one system.

If you have any ideas on getting the insallation to use the first partition as /boot, including the symlings in /, please share your thoughts.