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

Could not read disk MBR error #11

Closed
Keops10 opened this issue Dec 12, 2022 · 9 comments
Closed

Could not read disk MBR error #11

Keops10 opened this issue Dec 12, 2022 · 9 comments

Comments

@Keops10
Copy link

Keops10 commented Dec 12, 2022

Hello
I mount a Linux-based virtual machine (vhdx) with the arsenal mounter. I see this added in Disk management I want to access this disk with Sharpext4 and read and copy it I couldn't find how to do it. I used the code below but I get the Could not read disk MBR error.

private void Mountet_Click(object sender, RoutedEventArgs e)
{
//Open a Linux ext4 disk image
var disk = ExtDisk.Open(1);
//Get the Linux partition, and open
var fs = ExtFileSystem.Open(disk, disk.Partitions[0]);
//List all files in /etc folder
foreach (var file in fs.GetFiles("/etc", "*", SearchOption.AllDirectories))
{
Console.WriteLine(file);
}
} }

@nickdu088
Copy link
Owner

You need to convert the virtual machine (.vhdx) format to the raw disk format.

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

Can you give an idea on how I can do this?

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

Yep, it doesn't seem to work for me. Actually, I can read the paths of the files with DiscUtils, but I need to export these files. Any idea how it could be?

@nickdu088
Copy link
Owner

If you can use diskutils, you should be able export those files without any issue. Diskutils only provides read permission only from the disk image, but not write.

SharpExt4 allows you to write a file to the disk image.

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

I am reading with this code. If I make any changes to this code, I can export it.

 var disk = new DiscUtils.Vhdx.Disk(secilen.Text, System.IO.FileAccess.Read);
                    DiscUtils.FileSystems.SetupHelper.SetupFileSystems();
                    var manager = new VolumeManager(disk);
                    var logicalVolumes = manager.GetLogicalVolumes();
                    foreach (var volume in logicalVolumes)
                    {
                        var fsInfos = FileSystemManager.DetectFileSystems(volume);

                        foreach (var fsInfo in fsInfos)
                        {
                            var fs = fsInfo.Open(volume);

                            string[] array2 = fs.GetFiles(fs.Root.Name, "*.*", SearchOption.AllDirectories);
                            foreach (string name in array2)
                            {
                                listbox.Items.Add(name);
                            }
                        }
                    }

@nickdu088
Copy link
Owner

listbox.Items.Add(name)
//Open file and read the content from the name
...

@Keops10
Copy link
Author

Keops10 commented Dec 12, 2022

I don't think it's possible with something like this, but I tried it anyway.

string dd = listbox.SelectedItem.ToString();
FileStream fs = File.Open(dd,FileMode.Open);

@nickdu088
Copy link
Owner

You can't just use File.Open(dd,FileMode.Open). That is the.net native way. You need use diskutils API to open the file. Check diskutils file open API.

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