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

mount vdi vhd files #268

Open
Keops10 opened this issue Dec 11, 2022 · 39 comments
Open

mount vdi vhd files #268

Keops10 opened this issue Dec 11, 2022 · 39 comments

Comments

@Keops10
Copy link

Keops10 commented Dec 11, 2022

Hi I am using Discutils library.
I can read the contents of my files with .vdi-.vdh-.vdhx extensions.
However, I want to copy these files or add them to the computer as a drive and copy them, is it possible?

@LTRData
Copy link

LTRData commented Dec 11, 2022

Not through the DiscUtils library itself. It is possible though for example Arsenal Image Mounter where we use DiscUtils library as backend when you mount certain image file formats.

@Keops10
Copy link
Author

Keops10 commented Dec 11, 2022

Yes I tried with Arsenal Imager. However, I think it does not support the file belonging to applications such as virtualbox.

@LTRData
Copy link

LTRData commented Dec 12, 2022

Yes I tried with Arsenal Imager. However, I think it does not support the file belonging to applications such as virtualbox.

It should support all image formats supported by DiscUtils. Did you see any issues with some format?

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

Yeah. virtual box does not open image files (.vdi) and bluestacks (.vhdx)

@LTRData
Copy link

LTRData commented Dec 12, 2022

Yeah. virtual box does not open image files (.vdi) and bluestacks (.vhdx)

I am not sure I follow. I regularly use AIM to mount vdi, vhdx, vmdk etc images myself. It uses DiscUtils library to parse such image files and then another driver to expose them as virtual disks to the system.

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

you misunderstood me. I can read with DiscUtils but not mount with Arsenal

@LTRData
Copy link

LTRData commented Dec 12, 2022

you misunderstood me. I can read with DiscUtils but not mount with Arsenal

Yes and that is what surprised me. Arsenal Image Mounter should support all image formats supported by DiscUtils, because it uses DiscUtils to parse the image files. Did you get any error messages when you tried? Or what more exactly happened?

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

https://ibb.co/xCMfG78 https://ibb.co/C63d6rk Yes, it shows as added, even in disk manager, but I can't see it on my computer.

@LTRData
Copy link

LTRData commented Dec 12, 2022

https://ibb.co/xCMfG78 https://ibb.co/C63d6rk Yes, it shows as added, even in disk manager, but I can't see it on my computer.

Is it really a partition scheme and file system that is supported by Windows? I mean, if you would have attached a physical disk with the same contents to a Windows machine, would it have been possible to browse the file systems in Windows in that case?

If it is not a Windows compatible file system in your images, you cannot directly mount the images as virtual disks in this way in Windows. You would need some kind of file system emulation layer as well. I have a project like that over at my fork of dokan-dotnet. It uses DiscUtils libraries not only to parse disk contents but also to access the file systems in the disk images and then it uses Dokan virtual file system driver to mount them as virtual file systems. They will not show up as disks in Disk Management and not accessible to applications looking for physical disks in any way, but it is possible to browse such file systems in Explorer in Windows.
https://github.com/LTRData/dokan-dotnet/tree/LTRData.DokanNet-initial/DiscUtilsFs

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

Thank you very much for writing so descriptively. Also, thank you for your interest. I think I understood where the problem is. As you said yes, if windows is a drive, it can display it as a disk. Since my vhdx is in Ext4 format, this is how I see it. I did some research in it and found the SharpExt4 library, but I'm not sure it will work. Sorry for my bad english.

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

While Vhdx can be read with DiscUtils, shouldn't I export the contents?

@LTRData
Copy link

LTRData commented Dec 12, 2022

Can you show me how you can do it

If you build DiscUtilsFs from that dokan-dotnet fork, you can do:
DiscUtilsFs -where=D: -vhd=c:\path\to\image.vdi

You need to install Dokan first:
https://github.com/dokan-dev/dokany/releases

@LTRData
Copy link

LTRData commented Dec 12, 2022

Dokan is actually quite simple. The DiscUtilsFs project I linked to shows how to do it. You basically wrap a DiscUtils IFileSystem instance in a DokanDiscUtils object and then call Dokan API to mount it as a virtual file system. But you need to install Dokan driver too, that is why I linked to Dokan release pages too. You do not need to build it, just install it.

On the other hand, if all that you are looking for here is to copy files from a file system recognized by DiscUtils libraries, you do not really need a virtual file system or a drive letter visible in Windows Explorer. You could simply open each file in your foreach loop there like fs.OpenFile(name, FileMode.Open, FileAccess.Read) and the create a target file somewhere else and call CopyTo to copy source file data to destination file.

@LTRData
Copy link

LTRData commented Dec 13, 2022

Change

