VHD format?

Bas
Top Contributor
Posts: 545
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 69 times
Been thanked: 251 times

VHD format?

Unread post by Bas »

Hey all. How far does the AO486 core actually follow Microsoft's VHD format specifications? I'm working on some software that needs to manipulate VHD-images for this core. Apart from the fact that the specs by MS are sparse, I'm getting good results from AO486 by simply handing it a file containing nothing but zeroes with a .vhd extension. I guess the main question is: can I get away with the latter?
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: VHD format?

Unread post by jca »

I don't think there is a specification for VHDs. It is just a big file. If it contains only zeroes it will be an uninitialized disk and you will have to use fdisk and format. More generally if it does not contains the mbr and partition table it will be considered uninitialized.
Bas
Top Contributor
Posts: 545
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 69 times
Been thanked: 251 times

Re: VHD format?

Unread post by Bas »

Oh there is, Microsoft publishes one that holds a header, a copy of the footer which actually holds some metadata like CHS, and a Block Allocation Table (that I've yet to figure out how to fill). The spec is here: https://www.microsoft.com/en-us/downloa ... x?id=23850

However: AO486 seems to completely ignore all of this but I'm not sure in how far that's true.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: VHD format?

Unread post by jca »

Thanks and good to know.
I made the following test:
Under MISTer
I created a 100MB file named Test.vhd using dd.
I started AO486 with a DOS floppy and Test.vhd as the first HD.
I used FDISK to create a partition, formatted it using format c: /s and copied all the dos files to it.
I unmounted the floppy and booted from Test.vhd without any problem.
I copied Test.vhd to my PC.
On the PC
I used Disk Management to attach the VHD: it failed with the same error as the Windows 9X vhds from fpgafan.
I even tried to create a VM using VirtualBox: it also did not like the VHD.
Today I learned 2 things:
You have to create your AO486 VHDs under Windows.
Fpgafan created his VHDs under MISTer.

Edit: You have to create them under Windows if you want to be able to use them under Windows. If you never plan to use them under Windows it does not matter.
Bas
Top Contributor
Posts: 545
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 69 times
Been thanked: 251 times

Re: VHD format?

Unread post by Bas »

Rephrasing that: Windows most likely creates a VHD according to spec and expects any incoming ones to behave as such. Linux's dd command just creates a dummy file with nothing/garbage in it, that AO486 then happily consumes and MS-DOS fdisk will even partition, format and then boot from.. but at the end of the day it's not really a compliant VHD at all regardless of filename extension. Assumption: AO486 does *nothing* on its own to make this bare file into a compliant VHD.

VHD's originally created by Windows will be spec-compliant (to a point.. knowing Microsoft), work in MiSTer, and Windows will accept them back as long as nothing mangles the header/footer structures.. which is unlikely because these parts are small and usually out of the way from anything writing to a filesystem inside a formatted MBR partition inside the image file. So, rephrasing my previous assumption: that's more a matter of luck than anything else.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: VHD format?

Unread post by jca »

I just made a 100MB VHD under Windows, it is 512 Bytes bigger and I suppose it is at the end of the file.
I did not read yet the paper you linked to but the abstract stated:
"This paper describes the different virtual hard disk formats supported by Microsoft Virtual PC and Virtual Server".
So I suppose this extra data is only used by VMs and MISTer does not care about that, it just wants a raw disk image which it finds and does not care about this extra data.
I still recommend to create these VHDs under Windows.
Bas
Top Contributor
Posts: 545
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 69 times
Been thanked: 251 times

Re: VHD format?

Unread post by Bas »

I don't have Windows around here but I'd like to know what it makes of a VHD as created by Oracle VirtualBox. Would you be able to test that? I'm reading the source code to that product's VHD-creator and it appears to be following spec properly. Now before I start *cough* borrowing heavily from that implementation I'd really like to know if Windows actually accepts these VHD's or not.

A side-effect of what I'm doing here could very well be a small self-contained command line tool for the MiSTer that actually creates compliant VHD's without needing Windows (or VirtualBox for that matter).
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: VHD format?

Unread post by jca »

VirtualBox can use VHDs so I guess it will be OK.
VirtualBox cannot directly create VHDs but can convert VDIs to VHDs.
On my PC I only have Linux VDIs. I converted one to VHD and was able to attach it with Disk Management. It has 2 partitions, the first one being a 512MB FAT32 partition which has been mounted as E: drive and is empty. I am not sure what is this partition but Windows had no problem with this VHD.
As you say a Linux tool could be written to create Windows VHDs. Just before you posted I was looking on the internet to see if such a tool existed, it does not. There are a lot of posts where people want to create Win XP VHDs to use on Linux using VM and there exist tools but they are not what we want to accomplish.
zakk4223
Posts: 270
Joined: Sun May 24, 2020 10:55 pm
Been thanked: 107 times

Re: VHD format?

Unread post by zakk4223 »

I don't see anything in the IDE code that cares about the VHD footer. All the geometry calculations are done based on file size and some default sector/per track, heads etc values.
df843
Posts: 14
Joined: Wed Sep 01, 2021 4:02 am
Has thanked: 2 times

Re: VHD format?

Unread post by df843 »

jca wrote: Sun Sep 26, 2021 1:18 pm Thanks and good to know.
I made the following test:
Under MISTer
I created a 100MB file named Test.vhd using dd.
I started AO486 with a DOS floppy and Test.vhd as the first HD.
I used FDISK to create a partition, formatted it using format c: /s and copied all the dos files to it.
I unmounted the floppy and booted from Test.vhd without any problem.
I copied Test.vhd to my PC.
On the PC
I used Disk Management to attach the VHD: it failed with the same error as the Windows 9X vhds from fpgafan.
I even tried to create a VM using VirtualBox: it also did not like the VHD.
Today I learned 2 things:
You have to create your AO486 VHDs under Windows.
Fpgafan created his VHDs under MISTer.

Edit: You have to create them under Windows if you want to be able to use them under Windows. If you never plan to use them under Windows it does not matter.
I too have had my Ao486 core with windows 98 installed from Fpgafan vhd. The problem is it was created with only 400mb which limits its functionality and capability to install stuff to. Since windows does not recognize this VHD, is there a way to expand it on mister to, say 2 GB? Have been trying but VHD manipulations always seems to rely on windows tools
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: VHD format?

Unread post by jca »

Have a look there and posts around it.
viewtopic.php?p=34057#p34057
df843
Posts: 14
Joined: Wed Sep 01, 2021 4:02 am
Has thanked: 2 times

Re: VHD format?

Unread post by df843 »

jca wrote: Mon Sep 27, 2021 1:41 am Have a look there and posts around it.
viewtopic.php?p=34057#p34057
Thanks for the help :) will try this!
Bas
Top Contributor
Posts: 545
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 69 times
Been thanked: 251 times

Re: VHD format?

Unread post by Bas »

So in conclusion AO486 does not need VHD's at all, just raw disk images. A lot of confusion comes from the fact that these are not the same thing. Software that actually expects a VHD will choke on a raw disk image from AO486. The other way around works but only by sheer luck.

The Linux dd command does not create valid VHD files nor does AO486 make any effort to fix anything about that after the fact.

I know enough and will proceed with raw images.
Post Reply