Page 1 of 1

Copy boot sector to HDD [edit: Booting under Virtual PC]

Posted: Thu Apr 21, 2005 6:02 pm
by Kemp
Hi, I had a search on Google and on here, but couln't find out how to copy a boot sector to a hard drive. There's about a million pages saying how to copy it to a floppy, but that's not what I want to do. I did some checking up on commands and as far as I know the following should work (assuming Boot.img is a 512 byte binary with no header junk or anything):

C:\>DEBUG Boot.img
-D
[address loaded at here] [hex values here]
-W [address] 3 0 1
-Q

(Choosing 3 because it's drive D)

I tried this under Virtual PC (as none of my drives are expendable right now) and got the message "Missing Operating System". Anyway, my question here is basically, is it a problem with my boot sector code rather than the method I used to get it onto the (virtual) disk?

Thanks for bothering to read all this.

Re:Copy boot sector to HDD

Posted: Thu Apr 21, 2005 6:35 pm
by Warrior

Re:Copy boot sector to HDD

Posted: Fri Apr 22, 2005 4:12 am
by Kemp
Thanks for the link. Strangely enough that's a site I was browsing a while back but I lost the bookmark since then somehow.

Re:Copy boot sector to HDD

Posted: Fri Apr 22, 2005 4:25 am
by Kemp
Ok, now getting

"Reboot and Select proper Boot device
or Insert Boot Media in selected Boot device"

which is a new message to me, but at least I can now assume I'm copying it correctly. I expected a message like this, now to add the finishing touches to the code.

Re:Copy boot sector to HDD

Posted: Fri Apr 22, 2005 8:27 am
by Dex4u
If you go here: http://alexfru.chat.ru/epm.html#bootprog
and get "bootprog.zip" in that zip is these programs.

GETBOOTH.EXE reads a boot sector from a HDD and saves to a specified file
SETBOOTH.EXE writes a boot sector to a HDD from a file
BOOTHDD.EXE makes your HDD bootable with my cool boot sector.

All come with source code.
Hope this helps.

Re:Copy boot sector to HDD

Posted: Fri Apr 22, 2005 10:29 am
by Kemp
Ok, stripped the boot sector down (was fun selecting it all and hitting delete ;D Saved elsewhere of course) to one that basically does nothing for the purposes of seeing if it would actually work under virtual pc and it does just that, nothing... it wasn't meant literally ::)

Code: Select all

.386P

CSEG   SEGMENT WORD 'Code' USE16
   ASSUME CS:CSEG, DS:CSEG, ES:Nothing

ORG   0h

JMP SHORT StartBoot
NOP

; Boot sector info start

[[Boot sector info goes here]]

StartBoot:
   MOV AH, 0Eh
   MOV BX, 0007
   MOV AL, 77h
   INT 10h
   MOV AL, 30h
   INT 10h
   MOV AL, 30h
   INT 10h
   MOV AL, 74h
   INT 10h
   HLT

Padding      DB   486 DUP (0)
BootSig      DD   0AA550000h

CSEG   ENDS
END
That should print the four characters shown to the screen, right?

Re:Copy boot sector to HDD [edit: Booting under Virtual PC]

Posted: Sat Apr 23, 2005 8:10 am
by Kemp
Still can't get that going. I don't see where the problem could be, there isn't exactly much code there to fail. No disk or memory accesses, no playing with pointers and offsets, just sticking fixed values in registers and calling int 10. ???

Edit:
Ok, kinda fixed. Turns out interrupts are disabled by default, whereas I thought they were enabled by default (never came into it before as the first thing I always did was disable them while I mess around with important things). Now I just need to find out why that code is executed three times in a row...

Edit 2:
That appears to be either a Virtual PC issue or a wierd gap in my knowledge (one among many), if I disable interrupts before the HLT then it's run once as it's meant to be.