Booting HD

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.
Post Reply
bc

Booting HD

Post by bc »

What is involved in getting a bootable hard drive as opposed to floppy?What do I need to do to make an OS boot from C drive?
Peter_Vigren

Re: Booting HD

Post by Peter_Vigren »

Well... If the hard drive doesn't have a master boot sector (see * below), you will have to write one to head 0, cylinder 0, sector 1. After that, you have to create a valid partition (see ** below) and make it active. Both of the above things can be done using fdisk or something like that but you might want to write your own program. When that is done... you have to have a boot sector on that partition. This is the easiest part because the boot sector on the partition is nearly the same as the one at a floppy (however, if you use FAT12 on the floppy and FAT16 on the partition, the part reading the files have to be different of course).

See http://www.mcc.ac.uk/grub/grub_23.html#SEC62 for some information about the master boot sector and partition table.

* = The master boot sector contains a program (at the most 446 bytes) and a partitiontable (see ** below) and the Master Boot Sector signature. The program checks which of the partitions (see ** below) that is active and then loads the partitions boot sector into memory and executes it. I don't remember the signature right now but I can post it later if I find out which one it is...

** = In the partition table there are 4 slots for partitions. In other words, 4 partitions can be set up (if you don't count extended partitions... but that is another story which isn't important in this case). The structure of a partition slot is somewhat like this (All lines is one byte):

Status
First Head?
First Sector?
First Cylinder?
Type
Last Head?
Last Sector?
Last Cylinder?
Starting LBA
Starting LBA
Starting LBA
Starting LBA
Size in sectors
Size in sectors
Size in sectors
Size in sectors

- Status is whether or not the partition is active or not. The byte is zero if it isn't, else bit 7 is set (80h).
- The "First x" (the start of the partition) is what the the program in the master boot sector will use with Int 13h to read the bootsector into memory. However, I am not completely sure about the sequence "Head, Sector, Cylinder"...
- Type is which kind of partition it is. Like if it is a DOS FAT12 the byte is 01h. Or if it is a Windows 95 FAT32 it is 0Bh
- The "Last x" is the end of the partition...
- Starting LBA is the where the start of the partition is in LBA-mode (how many)
- Size in sectors is pretty self-explanatory, don't you think?
bc

Re: Booting HD

Post by bc »

Thanks. My main reason for asking is that I recently built a second computer and intend to use it as a test platform. I would like to work directly with the hard drive of the test machine. I will most likely use fdisk to set it up for me, with the whole drive being one primary partition.
I have a sample code that will write a bootsector into a floppy. It is written in C++. Can it be modified to write to a hard disk? Here is the code.

//***************START****************
#include <bios.h>
#include <stdio.h>

void main()
{
       FILE *in;
       unsigned char buffer[520];

       if((in = fopen("bootcode", "rb"))==NULL)
       {
               printf("Error loading file\n");
               exit(0);
       }

       fread(&buffer, 512, 1, in);

       while(biosdisk(3, 0, 0, 0, 1, 1, buffer));

       fclose(in);
}
//*************END****************************

What it does it write from hd to fd a:. Can it be modified to do the opposite? I will need to develop on my main PC, and then transfer my work via floppy.
avinash

Re: Booting HD

Post by avinash »

i think this is the solution ...

instead of biosdisk(3,0,0.....)

use biosdisk(1,0,0,0...)

i think this will write it to hdd ...

tell me if it works ..

luv

avinash
BC

Re: Booting HD

Post by BC »

Thanks for the tip, but it did not seem to work. I have found another solution, so I am no longer too concerned.

What happened when I made the changes you suggested was that the computer showed hd activity, so it seems to have written something out, but when I reset to test, the pc totally ignored the bootsector, so it must not have ended up in the right place.
Post Reply