here is another question connected with the boot sector. if i want to transfer my self made boot sector to the hard disk and overwrite my original mbr how should i save the partition table in the new mbr so the disk would be readable? my intention is to overwrite the mbr so the partitions and all the information stay untouched. best regards,


:manchev
Posted on 2003-05-29 19:49:32 by manchev
while i won't give any solutions for fear of screwing something up, i highly recommend you back everything up first, anyway...

and/or use a virtual machine to test this stuff.
Posted on 2003-05-29 20:37:27 by jademtech
i am using vmware and i know what i am doing so don't worry :) so, any solution?




:manchev
Posted on 2003-05-29 20:58:01 by manchev
hi manchev, i guess you're familiar already with mbr structure, dont you?
once long time ago, i had a problem with my harddisk that one of its partition is gets deleted accidentally, and guess what, i read the mbr info from msdn and fix it with a hex editor that have capability to edit hd directly. and finally i did save it and glad with it. i thought you can alter the "entry point" to your new mbr and...
Posted on 2003-05-29 21:44:54 by dion
If you are just testing your boot sector you don't need to override the mbr;
(Boot sequence is mbr->bootsector->..)
If you still intend to do so, I guess it is a good idea to copy you partition
table to it. If you don't, you'll lose the partition;
That's why I also reccomend making a backup:tongue:

Now about your question: HOW should you save the partition table
Answer: Just like the one in your current mbr

You can create you're own partition table, but the problem is that your operating system (Windows/Linux) doesn't know the size etc of your partitions anymore

http://www.nondot.org/sabre/os/files/Booting/mbr.txt

You can use debug or int 0x13 to read/write these sectors
Posted on 2003-05-29 23:56:30 by Guerrilla
The Linux command dd can be used to read and write HD sectors. Remember that /dev/hda is the whole drive and /dev/hda1 is a partition.
Posted on 2003-05-30 01:23:39 by eet_1024
Hi,

simply copy the bytes from 01BEh .. 01FEh from original MBR
to your new one. But check first, that your new boot code isn't
that large that you touch the space beyond 01BEh. Is so, you
have to optmize your code (not speed but size)

Bye Miracle
Posted on 2003-05-30 04:05:27 by miracle
thank you guys, especially miracle. i highly appreciate your invaluable help! thanks again!




:manchev
Posted on 2003-05-30 15:27:00 by manchev
do you think this code will do the work i want to:
-------------------------------------------------------------



cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti

read:
mov ah,02h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x0600
int 13h

copy_pt:
mov ax,0x0000
mov es,ax
mov ds,ax
mov si,0x07be
mov di,0x7dbe
mov cx,40h
repz movsb

mov ax,0x0000
mov es,ax
mov di,0x7dbe
mov cx,04h

active_check:
mov ax,word
add word ,0010h
cmp ax,80h
jnz active_check
jz load_boot
repz

load_boot:
mov si,0
mov di,0200h
mov cx,0200h
repz movsb
jmp read_boot + 200h

read_boot:
mov ah,02h
mov al,01h
mov ch,byte
mov cl,byte
mov dh,byte
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h

write_mbr:
mov ah,03h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7c00
int 13h

jmp 0x0000:0x7C00

times 510-($-$$) db 0
dw 0AA55h

-------------------------------------------------------------
i wrote it yesterday and compiled it with nasm - it doesn't return any errors, but i don't dare to try it. it is supposed to do the following:
1. reads the hdd mbr at 0x0600
2. copy partition table of loaded hdd mbr to the right place in the current boot sector
3. checks for an active partition
4. finds the first sector of this partition
5. moves itself to another location, so
6. it can load the bootsector from step 4 at this address [0x7c00]
7. and finally execute it with jmp 0x0000:0x7c00
-------------------------------------------------------------
if i'm not right and not doing it the right way please tell me. if someone dares to test - ok. i'll be very interested in the results, or if you think the code is making the things i pointed out above in the right way and does not wipes the partition table or something i'll be the first to try it. the source can be downloaded at: http://manchev.data.bg/bs.asm and the bin file is here: http://manchev.data.bg/bs.bin :)
thanks for the patience!


:manchev
Posted on 2003-05-31 15:59:28 by manchev