Page 2 of 2

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 8:49 am
by johnsa
You cannot really tell which machine is going to do what.. the only option is to try and make them all happy at the same time :)

My first stage boot loader is even worse for me at the moment because i've effectively unified first stage loaders to deal with FDD,HDD,USB in both modes and native CDROM booting (eltorito) where the sector size is 2kb.
The idea for me was that i'd eventually land up with a single loader (code+bin) which could be applied to any device instead of having to select an appropriate one for each type of media.

I have it working on about 80% of machines so-far.. still not perfect!

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 9:29 am
by MustLearn
Thanks for all the replies :D!
Your Post has actually been more helpful than all the ones I've come across after searching for a couple of days :)

I've come across the code blocks at the start of a few bootloaders but never really paid attention to them :O
I would really appreciate it if someone could link me to some material online that would explain all the stuff about using and FINDING OUT the oem, sectors, bytes_sectors and what not :). I didn't actually read up on finding all that stuff out :(

I have it working on about 80% of machines so-far.. still not perfect!
Well 80% is pretty damn impressive considering all the problems I've run into trying to display a message!

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 9:31 am
by BrightLight
Booting from a USB is *usually* just like booting from a hard disk. You need to use ORG 0x7C00 and properly set up your segments (DS, ES) and stack (SS, SP).
This code from my own OS might help (it boots from USB sticks and hard disks and it works on real hardware.) Notice that when the BIOS gives control to the bootloader, the state of registers are all undefined (except DL which *always* contains the BIOS drive number.
Here's the code of my own boot sector.
boot.asm
Boot sector for harddisks/USB sticks
(2.54 KiB) Downloaded 63 times

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 9:39 am
by johnsa
I can almost guarantee you that bootsector will not boot on my machines as a HDD style load. Firstly you've put a pseudo-BPB in, and it has no partition table structure, unless you're formatting the USB with a file system first, using a valid MBR and putting this loader in an actual partition ?

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 9:50 am
by BrightLight
johnsa wrote:I can almost guarantee you that bootsector will not boot on my machines as a HDD style load. Firstly you've put a pseudo-BPB in, and it has no partition table structure, unless you're formatting the USB with a file system first, using a valid MBR and putting this loader in an actual partition ?
My OS boots from USB sticks as HDD on two of my computers. Yes my boot sector is on a partition and of course I have an MBR (originally by Muazzam.) Here it is:
mbr.asm
(2.97 KiB) Downloaded 71 times

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 10:18 am
by johnsa
In that case that's all good :)

Just wanted to make it clear so that MustLearn can see that the structure for the boot loader is very different if it's sitting in place of the MBR or on the bootable partition, and that you can't expect it to work if the machine boots as USB HDD and you've just written your 512b loader to sector 0 (because then it is replacing the MBR).

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 10:59 am
by embryo
johnsa wrote:unless you're formatting the USB with a file system first, using a valid MBR and putting this loader in an actual partition
It is a really helpful solution. It can deal with most of BIOSes, just because they try to infer media type by reading some information from a USB stick and if the stick has valid file system, then it is most probable that most BIOSes are able to identify the media type properly.

Re: Running a Bootloader from USB

Posted: Sat Feb 07, 2015 11:06 am
by BrightLight
johnsa wrote:In that case that's all good :)
Yes, I know how HDD booting works. :P