Page 1 of 1

Booting from USB

Posted: Mon Oct 15, 2007 3:16 pm
by johnsa
Hi all,

New to the forum (and to OS coding really) except for writing a pmode system for DOS so many years ago I can hardly remember ;)

I've started working on an OS purely for interest sake and have gone with a 2 stage boot-loader design.

Sofar all the bits of it have come together under bochs nicely (using floppy image).

I just wanted to find out if A) there are any "code" differences one should take into account when booting from a USB device, or CD for that matter.

I thought I'd take the time now to test what I have sofar on a few real machines and setups, starting with a USB boot on my laptop.
I've written the 1st and 2nd stage loaders to a USB memory stick but I'm not having any joy in getting it to boot.. All i get is either a flashing cursor (not even executing/loading the 1st stage) or a message that the media is not bootable.

I'm running an AMI bios in this laptop, are there any known problems with it booting of USB?

Lots of questions.. :) Thanks for any help in advance!

Posted: Tue Oct 16, 2007 2:23 am
by os64dev
If youre pc is able to boot an usb device it should not be a problem. The only thing you have to take into account is that your bios might use a different approach to accessing the drive. A floppy in general has 2 heads, 18 sectors and 2880 tracks or something a like. When using an usb device i found out that is is up to the bios to assign values for the head/sector/track. I tested on three different machines and got three different results. Best thing to do is read them with int 0x10 function 8 (GetDriveParameters). Then you can use those parameters for reading the drive. This is what i do and it works perfectly. It will automatically run on harddisk and floppy.

Posted: Tue Oct 16, 2007 3:20 am
by johnsa
Thanks for the info. I will use those returned values when reading the 2nd stage loader.

My problem though seems to be happening before I even do anything (code wise).

The bios will load the 1st sector (1st stage loader automatically), but it doesn't I just get a non-bootable media error come up sometimes and others a blank screen with a flashing cursor. The 1st stage loader has the 55aa end signature marker, works under bochs etc.

So I was wondering if certain AMI bioses which are supposed to be able to boot from usb, don't work properly :)

Posted: Tue Oct 16, 2007 7:34 am
by Zacariaz
my greatest obsticle regarding usb boting has been getting the actual bootsector onto the usb device. I tryed rawrite, but couldnt find any useable parameters, itryed other stuff too, but eventually the only solution to my problem was copy/paste using a lowlevel hex editor i found (by the way i havent been able to find it again and i need it!).
I could choose to open the first sector of any device and then it was just a matter of pasting the binarys and save.

I would like another solution to that problem.

Posted: Tue Oct 16, 2007 7:55 am
by Combuster
what about using dd?

Posted: Tue Oct 16, 2007 7:59 am
by os64dev
Zacariaz wrote:my greatest obsticle regarding usb boting has been getting the actual bootsector onto the usb device. I tryed rawrite, but couldnt find any useable parameters, itryed other stuff too, but eventually the only solution to my problem was copy/paste using a lowlevel hex editor i found (by the way i havent been able to find it again and i need it!).
I could choose to open the first sector of any device and then it was just a matter of pasting the binarys and save.

I would like another solution to that problem.
If you use cygwin or linux you could use dd. It works but can be dangerous, using dd wrong can result in a very clean harddisk :wink: .

I only use usb stick with led indication:

then use: dd if=/dev/sdf of=/dev/null to check if the device i address is indeed the usb stick. otherwise try sdb, sdc, sdd, sde etc. when i have located the correct device i use dd of=/dev/sdf if=bin/drive.img where sdf is the device found with the above check.

Posted: Tue Oct 16, 2007 8:03 am
by johnsa
Hey,

I wrote a program for this purpose, I can send you a copy of it if you like, just send me your email addy.

It basically uses win i/o low level device names like \\.\F: to access a logical device sector by sector.

The little app I made can read/write between devices and files so it's also useful for capturing sectors from disks... works with usb/floppy/hdisk.