Talking VirtualBox into running my boot code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Thargon
Posts: 2
Joined: Sun Dec 22, 2013 3:54 am

Talking VirtualBox into running my boot code

Post by Thargon »

After a few days of relearning and refreshing, I finally managed to write my own boot sector, which by now is only able to write lines on the screen (Hello, world! :-) ). Now the plan is:

- write a second stage boot code
- gather all possible info from BIOS then jump to 64-bits mode
- write a minimal kernel and a simple UI

So far so good, but it would be faster to be able to run (and debug) the boot code using a virtual machine, and since I am forced to have windows on my development box (please don't ask), it looks like my best option is to use VirtualBox. Now the question is: is there a simple and quick way to make VB boot a VM using a custom MBR?

Thanks in advance.
In a world with no fences and no walls we would need no Gates and no Windows.- Hui Yuan
User avatar
Combuster
Member
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: Talking VirtualBox into running my boot code

Post by Combuster »

The MBR is always on a disk. For things like floppies, you can just point virtualbox at your floppy image. If you need a harddisk, you can convert from the flat images that you can use with pretty much every other tool that's not a VM.

Before you get that far, you will need to get yourself a copy of dd for windows so you can easily make images of arbitrary sizes as well as copy individual sectors (read: MBR) or whole partitions.

Code: Select all

dd if=/dev/zero of=disk.img bs=512 count=<<number_of_sectors>>
dd if=mbr.bin of=disk.img bs=512 count=1 conv=notrunc
#convert disk.img to vm image if needed here
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Thargon
Posts: 2
Joined: Sun Dec 22, 2013 3:54 am

Re: Talking VirtualBox into running my boot code

Post by Thargon »

First of all, thank you for your prompt reply, it was very useful.
Combuster wrote:The MBR is always on a disk. For things like floppies, you can just point virtualbox at your floppy image. If you need a harddisk, you can convert from the flat images that you can use with pretty much every other tool that's not a VM.
Before you get that far, you will need to get yourself a copy of dd for windows so you can easily make images of arbitrary sizes as well as copy individual sectors (read: MBR) or whole partitions.
The last working FD drive seen around here was in another century. Booting from USB sticks (which OSes see as HD) is the trick nowadays. Anyway VB can use VHD virtual drives (raw disk images according to hex/disk editor) which can be saved from the disk editor or created by win7 disk manager. If one wants to use some other virtual disk format, VB provides a conversion utility (VBoxManage). After some tries, VB was able to boot from the .vhd file. The adventure continues...

Maybe an entry to wiki's FAQ about the subject at hand could be useful?
In a world with no fences and no walls we would need no Gates and no Windows.- Hui Yuan
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Talking VirtualBox into running my boot code

Post by iansjack »

Thargon wrote:Maybe an entry to wiki's FAQ about the subject at hand could be useful?
It's a wiki, so feel free to create such an entry.
Post Reply