How to make bootloader for USB flash memory ?
How to make bootloader for USB flash memory ?
Hey. I wanted to move my bootloader with my small kernel from floppy to usb.
I formated usb as fat32. After that i downloaded tool HxD to edit first 512 bytes of usb memory flash and then i put there my bootloader's 512 bytes. After i rebooted my pc to test it (usb flash was found in bios and selected as primary device) then i got bios message that no bootable device found.
What is wrong with usb ?
I have checked after that and first 512 bytes of 1st sector were correct as my bootloader's file.
What may be reason that usb is not discovered as bootable by bios ?
I formated usb as fat32. After that i downloaded tool HxD to edit first 512 bytes of usb memory flash and then i put there my bootloader's 512 bytes. After i rebooted my pc to test it (usb flash was found in bios and selected as primary device) then i got bios message that no bootable device found.
What is wrong with usb ?
I have checked after that and first 512 bytes of 1st sector were correct as my bootloader's file.
What may be reason that usb is not discovered as bootable by bios ?
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
Re: How to make bootloader for USB flash memory ?
It is probably looking for a master boot record and partition table.
The continuous image of a connected set is connected.
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How to make bootloader for USB flash memory ?
USB devices can either be formatted like a large floppy disk (sector 0 contains the volume boot record) or a hard disk (sector 0 contains the master boot record and partition table). You might be dealing with the latter, in which case you'll need to ensure that sector 0 contains a MBR that will load your VBR. In HxD, choose "Removable Disk 1" instead of a drive letter.
Some BIOSes are picky about what they'll accept. Make sure you have the boot signature at the end of the MBR and VBR. If you have a MBR, make sure the partition table is correct and the appropriate partition is marked as bootable. Make sure the values in the BPB are correct.
Some BIOSes are picky about what they'll accept. Make sure you have the boot signature at the end of the MBR and VBR. If you have a MBR, make sure the partition table is correct and the appropriate partition is marked as bootable. Make sure the values in the BPB are correct.
Re: How to make bootloader for USB flash memory ?
mathematician wrote:It is probably looking for a master boot record and partition table.
Well I have done it:
1. format usb flash using windows tool with fat32
2. edit with HxD tool first 512 bytes (i put there my bootloader)
Well I dont understand itOctocontrabass wrote:USB devices can either be formatted like a large floppy disk (sector 0 contains the volume boot record) or a hard disk (sector 0 contains the master boot record and partition table). You might be dealing with the latter, in which case you'll need to ensure that sector 0 contains a MBR that will load your VBR. In HxD, choose "Removable Disk 1" instead of a drive letter.
Some BIOSes are picky about what they'll accept. Make sure you have the boot signature at the end of the MBR and VBR. If you have a MBR, make sure the partition table is correct and the appropriate partition is marked as bootable. Make sure the values in the BPB are correct.
Could you explain how to deal with it more clearly ?
For floppy i have been using WinImage tool where i have only selected my bootloader and thats all.
How to prepear it to work correctly ?
Re: How to make bootloader for USB flash memory ?
Start with that first. Simply copy (with HxD) the floppy disk image to the flash drive. Boot and run.Pem3 wrote:Hey. I wanted to move my bootloader with my small kernel from floppy to usb.
Re: How to make bootloader for USB flash memory ?
I have done exactly what you are trying to do. You could try the following (assuming you are using Windows):
Open a CMD window and execute the following commands: (remove ')
Now try putting your bootloader on with HxD and booting from it.
Open a CMD window and execute the following commands: (remove ')
Code: Select all
'diskpart'
'list disk'
'select disk #' (replace # with the corresponding disk number - MAKE SURE IT IS YOUR FLASH DRIVE NOT YOUR HARD DRIVE)
'clean'
'create partition primary'
'select partition 1'
'active'
'format FS=FAT32'
'assign'
'exit'
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Re: How to make bootloader for USB flash memory ?
I have checked what kind of bytes are first 512 bytes of floppy image file and they seem to be some kind of meta datamikegonta wrote:Start with that first. Simply copy (with HxD) the floppy disk image to the flash drive. Boot and run.Pem3 wrote:Hey. I wanted to move my bootloader with my small kernel from floppy to usb.
Becouse last bytes (byte 510 and 511) were not aa55
BMW wrote:I have done exactly what you are trying to do. You could try the following (assuming you are using Windows):
Open a CMD window and execute the following commands: (remove ')Now try putting your bootloader on with HxD and booting from it.Code: Select all
'diskpart' 'list disk' 'select disk #' (replace # with the corresponding disk number - MAKE SURE IT IS YOUR FLASH DRIVE NOT YOUR HARD DRIVE) 'clean' 'create partition primary' 'select partition 1' 'active' 'format FS=FAT32' 'assign' 'exit'
Ok, but how to put it that way ?
Formating makes some byte's modification of first 512 bytes
my boot file is equal 512 bytes
so how to deal with it ?
Re: How to make bootloader for USB flash memory ?
I have formated as fat32 and loaded my bootloader code, but its not booting anyway ?!
According to this article http://www.easeus.com/resource/fat32-disk-structure.htm , first 446 bytes are my code.
So i "pasted" my first 446 bytes of my booloader into these memory space. My bootloader is aboout 300 bytes so some of these 446 are zeros. After these 446 bytes is partition 1st information that i left alone (16 bytes). Next are 3*16 bytes with zeros - info about other partitions. And last 2 bytes are 0x55 and 0xaa.
What is wrong here ?
BIOS not see this usb flash memory as correct bootable device. Why ?
or meaby I am understanding it in wrong way... in floppy there was 1 partition for 1,44MB
in fat32 i can have up to 4 partitions
and how about my bootloader ? where to put code of it ?
in 1st sector of usb memory flash or 1st sector of partition ?
if 1st sector of partitin then how to calculate what sector of partition data as first (according to http://www.easeus.com/resource/fat32-disk-structure.htm) ?
According to this article http://www.easeus.com/resource/fat32-disk-structure.htm , first 446 bytes are my code.
So i "pasted" my first 446 bytes of my booloader into these memory space. My bootloader is aboout 300 bytes so some of these 446 are zeros. After these 446 bytes is partition 1st information that i left alone (16 bytes). Next are 3*16 bytes with zeros - info about other partitions. And last 2 bytes are 0x55 and 0xaa.
What is wrong here ?
BIOS not see this usb flash memory as correct bootable device. Why ?
or meaby I am understanding it in wrong way... in floppy there was 1 partition for 1,44MB
in fat32 i can have up to 4 partitions
and how about my bootloader ? where to put code of it ?
in 1st sector of usb memory flash or 1st sector of partition ?
if 1st sector of partitin then how to calculate what sector of partition data as first (according to http://www.easeus.com/resource/fat32-disk-structure.htm) ?
Re: How to make bootloader for USB flash memory ?
You could try putting the BPB entries in your bootloader for the FAT filesystem.
Do you have the magic bytes at the end of your bootloader (0x55, 0xAA)?
Maybe it's your computer, have you tried it on an emulator?
Do you have the magic bytes at the end of your bootloader (0x55, 0xAA)?
Maybe it's your computer, have you tried it on an emulator?
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How to make bootloader for USB flash memory ?
You need two bootloaders.Pem3 wrote:After these 446 bytes is partition 1st information that i left alone (16 bytes). Next are 3*16 bytes with zeros - info about other partitions. And last 2 bytes are 0x55 and 0xaa.
What is wrong here ?
The first, in sector 0, is the MBR. You can copy Microsoft's code for now. You must also mark your partition as bootable (the first byte of the partition info must be 0x80).
The second, at the start of the partition, is the VBR. (When you open the drive letter in HxD, it will appear as sector 0 even though it isn't really at the beginning of the disk.) That's where you put your FAT32 code. Don't overwrite the BPB!
Some computers will not boot your drive unless both of these bootloaders have 0x55, 0xAA in the last two bytes.
Re: How to make bootloader for USB flash memory ?
I don't understand this answer. Could you possible write it more simply ?BMW wrote:You could try putting the BPB entries in your bootloader for the FAT filesystem.
YesBMW wrote:Do you have the magic bytes at the end of your bootloader (0x55, 0xAA)?
I have tried it withBMW wrote:Maybe it's your computer, have you tried it on an emulator?
I haven't tried it with Bochs yet, because I didn't find any solution for current bochs version to use usb.
I tried it with PC and VirutalBox, result is same - no bootable disc found.
How do the first bootloader know where is my second bootloader ? Bios loads first 512 bytes (1st bootloader) into 0x7c00. How about second bootloader ? How code is hidden inside these magic bytes of http://thestarman.pcministry.com/asm/mb ... br.htm#CHS ?Octocontrabass wrote:You need two bootloaders.Pem3 wrote:After these 446 bytes is partition 1st information that i left alone (16 bytes). Next are 3*16 bytes with zeros - info about other partitions. And last 2 bytes are 0x55 and 0xaa.
What is wrong here ?
The first, in sector 0, is the MBR. You can copy Microsoft's code for now. You must also mark your partition as bootable (the first byte of the partition info must be 0x80).
The second, at the start of the partition, is the VBR. (When you open the drive letter in HxD, it will appear as sector 0 even though it isn't really at the beginning of the disk.) That's where you put your FAT32 code. Don't overwrite the BPB!
Some computers will not boot your drive unless both of these bootloaders have 0x55, 0xAA in the last two bytes.
What do you mean fat32 code ?
Which bytes are BPB ?
Re: How to make bootloader for USB flash memory ?
BPB == Bios Parameter BlockPem3 wrote: Which bytes are BPB ?
http://wiki.osdev.org/FAT#BPB_.28BIOS_P ... r_Block.29
Currently developing Lithium OS (LiOS).
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How to make bootloader for USB flash memory ?
The first bootloader (MBR) reads the partition table to find the partition where you've put the second bootloader (VBR; your code).Pem3 wrote:How do the first bootloader know where is my second bootloader ?
Your code boots a FAT32 volume, correct?Pem3 wrote:What do you mean fat32 code ?
Re: How to make bootloader for USB flash memory ?
I'm sorry. Seriously so, I'm about to be a jackass... but I assume you mean Windows when you say "PC". Please don't do that. Please... I'm begging you. You mean Windows... just say "Windows". I could go on a rant here (and am obviously geared up for one), but I won't.Pem3 wrote:I tried it with PC and VirutalBox
Super sorry everyone. I hate to be that guy, but that hit a button hard. Enough so that I was willing to write this and apologize in it at the same time, and hit submit.
Re: How to make bootloader for USB flash memory ?
Ok, clear now. And how about bytes -> code. Is there available asembler code of these bytes (1st bootloader) ? Dunno how to find it by keywords in google, which keywords to use.Octocontrabass wrote:The first bootloader (MBR) reads the partition table to find the partition where you've put the second bootloader (VBR; your code).Pem3 wrote:How do the first bootloader know where is my second bootloader ?
Still don't understand what do you mean by fat32 code Do you mean by FAT32 code of both: bootloader code and BPB ?Octocontrabass wrote:Your code boots a FAT32 volume, correct?Pem3 wrote:What do you mean fat32 code ?
So for fat32 it will be ( http://wiki.osdev.org/FAT#BPB_.28BIOS_P ... r_Block.29 ) :
0 - 2: jmp instruction to my boot code
3-35: bpb's data
36-89; ebpb's data
90-509; boot code
510-511; signature of 0xaa55
Is it correct ?
Because it's not working. I pasted my code from 90 byte (0x5a) and same result - message "reebot and select proper boot device"
I don't understand you answer... By saying "PC" i had on my mind situation where I:mrstobbe wrote:I'm sorry. Seriously so, I'm about to be a jackass... but I assume you mean Windows when you say "PC". Please don't do that. Please... I'm begging you. You mean Windows... just say "Windows". I could go on a rant here (and am obviously geared up for one), but I won't.Pem3 wrote:I tried it with PC and VirutalBox
Super sorry everyone. I hate to be that guy, but that hit a button hard. Enough so that I was willing to write this and apologize in it at the same time, and hit submit.
1. restart PC by clicking button at pc's tover
2. go bios and select 1st bootable device - my usb memory flash drive
3. save bios settings and restart pc
4. check result of prepared bootable usb memory flash drive
By saying "VirtualBox" I meant:
1. Download and mount Plop Live ( http://www.plop.at/ ) to be possible to use USB as boot device (VirtualBox doesn't support it directly)
2. Mount my USB memory flash drive
3. restart virtualbox machine
4. check result of prepared bootable usb memory flash drive
I don't understand you. Shall I understand your answer as laughing of my person or what ? Have I written something funny or wrong ? I know that my question in this topic is funny as for person who was able to write in assembler a little advanced software like boot-loader and kernel, but so far I haven't worked directly with system files and so far I didn't know how is it working, yea have fun of that. I really don't understand your attitude.