I've got a custom boot loader and I would like to be able to boot my system with some VM (VirtualBox, VMware, etc).
Just in case of testing purposes the kernel is currently abandoned. So actually the only thing this boot loader does - is printing a string (using some bios interruptions). That's the only thing I want to be working right now. So...
First of all I've tried to make raw write of this boot loader (or perhaps boot "printer" ) to the beginning of VirtualBox's virtual drive file (*.vdi). But no success, since *.vdi files have their own structure and a header. I'm not really keen to dig into this structure, because there no proper documentation on it.
Secondly I've tried VMware. VMware's emulated hard drives seem to be purely mapped into *.vmdk files and therefore *.vmdk files do not have any headers or structure. So I did the same (wrote the first 512 bytes of boot loader into it). But when I start VM just nothing happens, and even carret does not blink - looks like VM freezes or whatever.
I would like to know if anyone has done similar tricks and succeeded. The problem is - I don't want to mess with that floppy stuff. Is there another way to test boot loader and operating system development in general, like the one I'm proposing in this topic.
Thanks in advance.
[SOLVED] Testing with VM and Custom Boot Loader
[SOLVED] Testing with VM and Custom Boot Loader
Last edited by Haroogan on Tue Aug 09, 2011 4:55 pm, edited 1 time in total.
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Testing with VM and Custom Boot Loader
If you want to use a hard disk image, you could try to use bochs. It supports flat binary images and comes with some simple documentation (chapter 8 is on disk images):
http://bochs.sourceforge.net/doc/docboo ... index.html
These flat binary disk images should work with other VMs as well, but I have not tried that so far. (I'm using floppy and CD images.)
Using a CD image is another possibility. There are also some tutorials in the wiki:
Mkisofs
Bootable CD
http://bochs.sourceforge.net/doc/docboo ... index.html
These flat binary disk images should work with other VMs as well, but I have not tried that so far. (I'm using floppy and CD images.)
Using a CD image is another possibility. There are also some tutorials in the wiki:
Mkisofs
Bootable CD
Re: Testing with VM and Custom Boot Loader
Best option? Use the first few bytes of a floppy image. Everybody uses a flat file for virtual floppies, since there is no point in saving space from a 1.44MB image.
VMware's format isn't flat. There is an API for it with sample code and I think it documents the formats. But digging through formats from various virtualization platforms is overkill for what you are doing. Most of them have a FUSE-based mechanism for mounting the disk on Linux, at which point you can write directly.
http://www.vmware.com/support/developer/vddk/
VMware's format isn't flat. There is an API for it with sample code and I think it documents the formats. But digging through formats from various virtualization platforms is overkill for what you are doing. Most of them have a FUSE-based mechanism for mounting the disk on Linux, at which point you can write directly.
http://www.vmware.com/support/developer/vddk/
Re: Testing with VM and Custom Boot Loader
Thanks guys I really appreciate your feedback. I totally agree with kscguru about the overkill and that's why I started this post.
Ok, so, I've created flat disk image with bximage utility as XenOS suggested. Please have a look at current state:
1. Bochs config
2. Boot loader
Compiled with NASM into binary file of 512 bytes.
Then I've wrote a simple Java utility to copy raw bytes from one file to another and used it to copy from compiled boot file to the first 512 bytes of MyOS.img file. Still no string output:
Am I doing something wrong? Maybe some problem with endianess? Should I write boot loader in little-endian or big-endian style into MyOS.img?
P. S. I've just found out that when I give Bochs empty (zeroed) MyOS.img - he quits with something like "No bootable device". But when I give him MyOS.img with boot loader (written by my Java utility) - he does not quit but shows "Booting from hard disk..." - like on the screenshot. So it seems like I'm on the right way, but still why the string does not output?
Ok, so, I've created flat disk image with bximage utility as XenOS suggested. Please have a look at current state:
1. Bochs config
Code: Select all
#----------------------------------------------------------------------------------------------------
# BIOS
#----------------------------------------------------------------------------------------------------
romimage: file=BIOS-bochs-latest, address=f0000 #0xdffff
vgaromimage: file=VGABIOS-lgpl-latest
#----------------------------------------------------------------------------------------------------
# Hard Drive
#----------------------------------------------------------------------------------------------------
ata0-master: type=disk, path="MyOS.img", mode=flat, cylinders=8, heads=16, spt=63
#----------------------------------------------------------------------------------------------------
# Boot
#----------------------------------------------------------------------------------------------------
boot: disk
#----------------------------------------------------------------------------------------------------
# Logging
#----------------------------------------------------------------------------------------------------
log: MyOS.log
error: action=report
info: action=report
Code: Select all
msg db "Welcome to My Operating System!", 0
;***************************************
; Prints a string
; DS=>SI: 0 terminated string
;***************************************
Print:
lodsb
or al, al ; al=current character
jz PrintDone ; null terminator found
mov ah, 0eh ; get next character
int 10h
jmp Print
PrintDone:
ret
;*************************************************;
; Bootloader Entry Point
;*************************************************;
loader:
xor ax, ax ; Setup segments to insure they are 0. Remember that
mov ds, ax ; we have ORG 0x7c00. This means all addresses are based
mov es, ax ; from 0x7c00:0. Because the data segments are within the same
; code segment, null em.
mov si, msg
call Print
cli ; Clear all Interrupts
hlt ; halt the system
times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0
dw 0xAA55 ; Boot Signiture
Then I've wrote a simple Java utility to copy raw bytes from one file to another and used it to copy from compiled boot file to the first 512 bytes of MyOS.img file. Still no string output:
Am I doing something wrong? Maybe some problem with endianess? Should I write boot loader in little-endian or big-endian style into MyOS.img?
P. S. I've just found out that when I give Bochs empty (zeroed) MyOS.img - he quits with something like "No bootable device". But when I give him MyOS.img with boot loader (written by my Java utility) - he does not quit but shows "Booting from hard disk..." - like on the screenshot. So it seems like I'm on the right way, but still why the string does not output?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Testing with VM and Custom Boot Loader
boot sector byte 0: text data.
when interpreted as an instruction: garbage
when interpreted as an instruction: garbage
Re: Testing with VM and Custom Boot Loader
Ok, NVM I did it
Thanks everyone!
Thanks everyone!