{"id":1044,"date":"2022-11-06T17:45:51","date_gmt":"2022-11-06T22:45:51","guid":{"rendered":"https:\/\/www.ecsdump.net\/?p=1044"},"modified":"2022-11-06T17:45:51","modified_gmt":"2022-11-06T22:45:51","slug":"vdi_info","status":"publish","type":"post","link":"https:\/\/www.ecsdump.net\/?p=1044","title":{"rendered":"vdi_info"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">General<\/h3>\n\n\n\n<p>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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/BIOS_parameter_block\" data-internallinksmanager029f6b8e52c=\"4\" title=\"BPB\" target=\"_blank\" rel=\"noopener\">BPB<\/a> 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Specifics<\/h3>\n\n\n\n<p>Again, this tool is to make my life easier. Currently, I use <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/open-watcom\/open-watcom-v2\/wiki\" data-type=\"URL\" data-id=\"https:\/\/github.com\/open-watcom\/open-watcom-v2\/wiki\" target=\"_blank\">Open Watcom v2<\/a> maintained by Ji\u0159\u00ed Mal\u00e1k. 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.<\/p>\n\n\n\n<p>My build flow is to compile my boot loader on a 32bit system, transfer the boot loader to a vdi image, and boot via <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/bochs-emu\/Bochs\" data-type=\"URL\" data-id=\"https:\/\/github.com\/bochs-emu\/Bochs\" target=\"_blank\">bochs<\/a> 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.<\/p>\n\n\n\n<p>Code repo:   <a rel=\"noreferrer noopener\" href=\"https:\/\/gitlab.com\/mikeos2\/vdi_info\" data-type=\"URL\" data-id=\"https:\/\/gitlab.com\/mikeos2\/vdi_info\" target=\"_blank\">Gitlab<\/a>  or  <a rel=\"noreferrer noopener\" href=\"https:\/\/greenenet.ddns.net\/misc_public\/vdi_info\" data-type=\"URL\" data-id=\"https:\/\/greenenet.ddns.net\/misc_public\/vdi_info\" target=\"_blank\">My Gitlab<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How it works<\/h3>\n\n\n\n<p>The command line options are if you run <strong>vdi_info -h<\/strong> :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vdi_info: get dev image vdi information.\nVersion 1.0, compiled Nov  5 2022 with OpenWatcom 2.0\n\nusage: vdi_info &#91;-f alt filename]&#91;-i]&#91;-m]&#91;-p]&#91;-w] vdi_filename\n\n   -f #  alternate input filename for -w option.\n   -i    Dump BPB inc to bootpbp.inc.\n   -m    Dump MBR to mbr.bin.\n   -b    Dump active BPB to bpb.bin.\n   -w    Write newmbr.bin to active BPB.\n   -h    help message.\n\nValid option combinations:\n  1. -m, -b, or -i single or all at once to dump MBR, BPB and INC.\n  2. -w only or with optional -f &lt;filename&gt; for alternate BPB image to add.<\/code><\/pre>\n\n\n\n<p>The output with vdi name input results in some info about the image:<\/p>\n\n\n\n<p><em><strong>vdi_info fat16drive.vdi<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Info: Input file found (fat16drive.vdi) and opened.\n\n&lt;&lt;&lt; Oracle VM VirtualBox Disk Image &gt;&gt;&gt;\nImage Version: 1.1\nImage Sig: BEDA107F\nHeader size: 190\nDrive Start: 200000\nMBR Sig: AA55 Valid MBR signature!\n\nPart num  1\nState: 80\nHead:  1\nEnd:   1\nType:  6\nHead:  F\nEnd:   CD3F\nOff:   3F\nSect:  32AE1\n\nPart num  2\nState: 0\nHead:  0\nEnd:   0\nType:  0\nHead:  0\nEnd:   0\nOff:   0\nSect:  0\n\nPart num  3\nState: 0\nHead:  0\nEnd:   0\nType:  0\nHead:  0\nEnd:   0\nOff:   0\nSect:  0\n\nPart num  4\nState: 0\nHead:  0\nEnd:   0\nType:  0\nHead:  0\nEnd:   0\nOff:   0\nSect:  0\n\nActive partition 1 found at offset 3F\nBoot sector VDI offset:  2129408\n\nAll done!<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">-m<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">-b<\/h3>\n\n\n\n<p>The MBR is scanned for the first active partition and extracted. <span style=\"font-size: revert; color: initial;\">If the -b option is passed, then write the BPB of the first active partition to a file named bpb.bin.<\/span>    <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">-i<\/h3>\n\n\n\n<p>So, here is the real use for this tool. When <strong>vdi_info -i &lt;vdi file&gt;<\/strong> is executed it outputs <em>bootpbp.inc<\/em>. Why did I name the output <em>bootpbp.inc<\/em> ? Who knows, I was probably tired or dyslexic. Anyway, I should really change it to <em>bootbpb.inc<\/em>. 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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; *** BPB output of vdi_info *** \n\nBS_OEMName      db  'MSDOS5.0'\n\nBPB_BytsPerSec \tdw  0X0200\nBPB_SecPerClus \tdb  0X04\nBPB_RsvdSecCnt \tdw  0X0001\nBPB_NumFATs    \tdb  0X02\nBPB_RootEntCnt \tdw  0X0200\nBPB_TotSec16    dw  000000\nBPB_Media       db  0XF8\nBPB_FATSz16 \tdw  0X00CB\nBPB_SecPerTrk   dw  0X003F\nBPB_NumHeads    dw  0X0010\nBPB_HiddSec     dd  0X0000003F\nBPB_TotSec32 \tdd  0X00032AE1\n\nBS_DrvNum       db  0X80\nBS_Reserved1    db  0000\nBS_BootSig      db  0X29\nBS_VolID        dd  0X2A6316E8\nBS_VolLab       db  'TESTDRV    '\nBS_FilSysType   db  'FAT16   '\n\n; *** end of BPB output ***<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">-w<\/h3>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>General 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&hellip;<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/www.ecsdump.net\/?p=1044\" title=\"Continue reading &lsquo;vdi_info&rsquo;\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,12],"tags":[20,98,71],"class_list":["post-1044","post","type-post","status-publish","format-standard","hentry","category-boot-process","category-watcom","tag-boot","tag-boot-sector","tag-watcom"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/posts\/1044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1044"}],"version-history":[{"count":0,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/posts\/1044\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}