nickdu088 / SharpExt4

A .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem
https://www.nickdu.com/?p=890
40 stars 8 forks source link

Cannot mount ext4 partition #4

Closed Rampftl closed 2 years ago

Rampftl commented 2 years ago

Hi,

i am testing your lib with an external ext4 disk on a usb hard disk. Under Windows 10 I plugged in the usb disk. Then I used diskpart to determine the disk number (in my case 8). I changed the Sample code to:

//Open a Linux ext4 disk image
 //var disk = ExtDisk.Open(@".\ext4.img");
var disk = ExtDisk.Open(8);
foreach(var part in disk.Partitions)
{
    Console.WriteLine("part = " + part.ToString());
}
...

Sample.exe returns an exception:

C:\Users\mic\source\repos\SharpExt4\Sample\bin\Debug>Sample.exe
part = SharpExt4.Partition
part = SharpExt4.Partition
part = SharpExt4.Partition
part = SharpExt4.Partition

Unbehandelte Ausnahme: System.IO.IOException: Could not mount partition.
   bei SharpExt4.ExtFileSystem.Open(Partition partition) in C:\Users\mic\Source\Repos\SharpExt4\SharpExt4\ExtFileSystem.cpp:Zeile 219.
   bei Sample.Program.Main(String[] args) in C:\Users\mic\Source\Repos\SharpExt4\Sample\Program.cs:Zeile 48.

Interesting is, that the disk seems to contain four partitions, but the usb disk just has one partition on it. So I assume, that the physical Disk number may not be the one which diskPart is showing me. I checked with wmic as well. The disk index für the usb disk is 8.

Do you have an idea what goes wrong?

Best Mic

nickdu088 commented 2 years ago

Hi Mic,

  1. Did you follow these steps? You have to ensure the admin permission.
  2. Did you use the correct disk number? From the error, it seems not EXT4 file system. Disk number "8" seems not correct. Normally, PC has 4 SATA ports and few USB ports. Are you sure you have 8 physical disks installed?

Best regards,

Nick

Rampftl commented 2 years ago

Hi Nick,

its correct, I have 8 Disks on my machine (XEON Workstation with 10 Sata Ports) I admit this is not a mainstream computer :) I did the steps you mentioned in 1), but it seems that I have a PlatformToolset issue. V142 is missing on my computer. I found this after abandoning Visual Studio and starting Jetbrains Rider. The error messages there are far more understandable.

I will try to fix this and come back to you with the result asap.

Best regards Mic

Rampftl commented 2 years ago

Hi Nick, sorry not replying for so long. I was absorbed by other parts of my project. Now I am back on the Linux issue. I guess my problem is, how i compile. When compiling the lwext4 lib a lot of conversion warnings arrise with lots of "possible loss of data". My properties in VS2019: Windows SDK Version 10.0 Platform Toolset Visual Studio 2019 (v142) C++ Language Standard ISO C++ 14 C Language Standard Legacy MSVC

How are your settings when compining and building the Sample App?

Best Mic

nickdu088 commented 2 years ago

Hi Nick, sorry not replying for so long. I was absorbed by other parts of my project. Now I am back on the Linux issue. I guess my problem is, how i compile. When compiling the lwext4 lib a lot of conversion warnings arrise with lots of "possible loss of data". My properties in VS2019: Windows SDK Version 10.0 Platform Toolset Visual Studio 2019 (v142) C++ Language Standard ISO C++ 14 C Language Standard Legacy MSVC

How are your settings when compining and building the Sample App?

Best Mic

It shouldn't be a problem. Can you try another PC with fewer disks or follow the steps earlier?

Rampftl commented 2 years ago

I have a laptop and will try this.

Rampftl commented 2 years ago

Hi Nick, finally I managed to run the Sample on my laptop. For that I modified the Sample Program.cs to access a physical disk:

Program.cs.txt

My laptop has a gpt formatted disk 0 with partitions for Windows and linux and a mbr formatted disk 1 with one windows partition on it.

Calling the sample.exe for disk 0 I get:

C:\Users\Mic\RiderProjects\SharpExt4\Sample\bin\Debug>Sample.exe 0 1 Partition 0 : SharpExt4.Partition EXCEPTION: Could not mount partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition.

Only four partitions are found, but the disk contains more partitions: `DISKPART> sel disk 0

Datenträger 0 ist jetzt der gewählte Datenträger.

DISKPART> list part

Partition ### Typ Größe Offset


Partition 1 System 190 MB 1024 KB Partition 2 Reserviert 128 MB 191 MB Partition 3 Primär 156 GB 319 MB Partition 4 Primär 67 GB 156 GB Partition 5 Unbekannt 1907 MB 223 GB Partition 6 Unbekannt 119 GB 225 GB Partition 7 Unbekannt 119 GB 345 GB Partition 8 Unbekannt 238 GB 464 GB Partition 9 Primär 230 GB 702 GB Partition 10 Wiederherstellun 990 MB 933 GB Partition 11 Wiederherstellun 18 GB 933 GB Partition 12 Wiederherstellun 1644 MB 952 GB`

Partition 10,11 and 12 are from the Laptop Manufacturer. Partition 5,6,7,8 are the Linux partitions which I want to mount Partition 3,4,9 are the Windows partitions (Windows 10)

So the question is: Is there a problem when building the lib and the exe (when compiling I got a lot of conversion warnings)? Do I access the disk in a wrong way?

Best Mic

nickdu088 commented 2 years ago

I haven't tested for Linux on gpt disk. You can try a USB flash drives with Linux partition.

Rampftl commented 2 years ago

I created an MBR formatted USB stick with one ext4 partition on it with my linux system. Then I booted Windows again and plugged in the stick. Using the Sample.exe gives: C:\Users\Mic\RiderProjects\SharpExt4\Sample\bin\Debug>Sample.exe 2 1 Partition 61529391104 : SharpExt4.Partition EXCEPTION: Could not mount partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition.

Now I can see the size of the partition, but again it lists me 4 partition even if there is only one on the disk. And a mount is not working: "EXCEPTION: Could not mount partition"

nickdu088 commented 2 years ago

I created an MBR formatted USB stick with one ext4 partition on it with my linux system. Then I booted Windows again and plugged in the stick. Using the Sample.exe gives: C:\Users\Mic\RiderProjects\SharpExt4\Sample\bin\Debug>Sample.exe 2 1 Partition 61529391104 : SharpExt4.Partition EXCEPTION: Could not mount partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition. Partition 0 : SharpExt4.Partition EXCEPTION: Could not register partition.

Now I can see the size of the partition, but again it lists me 4 partition even if there is only one on the disk. And a mount is not working: "EXCEPTION: Could not mount partition"

I don't know how you make the USB. Can you download the Raspberry Pi image and burn to USB?