Page 1 of 1

Error loading OS from USB

Posted: Tue Apr 23, 2013 9:04 am
by jsnider3
I'm trying to write a bootloader that prints a character to the screen and then sits there. I'm working with the following code and since it's 512 bytes after assembly I think that part is working right. I've got it to the point that when the USB is selected as the boot medium it will crash with "Error loading operating system" instead of "Could not Find Operating System".

Code: Select all

[BITS 16]	;Tells the assembler that its a 16 bit code
[ORG 0x9000]	;0x7C00 and 0x9000 are equally ineffective values to put here.

mov ax, 0x0000
mov ds, ax	;Set ds to 0
MOV AL, 65
CALL PrintCharacter
JMP $ 		;Infinite loop, hang it here.

PrintCharacter:	;Procedure to print character on screen
MOV AH, 0x0E	;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00	;Page no.
MOV BL, 0x07	;Text attribute 0x07 is lightgrey font on black background
INT 0x10	;Call video interrupt
RET		;Return to calling procedure

TIMES 510 - ($ - $$) db 0	;Pad the code with zeros.
DW 0xAA55			;Put the boot signature in bytes 510 and 511.
I expect that the problem is how I'm copying the program to the USB. Since I'm working on a 64 bit windows machine, I originally tried typing "partcopy boot.bin 0 200 -f0" which runs without printing an error message but doesn't work, I tried typing " dd if=C:/boot.bin bs=512 of=E:/" in cygwin but that told me that E was a directory and did nothing, I also tried "cp C:/boot.bin E:/" which runs without an error message, but doesn't work. Any other ideas?

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 9:20 am
by iansjack
http://stackoverflow.com/questions/1894 ... ck-or-disk

Be very careful! It's obvious that you have no idea what you are doing and getting things wrong will probably make your computer unbootable.

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 9:28 am
by jsnider3
iansjack wrote:http://stackoverflow.com/questions/1894843/how-can-i-put-a-compiled-boot-sector-onto-a-usb-stick-or-disk
I've seen that thread before. The top rated answer suggests using dd, which I've already mentioned didn't work.

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 9:36 am
by iansjack
Read that thread again and you will see where you went wrong. You have to dd to the device, not the root folder of the drive.

From what you have said so far I would advise you to not try this as there is a real danger of overwriting important parts of your hard disk. Why not use a virtual machine and a virtual floppy disk instead? You will find that much safer (and much easier).

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 10:23 am
by jsnider3
iansjack wrote:Read that thread again and you will see where you went wrong. You have to dd to the device, not the root folder of the drive.
Oh. I tried that before but it gave me an "Operation not permitted" error message, trying it again as an administrator fixes the error message but doesn't get it to boot.
From what you have said so far I would advise you to not try this as there is a real danger of overwriting important parts of your hard disk. Why not use a virtual machine and a virtual floppy disk instead? You will find that much safer (and much easier).
I'll probably give a virtual machine a try. Anything wrong with using this tutorial as a guide?

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 1:19 pm
by iansjack
The article that you linked to seems to give a good introduction (although I haven't actually worked through it). Give it a try and see how it goes.

Re: Error loading OS from USB

Posted: Tue Apr 23, 2013 3:44 pm
by turdus
Oh man, you're a lot of work.

Code: Select all

[ORG 0x9000]   ;0x7C00 and 0x9000 are equally ineffective values to put here.
Think it again. First mistake here.

And where's your stack btw? And what about cpu flags? Does stack grow upwards or downwards?

Code: Select all

dd if=C:/boot.bin bs=512 of=E:/
told me that E was a directory
Yeah, cygwin is absolutely correct, why on earth do you want to write a boot record on a directory? What's the difference between E: and E:/...?

Re: Error loading OS from USB

Posted: Wed May 01, 2013 3:23 am
by osdog
jsnider3 wrote:I've seen that thread before. The top rated answer suggests using dd, which I've already mentioned didn't work.
You are doing it wrong!

From the thread:
use it like so:

dd if=c:\my files\boot.bin of=\\.\z: bs=512 count=1
Your attempt:
jsnider3 wrote:dd if=C:/boot.bin bs=512 of=E:/
Spot the difference?

Here is a good tutorial (first thing one finds when searching for dd windows help on Google!) on dd: http://uranus.chrysocome.net/linux/rawwrite/dd-old.htm

Anyway if your "code" was written correctly to the device it will boot but likely triple fault and reset the machine because of the insufficiencies that turdus pointed out.