Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does DiscUtils support convert VHDX to VHD? #293

Open
LunfanZhang opened this issue Feb 23, 2024 · 12 comments
Open

Does DiscUtils support convert VHDX to VHD? #293

LunfanZhang opened this issue Feb 23, 2024 · 12 comments

Comments

@LunfanZhang
Copy link

LunfanZhang commented Feb 23, 2024

as title, Does DiscUtils support convert a VHDX image into VHD?

@LTRData
Copy link

LTRData commented Feb 23, 2024

Yes. You can for example open a VHD file and create a new VHDX file with the same size and copy all data between them.

@LunfanZhang
Copy link
Author

I am not a VHDX or VHD expert, but from my view, if the VHDX and VHD has different formats with different capabilities or structures, is it OK to just directly copy the data from VHDX to VHD?

@LTRData
Copy link

LTRData commented Feb 23, 2024

If you open the VHD with DiscUtils using VirtualDisk.OpenDisk and read data from the stream that you get from the Contents property, you will get the virtual disk data in the image. Not the image file format itself. So, if you then create a VHDX using VirtualDisk.CreateDisk you can write to the contents stream in a similar way. If you copy all image contents from the source contents stream to the target content stream, you effectively convert the image to another format.

@LunfanZhang LunfanZhang changed the title Does DisUtils support convert VHDX to VHD? Does DiscUtils support convert VHDX to VHD? Feb 26, 2024
@LunfanZhang
Copy link
Author

Does DiscUtil support merge VHDX chain? is there any interface to do that?

@LTRData
Copy link

LTRData commented Mar 1, 2024

Does DiscUtil support merge VHDX chain? is there any interface to do that?

No, this is not implemented. It can only be done by converting to a new file, not in place.

@LunfanZhang
Copy link
Author

LunfanZhang commented Mar 6, 2024

@LTRData But, when I use VirtualDisk.OpenDisk to open a .avhdx file, I notice it will follow the chain relationship to find the base parent VHDX image, I`m not sure if there is some merging operation involved or not. but anyway it seems like the final content had been opened include both chain and base contents.

@LTRData
Copy link

LTRData commented Mar 6, 2024

Ah, yes that it correct. The result that you see is that image file contents merged with parents etc.

Sorry, I first thought you meant merging like in writing data from a differencing image back into parent image.

@LunfanZhang
Copy link
Author

Hello @LTRData , I hope you're doing well. Apologies for reaching out once more, but I would appreciate your assistance with a quick clarification. Could you please confirm if the stream opened with VirtualDisk inDisk = VirtualDisk.OpenDisk(source_file, FileAccess.Read, username, password) includes both differencing and base image content?

The reason for my inquiry is that I've created a chain with some additional files, but when I start a VM with this opened stream, it seems that the additional files are not included. Your insights would be greatly appreciated. Thank you very much for your time and assistance.

@LTRData
Copy link

LTRData commented Apr 18, 2024

If you specify the differencing file in your call to VirtualDisk.OpenDisk, it should include both parent and differencing data. If you specify the parent file, only parent data before the differencing image was created should be visible.

@LunfanZhang
Copy link
Author

LunfanZhang commented Apr 18, 2024

As we discussed above, I call VirtualDisk.OpenDisk to open a differencing file (e.g. .ahvdx), and call HTTP interface to import the stream to a VHD file, will the differencing data lose?

@LTRData
Copy link

LTRData commented Apr 18, 2024

I am sorry, but I do not understand what "the HTTP interface" refers to here.

If you open a .avhdx file and create a new .vhd image, and then you copy stream contents from .Contents property of the differencing image to the .Contents property of the target vhd image, then you will get all data from the differencing image combined with the parent image file. Just like when the differencing image file is used by a virtual machine.

@LunfanZhang
Copy link
Author

The issue is resolved, really appreciate for your help :-) @LTRData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants