This is a utility of need. I needed to get info from a virtualbox vdi image so that I could modify the boot sector. By modify, I mean to dump the required BPB info to an include file and graft my compiled oemboot boot sector on to the vdi. I did this a year ago and it has been used via a makefile since. What this means is I need to go back and figure out everything it does.
Again, this tool is to make my life easier. Currently, I use Open Watcom v2 maintained by Jiří Malák. I compile it on a 32bit system, either an old Win XP image or a ReactOS image. I assume it would compile on AcraOS, I just have not tried to do so. I have only been using FAT16 because it is simple, and I just wanted to get things running.
My build flow is to compile my boot loader on a 32bit system, transfer the boot loader to a vdi image, and boot via bochs from Linux. To get the boot loader in memory, I use a custom boot sector named oemboot (I know, not very original). Without going into details, a vdi has a different structure than a normal hard drive image and it is tedious to extract the vdi information to an include file (BPB include) and, after compiling oemboot, writing the boot sector back to the vdi. The result was this tool that made the task easier when swapped to a new vdi or write a new boot sector to my dev image.
Be careful, while I put the repo together, I already see things I need to fix. Not big things, but mistakes that happen in a hurry. For example, in the v1.0 source if WRITEBPB is true I should skip the input file check until later. Oops.
How it works
The command line options are if you run vdi_info -h :
vdi_info: get dev image vdi information. Version 1.0, compiled Nov 5 2022 with OpenWatcom 2.0 usage: vdi_info [-f alt filename][-i][-m][-p][-w] vdi_filename -f # alternate input filename for -w option. -i Dump BPB inc to bootpbp.inc. -m Dump MBR to mbr.bin. -b Dump active BPB to bpb.bin. -w Write newmbr.bin to active BPB. -h help message. Valid option combinations: 1. -m, -b, or -i single or all at once to dump MBR, BPB and INC. 2. -w only or with optional -f <filename> for alternate BPB image to add.
The output with vdi name input results in some info about the image:
Info: Input file found (fat16drive.vdi) and opened. <<< Oracle VM VirtualBox Disk Image >>> Image Version: 1.1 Image Sig: BEDA107F Header size: 190 Drive Start: 200000 MBR Sig: AA55 Valid MBR signature! Part num 1 State: 80 Head: 1 End: 1 Type: 6 Head: F End: CD3F Off: 3F Sect: 32AE1 Part num 2 State: 0 Head: 0 End: 0 Type: 0 Head: 0 End: 0 Off: 0 Sect: 0 Part num 3 State: 0 Head: 0 End: 0 Type: 0 Head: 0 End: 0 Off: 0 Sect: 0 Part num 4 State: 0 Head: 0 End: 0 Type: 0 Head: 0 End: 0 Off: 0 Sect: 0 Active partition 1 found at offset 3F Boot sector VDI offset: 2129408 All done!
Read the vdi and get what is expected to be the MBR and check for a valid signature. If the -m option is passed then write the MBR to a file named mbr.bin.
The MBR is scanned for the first active partition and extracted. If the -b option is passed, then write the BPB of the first active partition to a file named bpb.bin.
So, here is the real use for this tool. When vdi_info -i <vdi file> is executed it outputs bootpbp.inc. Why did I name the output bootpbp.inc ? Who knows, I was probably tired or dyslexic. Anyway, I should really change it to bootbpb.inc. Passing -i goes through all the step above, read MBR, scan for first active partition, load the BPB of that partition, and dump it to an include file. The following is the output for my current development image.
; *** BPB output of vdi_info *** BS_OEMName db 'MSDOS5.0' BPB_BytsPerSec dw 0X0200 BPB_SecPerClus db 0X04 BPB_RsvdSecCnt dw 0X0001 BPB_NumFATs db 0X02 BPB_RootEntCnt dw 0X0200 BPB_TotSec16 dw 000000 BPB_Media db 0XF8 BPB_FATSz16 dw 0X00CB BPB_SecPerTrk dw 0X003F BPB_NumHeads dw 0X0010 BPB_HiddSec dd 0X0000003F BPB_TotSec32 dd 0X00032AE1 BS_DrvNum db 0X80 BS_Reserved1 db 0000 BS_BootSig db 0X29 BS_VolID dd 0X2A6316E8 BS_VolLab db 'TESTDRV ' BS_FilSysType db 'FAT16 ' ; *** end of BPB output ***
This finds the active partition and writes a new boot sector from the file named newbpb.bin or the file name passed with the -f option.