So you want your OS to start without the support of GRUB and other like bootloaders, am I corect ?
In that case what you need is :
- to write your bootsector to MBR [MasterBootRecord]
BUT take care ! MBR contains all the partition information about the drive ! You need to rewrite the bootsector with your own bootsector but PRESERVING the Partition Tables otherwise you will loose your drive !
You should use an USB stick, an OLD harddisk, a virtual drive but never try this on your real computer as long as you are noob ...[otherwise you will distroy your partition tables]
technical part:
the MASTER BOOT RECORD sector stucture :
at byte 0x03 start the boot_sector standard record [after which it maybe the boot_sector_extended record]:
Code: Select all
Type boot_sector Field = 1
OEM_Identifier(1 To 8) As ubyte
BytesPerSector As ushort
SectorsPerCluster As UByte
ReservedSectors As ushort
NumberOfFATs As ubyte
RootEntries As ushort
NumberOfSectors As ushort
MediaDescriptor As ubyte
SectorsPerFAT As ushort
SectorsPerHead As ushort
HeadsPerCylinder As ushort
HiddenSectors As UInteger
BigNumberOfSectors As UInteger
BigSectorsPerFAT As UInteger
ExtFlags As UShort
FSVersion As ushort
RootDirectoryStart As UInteger
FSInfoSector As UShort
BackupBootSector As UShort
End Type
Const boot_sector_ext_16= &h25
Const boot_sector_ext_32= &h41
Type bootsect_ext Field = 1
BIOS_drive_number As UByte
Reserved As UByte
Extended_Boot_Record_signature As UByte '= 29h
Serial_Number As UInteger
Volume_label(1 To 11) As ubyte
System_Identifier(1 To 2) As UInteger
End Type
the partition_tables start at byte : 0x1BE
(1st) partition record at : 0x1BE
(2nd) partition record at : 0x1CE
(3rd) partition record at : 0x1DE
(4th) partition record at : 0x1EE
the partition record :
Code: Select all
Type partition_table Field =1
Boot_indicator As ubyte
Beginning_head_number As ubyte
Beginning_sector_and_high_cylinder_number As UByte
Beginning_low_cylinder_number As UByte
System_indicator As UByte
Ending_head_number As ubyte
Ending_sector_and_high_cylinder_number As ubyte
Ending_low_cylinder_number As ubyte
Number_of_sectors_preceding_the_partition As UInteger 'or LBA start
Number_of_sectors_in_the_partition As UInteger 'or LBA length
End Type
------------------------------------
A tool that writes a new bootsector to the MBR needs to preserves these records :
boot_sector,boot_sector_extended, partition_tables [1 to 4];
the rest of space is yours !
the first 3 bytes in the sector represents a "jump assembly instruction" to the boot sector code [will make cpu jump over boot_sector record to the boot sector code];
the few next sectors after the MBR are used by the boot_loaders to store additional code
[it can uses up to [partition_table[0].Number_of_sectors_preceding_the_partition]
I once used a tool called BOOTABLE.EXE to safely integrate my own BOOTSECTOR inside the MBR... [but I don't garantee for it; you should read it's docs first]
see ya ! happy coding