Page 1 of 1

Booting from a thumb drive....

Posted: Sat Jan 03, 2009 4:28 am
by worldsapart
Hi all,

Am new to this forum and find it really useful. I have currently just entered into the world of OS development. I have been trying out some small stuff... I am trying to brush up on my x85 assembly skills and tried writing my own bootloader.. Since I use a laptop for development, I dont have a floppy drive. I see a lot of articles on how to boot off a USB drive, but doesnt make much sense to me or rather isnt giving me the answers I need. I want an environment to test my bootloader. I have a Lexar 1GB Jumpdrive Firefly thumb drive and my BIOS supports booting off a USB drive.

Any help would be appreciated.. Any other suggestions will also be helpful.. like using a USB floppy drive or somethin like that.. thank you so much and look forward to gaining a lot of knowledge from this forum and the associated Wiki.

Re: Booting from a thumb drive....

Posted: Sat Jan 03, 2009 4:46 am
by 01000101
worldsapart wrote:I am trying to brush up on my x85 assembly skills
yeah... me to. :lol:

I'd recommend booting a disk image in an emulator instead of booting on real hardware if you're just beginning OS development. Grab BOCHS/QEMU/VPC/VirtualBox/etc... a GRUB image (or make your own bootloader) and run it virtually.

If you're still wanting to boot from a USB pen, I'd look up using the BIOS interrupt 0x13 (AH=0x02). Just write your bootloader to the USB drive (using partcopy, dd, winwrite, etc...) and have your bootloader treat it as the HDD or FDD it is being emulated as and use the INT 0x13 to load the sectors of your kernel into memory.

Re: Booting from a thumb drive....

Posted: Sat Jan 03, 2009 4:48 am
by LoseThos
You'll probably be stuck with the BIOS. It's not too hard making PIO ATA hard drive code, but USB is not easy. Using the BIOS for I/O means you're in the bush leagues.

With the BIOS, you have to stay in real 16-bit mode or switch back and forth. If you do direct hardware I/O instead of the BIOS, you can stay in 32 or 64-bit modes, but it's more work.

Re: Booting from a thumb drive....

Posted: Sat Jan 03, 2009 5:02 am
by worldsapart
lol!... i meant x86!... n thanks for the responses... wil resume workin on it soon.. pooped out for now.. :)

Re: Booting from a thumb drive....

Posted: Sat Jan 03, 2009 6:22 am
by worldsapart
k... think i posted too fast.. :) .. typical of a noob! thanks anyways guys...

this is wat I did..

dd if=boot.bin of=/dev/sdb

where boot.bin was the binary file(the bootloader). and sdb the thumbdrive as identified by Linux.. then I changed by BIOS settings to raise the boot priority of USB flash drive.. then enabled external drive boot..

n hey presto.. it worked! :) ..

Re: Booting from a thumb drive....

Posted: Sat Jan 03, 2009 2:59 pm
by Dex
Here's my two cents, booting from a USB device is very easy, as long as your BIOS lets you boot usb.
But you need to do two things, first check if your BIOS users hdd or fdd emulation or both.
For Fdd emulation you simple put a bootable floppy image on the usb fob, to do this you can use linux or a tool for XP.
Now once you do this your usb fob is only the size of the floppy image, but you can undo this by a simple format.

For hdd emulation you will need a special program to mod both the usb mbr and boot sector with your own boot sector, and you will need to format the fob ether Fat16 or Fat32 acording to what your boot sector user's.
The above boot sector will be the same as a normal floppy or hdd using int 13h, but if you go back and forward to realmode from pmode you can read/write to a usb fob without a USB driver.
That it, but the best usb device you can get is a USB fob with both a fdd and a hdd partion so you can boot your OS from any type of emulation, note: you can not make a normal fob do this without alot of work.

NOTE: The best way to check your emulation type, is to put a USB fob in you pc/laptop and reboot and go into your BIOS, then go to the boot order part and see if it say fdd usb or hdd usb etc.

Re: Booting from a thumb drive....

Posted: Sun Jan 04, 2009 3:10 am
by worldsapart
think my BIOS mentioned a "USB flash drive" and couple more USb stuff... dont remember exactly.. But very valuable advice.. thanks..

Re: Booting from a thumb drive....

Posted: Sun Jan 04, 2009 11:46 am
by Dex
I also have written simple usb booting tut here: http://dex4u.com/USBboot.htm
Its for coders with XP and booting my OS, but you can just replace the boot file with your own OS files.