boot USB memory stick

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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:boot USB memory stick

Post by Candy »

Kemp wrote: Just a quick point that no-one seems to have picked up, the boot sector is sector 0, not 1.
*cough*

LBA sector 0, CHS cluster 0 head 0 sector 1.

In CHS, there is no sector 0.
DennisCGc

Re:boot USB memory stick

Post by DennisCGc »

Kemp wrote: Just a quick point that no-one seems to have picked up, the boot sector is sector 0, not 1.
Dumb question: CHS or LBA?
Kemp

Re:boot USB memory stick

Post by Kemp »

... I honestly don't know what to say... How have I always managed to call it sector 0 without noticing a contradiction in the docs? I could have sworn that sectors started at 0 and one of the others (track specifically) started numbering at 1. I guess you really do learn something new every day.

Of course, a lot of the stuff I read (and coded) was in terms of LBA numbering so I guess I can get away with that part, but it's really quite scary when you find out you had such a basic piece of knowledge wrong :o

In other news, the FAQ doesn't mention where the bootloader goes on the disk at all except in the FAT12 docs, I would have thought the boot sequence page would be logical, lol. Just in case someone is at a state of knowledge where they don't know 'boot sector' tends to mean 'first sector'.
OS ?

Re:boot USB memory stick

Post by OS ? »

Hi all.
I have run a disk sector editor on the usb stick and searched for a string that I know is in boot sector and found a good 1000 sectors into the usb memory stick. The first sector is what you would expect to find from a none bootable disk :-\
Is it possible to find out what sector I the boot sector is loaded from after it has been loaded and run ??? I cannot figure out why the boot sector is not located right at the beginning :-\. Anyway according to documentation I have
read the bios just see's it as being a harddrive! I have tried to create an image with the required code at the beginning but fasm runs out of memory (the image is about 119mb) with the intention of writing the entire image.
Thanks for everybody's help. I hope this extra infomation helps :D
Ryu

Re:boot USB memory stick

Post by Ryu »

Are you sure your writting your binary at offset 7C00h-7DFFh to the first sector of the usb stick? Also, your boot sector was found at sector 1000 exactly? 1000 * 512 = 7D000h Although its not exactly where it would end up if you written the entire binary starting at the first sector, it one fishy number.

edit: As I know org 7C00h in masm would produced a binary that large + the code following it I'm not sure about nasm.
OS ?

Re:boot USB memory stick

Post by OS ? »

Hi all
Just taken another look at the disk sector editor. The first sector has been written correctly but the second which contains a string to be displayed is at offset 0x000f5400 this is really weird :-\
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:boot USB memory stick

Post by Candy »

OS ? wrote: Hi all.
I have run a disk sector editor on the usb stick and searched for a string that I know is in boot sector and found a good 1000 sectors into the usb memory stick. The first sector is what you would expect to find from a none bootable disk :-\
Is it possible to find out what sector I the boot sector is loaded from after it has been loaded and run ??? I cannot figure out why the boot sector is not located right at the beginning :-\. Anyway according to documentation I have
read the bios just see's it as being a harddrive! I have tried to create an image with the required code at the beginning but fasm runs out of memory (the image is about 119mb) with the intention of writing the entire image.
Thanks for everybody's help. I hope this extra infomation helps :D
Your disk is probably partitioned. That means that the first sector contains a partition table between 0x1be and 0x1fd which explains where the actual partitions are. The sector you found is probably from your partition, being the first sector in the partition. If your master boot record doesn't exist though, you still can't boot from it.

I'll play around with my usb stick tonight if I have the time.
Dex4u

Re:boot USB memory stick

Post by Dex4u »

This is how it works, all boot sectors are the same, (eg: first sector, 512bytes etc), but for Hdd you need to load, a second sector (fat16) or more for (fat32), to get the info you need to load from disk.

Try this code, from my hdd module, to do that:

Code: Select all

mov   esi,446 ;offset from start of boot sector 
mov   al,byte[ds:esi]
cmp   al,80h
jne   LoadMbrError
mov   dx,word[ds:esi]    ; set DH/DL for INT 13 call
mov   cx,word[ds:esi+2]   ; set CH/CL for INT 13 call
mov   [count],0
int13hloop1:
call FddRead    ; int 13h call
jc    HddTryAgain1
The buff you load this to, needs to be setout for fat16 or fat32, this will give you the info you need to load from disk.
Here a link that i found helpfull:
http://www.geocities.com/thestarman3/as ... Tables.htm

NOTE: The above code is for 32bit pmode and needs converting to 16bit realmode, and it only test for first partion.
OS ?

Re:boot USB memory stick

Post by OS ? »

Hi all :)
I've done it (I think). I had to write the next sector direct using WinHex and the code works :D This I think is going to take some investigation :-\ With this method I think I will be information direct into the boot sector (stuff like sector size, cluster size, etc,....). But thanks for everybody's help :D You are all stars ;D
viral

Re:boot USB memory stick

Post by viral »

hello..
sorry i woke up this thread.. but i thought my question is much similar to this and i shuld not fork another thread.

I am trying to boot my kernel from usb pen drive. I have I-Ball 256mb pen drive. What i am trying to do is just run a "Hello World" bootsector. But my bios is not loading it. It gives me error "Operating System not found."

Bios is emulating usb stick as hard drive and i am making it 1st boot device too.

i am using mkbt.exe (just found it when i was googling) to write bootsector to pen drive..

can anyone give some idea.......
Dex4u

Re:boot USB memory stick

Post by Dex4u »

The best way to boot from a usb pen drive, it to try this: format the drive from windows to fat16, with sys drive, choice ticked.
This will put the basic dos files on the drive.
You can then load your OS from dos (including freedos), this is the simplest way around the problems, that i have found.
Same topic here: http://board.flatassembler.net/topic.php?t=5133
viral

Re:boot USB memory stick

Post by viral »

hi.....
i have tried to format it from window XP. But the option "Create an MS-DOS startup disk" is disabled.. so i cant make it system disk.... i have attached the screen shot of format window...
Dex4u

Re:boot USB memory stick

Post by Dex4u »

Hi, first off i do not use XP but win98 for this.
but first make shore you highlight Fat not fat32 as fat is short for fat12, if it still does not work, try this program http://www.nu2.nu/mkbt/
I have also used this " HP USB Disk Storage Format Tool", but the link for it is now dead :( .
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:boot USB memory stick

Post by Candy »

Dex4u wrote: Hi, first off i do not use XP but win98 for this.
but first make shore you highlight Fat not fat32 as fat is short for fat12
FAT16. FAT12 disks can not be that large (fat12 only supports 4086 clusters, which accounts for only 128-something MB, not 256), not counting that it would be very very wasteful.
Post Reply