fs.OpenFile(name, FileMode.Open, FileAccess.Read);
System.IO.File.Copy(name, @"D:\", true);

To

using var sourceStream = fs.OpenFile(name, FileMode.Open, FileAccess.Read);
using var targetStream = System.IO.File.OpenWrite(@"D:\" + name);
sourceStream.CopyTo(targetStream);

You don't need Dokan for this. It does not mount as virtual disk or file system in any way. It just reads and copies data directly.

@Keops10
Copy link
Author

Keops10 commented Dec 13, 2022

dude you are amazing thank you for helping me patiently. Finally, I have one more question to ask var disk = new DiscUtils.Xva.Disk(secilen.Text, System.IO.FileAccess.Read);

When I make DiscUtils.Xva here, I see that the code is not working, where do you think I am going wrong? Also I need to do this in iso and img.

@LTRData
Copy link

LTRData commented Dec 13, 2022

dude you are amazing thank you for helping me patiently. Finally, I have one more question to ask var disk = new DiscUtils.Xva.Disk(secilen.Text, System.IO.FileAccess.Read);

When I make DiscUtils.Xva here, I see that the code is not working, where do you think I am going wrong? Also I need to do this in iso and img.

You should really avoid specifying class of virtual disk in this way in your use case.

Use the methods described here to use all available format support:
https://github.com/DiscUtils/DiscUtils

Then, VirtualDisk.OpenDisk etc methods that will find correct library automatically.

@Keops10
Copy link
Author

Keops10 commented Dec 13, 2022

I want to display the structure I read in the treeview content. But I found that it doesn't read folder by folder in the loop. How can I do that.I can't thank you enough.

@LTRData
Copy link

LTRData commented Dec 13, 2022

I want to display the structure I read in the treeview content. But I found that it doesn't read folder by folder in the loop. How can I do that.I can't thank you enough.

There are other methods like GetDirectories instead of GetFiles for that. You probably need to go down each directory and enumerate files there too etc.

@Keops10
Copy link
Author

Keops10 commented Dec 13, 2022

I am using Xaml. How can I number each directory, can you show me on my sample code above? It returns a directory instead of a folder in the loop. I guess my logic wasn't enough :(

@LTRData
Copy link

LTRData commented Dec 13, 2022

I am using Xaml. How can I number each directory, can you show me on my sample code above? It returns a directory instead of a folder in the loop. I guess my logic wasn't enough :(

Sorry, I cannot write the entire program for you. I think you need to ask someone more familiar with XAML/WPF etc for such questions. It is a bit out-of-scope for DiscUtils.

@Keops10
Copy link
Author

Keops10 commented Dec 29, 2022

Hello, with the method you have shown, I can easily copy a virtual machine image in windows structure to windows. The problem is that when I want to copy the contents of an image with a linux image to windows, I encounter errors due to filenames (* ? | < > :) how can I solve this?

@EricZimmerman
Copy link

Search for those illegal Characters and replace them on the new name

@Keops10
Copy link
Author

Keops10 commented Dec 29, 2022

yes i tried that. 'replace'
But the line I'm having trouble with is :fs.OpenFile(name, FileMode.Open, FileAccess.Read);

I guess it can't read because I read it on windows

@EricZimmerman
Copy link

Ext? Install a driver for ext and then mount it normally and things should just work to copy from what I recall

@Keops10
Copy link
Author

Keops10 commented Dec 29, 2022

You're right, but to speed things up, I want to get around this problem without mounting.

@Keops10
Copy link
Author

Keops10 commented Dec 29, 2022

I even took the risk of incomplete copying. fs.OpenFile(name.Replace('*', '_'), FileMode.Open, FileAccess.Read); I tried 'catch (FileNotFoundException)' but the result did not change. It seems to be working without any errors but I've checked that it's not copying. the problem persists.

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

Can I copy the image without decompressing?

@LTRData
Copy link

LTRData commented Dec 30, 2022

We have made lots of changes in the LTRData fork of DiscUtils regarding file name and symbolic link compatibility. Have you tried it and it does not work there either for some reason, I can take a look at why and how it happens and make a fix for it.

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

Thanks for the fix, I really need it. How soon will you fix it? Also, if you have the opportunity to try, can you try to read an image with .vmdk extension, is there a problem with my vmdk?

@LTRData
Copy link

LTRData commented Dec 30, 2022

No, I meant that you could try first with the LTRData.DiscUtils fork of this repository. That will probably help because I recognize this kind of issues as something we had when we developed File system bypass mount mode in Arsenal Image Mounter. We managed to fix most of it by emulating slightly changed file names etc to make it work on Windows systems. But then if you see similar issues when using that fork too, then I can try to fix it.

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

sourceStream.CopyTo(targetStream); > System.IO.IOException: 'Unable to find extent for block 0'
I'm getting an error and the problem persists when I pass this error with try I have the same problem in LTRData (I installed it as nuget)

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

Yes I've seen LTRData fix special characters. Strangely, I found it stuck on a file with the .version extension, and when I told it to skip it, it worked fine.

@LTRData
Copy link

LTRData commented Dec 30, 2022

sourceStream.CopyTo(targetStream); > System.IO.IOException: 'Unable to find extent for block 0'
I'm getting an error and the problem persists when I pass this error with try I have the same problem in LTRData (I installed it as nuget)

That looks interesting. Do you know what kind of file that was? Anything special with it? Is it an image that you could share somewhere?

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

https://ibb.co/wsTW9fM Of course... I guess it has something to do with null content.

@Keops10
Copy link
Author

Keops10 commented Dec 30, 2022

Then DiscUtils.Vmdk.Disk(textbox.Text, System.IO.FileAccess.Read); I detected that it is not reading the vmdk image.

@LTRData
Copy link

LTRData commented Dec 30, 2022

https://ibb.co/wsTW9fM Of course... I guess it has something to do with null content.

Sorry for the confusion! I meant, the image file that you are trying to read files from, is that an image that you could share somewhere?

@Keops10
Copy link
Author

Keops10 commented Dec 31, 2022

If I can reach you privately, this could be it.

@LTRData
Copy link

LTRData commented Dec 31, 2022

If I can reach you privately, this could be it.

Yes no problem. E-mail me at olof@ltr-data.se

@Keops10
Copy link
Author

Keops10 commented Dec 31, 2022

okey. I sent an e-mail.

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

3 participants