This project is read-only.

Is it possible to write custom MBR when creating a virtual disk

Mar 9, 2009 at 10:16 AM
Hi everyone,
I know this might sound a bit hard but i am trying to create a project template that automatically generates a virtual hard disk using vhd or vmdk format that has a custom written boot sector since i have written my own bootloader and would like to boot it.
Is it possible to re-write the MBR for the disk image or manipulate it?
Any replies are appreciated.
Mar 10, 2009 at 2:58 AM
For VHD and VMDK, you can access the disk.Content member to get a Stream that represents the contents of the disk.  Simply write your MBR to the start of the stream.

Mar 10, 2009 at 9:43 AM
Hi Ken,
Thnx for the reply,
gonna try this today and tell u whether works or not.

Mar 16, 2009 at 4:01 AM
There's a tool for doing this in the MOSA project ( called MakeBootImage. We use it to build VHD and VMDK disk images for our OS.
Mar 17, 2009 at 5:12 PM
Very cool stuff MOSA.

Just a note for anyone trying to access the disk through the Content property - quite often the stream will not be at the start.  All access to the disk content goes through a single stream, so if you've accessed the disk in anyway through the partition table / filesystem, you'll likely find the stream position in the middle of the disk somewhere.

disk.Content.Position = 0
Will get you to the MBR.