howto write bootsector to HDD ? ("now what")

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.
xyjamepa

howto write bootsector to HDD ? ("now what")

Post by xyjamepa »

hey guys it's been long time!!!
okay i've just finished my exam and want to get back to os devlopment.
my question is how can i boot my os from hard drive
please note that my os use Fat12 file system
just give the first step
thanx alot....
User avatar
spix
Member
Member
Posts: 128
Joined: Mon Jun 26, 2006 8:41 am
Location: Millicent, South Australia
Contact:

Re:now what

Post by spix »

my question is how can i boot my os from hard drive
please note that my os use Fat12 file system
Did you write your own boot loader, or are you using grub?

If you are using Grub, it's fairly easy, you just edit you menu.lst to point to the kernel on your Hard Drive.

If not, you will need to write code to read from the Hard Drive, then you need to access the file system on your hard drive.

Is the Hard Drive file system also FAT? Will your FAT file system code work with a large disk like a Hard drive (will it support FAT16 and FAT32?)

You will probably want some sort of VFS layer so your OS can work out which file system the file requested is on, ie. the one on the hard drive, or the one on the floppy drive.

Hope that helps..
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:now what

Post by Pype.Clicker »

spix wrote: You will probably want some sort of VFS layer so your OS can work out which file system the file requested is on, ie. the one on the hard drive, or the one on the floppy drive.
okay, for the OS itself, but wait ... VFS for the bootloader ?

The options i'd suggest would be
1. use GRUB if you plan to switch to HDD booting unless you have a crashdisk you're ready to low-level format.
2. make a small FAT12 partition on your HDD (it's typical for Unix system to have /boot on a separate partition, for instance).
3. just write both a FAT12 and a FAT32 bootloader. The FAT12 loader will be used when installing the system on a floppy, and the FAT32 one when installing on a FAT32 partition of a HDD.

I'd also say "Stay away from the master bootrecord for the moment". You can use GRUB and chainloading if you really need multiboot.
just give the first step
* make sure you have a proper sector read/write function for HDDs (iirc, you do not use the same BIOS functions for HDDs and floppies)
* make sure you really want to write your own HDD bootloader
* prepare a HDD disk image you'll operate on with QEMU/bochs at the start. Unless you find a magic tool for that, you can
a. create an empty disk image (bximage)
b. start qemu with -hda=myimage -floppy=/dev/fd0 -boot a (and put a real floppy with MS-DOS installed on it)
c. within the emulator, create partitions and format the FAT stuff you'll use for storing boot files.
d. get out of the emulator, zip a copy of the disk image to avoid repeating those steps...
* have fun in the bochs before you attack the real world.

Btw, what dev'ing environment do you use ? (windows/linux/...)

@all: anyone knows of a open-source easy-to-use floppy image one could use for step C. other than digging for MS-DOS 6.22 boot floppy ?
User avatar
spix
Member
Member
Posts: 128
Joined: Mon Jun 26, 2006 8:41 am
Location: Millicent, South Australia
Contact:

Re:now what

Post by spix »

okay, for the OS itself, but wait ... VFS for the bootloader ?
Sorry, I was thinking of for the OS itself, my train of thought left the tracks.
blip

Re:now what

Post by blip »

Pype.Clicker wrote:* make sure you have a proper sector read/write function for HDDs (iirc, you do not use the same BIOS functions for HDDs and floppies)
Nah, you use the same BIOS functions, the only thing that differs is the device number you give them.
Pype.Clicker wrote:@all: anyone knows of a open-source easy-to-use floppy image one could use for step C. other than digging for MS-DOS 6.22 boot floppy ?
You could use FreeDOS. Other than (i.e. non-OSS) that head over to here and zipped images are under "Non-Windows Based Image Files W/ImageApp". The images are intended for system recovery stuff.
xyjamepa

Re:now what

Post by xyjamepa »

first of all i used my own bootloader and i'm using windows as
an operating system and i used virsual pc as an emulator...
*what is the Grub?
*where can i get it from?
*how can i use it under windows platform?
*my HDD file system will be FAT32....
thanx...
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:now what

Post by Solar »

Hmm... please visit the "Quick Links" sticky thread in this forum, and the "mega-tokyo.com" banner on top (-> OS FAQ), to find the information this community has assembled over time. Both links are also available from my signature.
Every good solution is obvious once you've found it.
xyjamepa

Re:now what

Post by xyjamepa »

sorry guys but that didn't help so...
lets ask the question agin..
how can i write my own bootloader to the HDD and make it
loadable?
i used the bootloader program to write my own bootloader to the FDD can i do the same thing with HDD?
what do you think?
note :
i used the FAT12 file system and i am doing all that under windows.
thanx...
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:now what

Post by Solar »

"That didn't help"? ::)
Every good solution is obvious once you've found it.
chasetec

Re:now what

Post by chasetec »

Having just answered this queistion some where else I believe the OP is asking how to write his boot loader and maybe other files into his virtual disk image.

If you are using Fat12 you'll only be able to have a 32meg hard drive(or partition if you want to make a mbr too).

The easiest thing to do to test you boot sector as a hard drive is just compile your code to a binary file. In your virtual machine software configure a raw(no compression or special) disk image that is your binary.

You can also copy you compiled code on top of your virtual disk image. Under linux you do this with "dd". I think you might be able to with debug but it'd be better if you get a copy of dd for windows(cygwin software maybe).

The problem is going to be how you get your virtual image updated with other files. Unless you write code that writes the Fat12 filesystem and your compiled files you will need to have Windows mount the disk image so you can copy things into it. Under Unix OSes you can do this easy with a loopback device, I'm not sure how it would be dealt with under Windows.
viral

Re:now what

Post by viral »

hello..
If your question is "how to copy 512 byte bootsector to real hdd or an hdd image?" then "partcopy" can serve the purpose. You can find it on osdever.net.

If you want to make a hdd image & format it for FAT under Windows, then you can do one thing:

* Make a DOS disk image having fdisk, format utilities.
* Boot from this disk under an emulator like Qemu.
* fdisk & format the hdd image.

If you want to copy your files in an hdd image under Windows, then VFD (Virtual Floppy Drive) can serve the purpose.

Note: plz be specific in your subject.. it should be something like "How to copy mbr to hdd?" and not "now what?"
xyjamepa

Re:now what

Post by xyjamepa »

okay.....
when i worked with the FDD i was writng the next command:
bootloader boot.bin a:
that command was copying my bootloader wich called here
"boot.bin" to the FDD
and then i copy my kernel to the FDD
so can i do the same with HDD
and i guess you know that the bootloader here is a program.
sorry ...next time i'm ganna try to be more specific.
viral

Re:now what

Post by viral »

Hello...
Is your OS, bootloader specific? I mean are you doing some initialization in bootloader.. Well I suggest you to load your OS using GRUB. Dont make it too dependent on bootloader.
I guess you are in early stage of development, so use GRUB. It will reduce a lot of complexity and even multiboot support enables you to boot from hdd. I still recommended you what Solar had pointed out: USE GRUB
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:now what

Post by Pype.Clicker »

i think what he means here is that "bootloader" is the name of a tool that copy a file onto the bootsector of a disk in his building process...
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:now what

Post by kataklinger »

abuashraf wrote: so can i do the same with HDD
So you need something like PARTCOPY... But under Win XP it won't work. So I wrote my own utility for this purpose, but Windows alway restores old bootsector and I didn't find solution for this problem, well if I restart computer just after I write new bootsector :D.
Post Reply