Page 1 of 1
Talking VirtualBox into running my boot code
Posted: Sun Jan 12, 2014 1:42 pm
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.
Re: Talking VirtualBox into running my boot code
Posted: Sun Jan 12, 2014 2:03 pm
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
Re: Talking VirtualBox into running my boot code
Posted: Mon Jan 13, 2014 2:23 am
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?
Re: Talking VirtualBox into running my boot code
Posted: Mon Jan 13, 2014 2:48 am
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.