Running a Bootloader from USB

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
johnsa
Member
Member
Posts: 296
Joined: Mon Oct 15, 2007 3:04 pm

Re: Running a Bootloader from USB

Post 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!
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Re: Running a Bootloader from USB

Post 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!
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Running a Bootloader from USB

Post 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 62 times
You know your OS is advanced when you stop using the Intel programming guide as a reference.
johnsa
Member
Member
Posts: 296
Joined: Mon Oct 15, 2007 3:04 pm

Re: Running a Bootloader from USB

Post 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 ?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Running a Bootloader from USB

Post 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 70 times
You know your OS is advanced when you stop using the Intel programming guide as a reference.
johnsa
Member
Member
Posts: 296
Joined: Mon Oct 15, 2007 3:04 pm

Re: Running a Bootloader from USB

Post 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).
embryo

Re: Running a Bootloader from USB

Post 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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Running a Bootloader from USB

Post by BrightLight »

johnsa wrote:In that case that's all good :)
Yes, I know how HDD booting works. :P
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Post Reply