How do I find a partition while in WSL2?
How do I find a partition while in WSL2?
Hi, I'm using WSL2 as my programming environment and was wondering if this would cause issues when trying to partition the disk to read and write to it. So I have a few questions in regard to partitioning the disk.
First, should I partition the disk on my windows machine, or on the virtual disk? When looking at the partition table, is it a separate one for WSL or is it the same one as windows? (I tried to find what partition WSL was on, but I must not understand how it works because I could not find one).
Mainly, what's the process to making sure my OS is able to find a partition on the hard disk if it is running from WSL?
I'm sorry if I did not phrase that very well.
First, should I partition the disk on my windows machine, or on the virtual disk? When looking at the partition table, is it a separate one for WSL or is it the same one as windows? (I tried to find what partition WSL was on, but I must not understand how it works because I could not find one).
Mainly, what's the process to making sure my OS is able to find a partition on the hard disk if it is running from WSL?
I'm sorry if I did not phrase that very well.
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
Which disk are you trying to partition?
Re: How do I find a partition while in WSL2?
STOP, STOP, STOP!!!
Don’t mess with partitions if you are not absolutely sure what you are doing. (And it is obvious that you aren’t.)
Don’t touch your physical hard disk; create a virtual hard disk and use that. In Linux you would access this via a loop back device - a little Googling will provide a wealth of detail about this.
Don’t mess with partitions if you are not absolutely sure what you are doing. (And it is obvious that you aren’t.)
Don’t touch your physical hard disk; create a virtual hard disk and use that. In Linux you would access this via a loop back device - a little Googling will provide a wealth of detail about this.
Re: How do I find a partition while in WSL2?
Thanks, I'll do that instead.iansjack wrote:STOP, STOP, STOP!!!
Don’t mess with partitions if you are not absolutely sure what you are doing. (And it is obvious that you aren’t.)
Don’t touch your physical hard disk; create a virtual hard disk and use that. In Linux you would access this via a loop back device - a little Googling will provide a wealth of detail about this.
Re: How do I find a partition while in WSL2?
I created a virtual hard disk using this command:
And am running the OS with this:
But when writing to the disk using my ata driver (the code is below) and restarting the OS, the virtual hard disk does not save my changes. Is there a reason that this is happening?
The ataPioWrite() function to write to hard disk:
Code: Select all
qemu-img create -f raw disk.img 2000M
Code: Select all
qemu-system-i386 -hda disk.img -cdrom Binaries/caffieneOS.iso -m 16M -boot order=dc
The ataPioWrite() function to write to hard disk:
Code: Select all
void ataPioWrite(unsigned int LBA, unsigned short sectorcount, unsigned char *target) {
outportb(ATA_PRIMARY_DRIVE_HEAD, 0x40); // Select master
outportb(ATA_PRIMARY_SECCOUNT, (sectorcount >> 8) & 0xFF); // Sector Count hi
outportb(ATA_PRIMARY_LBA_LO, (LBA << 24) & 0xFF); // LBA4
outportb(ATA_PRIMARY_LBA_MID, (LBA << 32) & 0xFF); //LBA5
outportb(ATA_PRIMARY_LBA_HI, (LBA << 40) & 0xFF); // LBA6
outportb(ATA_PRIMARY_SECCOUNT, sectorcount & 0xFF); // Sector Count low
outportb(ATA_PRIMARY_LBA_LO, LBA & 0xFF); // LBA1
outportb(ATA_PRIMARY_LBA_MID, (LBA << 8) & 0xFF); //LBA2
outportb(ATA_PRIMARY_LBA_HI, (LBA << 16) & 0xFF); // LBA3
outportb(ATA_PRIMARY_COMM_REGSTAT, 0x34); // WRITE SECTORS EXT command
for (unsigned char i = 0; i < sectorcount; i++) {
pollATA(); // Wait for it to be able to transfer data
// Transfer the data
for (int j = 0; j < 256; j++) { outportl(ATA_PRIMARY_DATA, target[i]); }
target += 256;
}
// Flush the cache.
outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);
// Poll for BSY.
while (inportb(ATA_PRIMARY_COMM_REGSTAT) & STAT_BSY) {}
}
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
Do you see any compiler warnings? If not, turn on compiler warnings, then fix the mistakes in your code that cause the warnings to appear.
Do you see any QEMU warnings?
Which direction does "<<" shift the bits?
What size is the data port? What size does outportl write? What size is target?
Do you see any QEMU warnings?
Which direction does "<<" shift the bits?
What size is the data port? What size does outportl write? What size is target?
Re: How do I find a partition while in WSL2?
I've fixed all of the compiler warnings, so no luck with thatOctocontrabass wrote:Do you see any compiler warnings? If not, turn on compiler warnings, then fix the mistakes in your code that cause the warnings to appear.
Yes, the warning is:Octocontrabass wrote:Do you see any QEMU warnings?
Code: Select all
WARNING: Image format was not specified for 'disk.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
I was shifting them the wrong way, thanks for catching that.Octocontrabass wrote:Which direction does "<<" shift the bits?
Octocontrabass wrote:What size is the data port? What size does outportl write? What size is target?
And here is the code for outportl:
Code: Select all
void outportl(unsigned int port, unsigned int value) {
__asm__ __volatile__("outl %%eax,%%dx"::"d" (port), "a" (value));
};
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
So outportl writes 32 bits. What size is the data port? What size is target?Caffeine wrote:And here is the code for outportl:
Re: How do I find a partition while in WSL2?
Octocontrabass wrote:So outportl writes 32 bits. What size is the data port? What size is target?Caffeine wrote:And here is the code for outportl:
ATA_PRIMARY_DATA is defined as 0x1F0, and target (in this case) is 0x1.
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
Yes, but how big is that port? What size of reads and writes does it accept?Caffeine wrote:ATA_PRIMARY_DATA is defined as 0x1F0,
Caffeine wrote:and target (in this case) is 0x1.
Yes, but how big is it? What would sizeof(target) be?
Re: How do I find a partition while in WSL2?
Octocontrabass wrote:Yes, but how big is that port? What size of reads and writes does it accept?Caffeine wrote:ATA_PRIMARY_DATA is defined as 0x1F0,
Caffeine wrote:and target (in this case) is 0x1.
Yes, but how big is it? What would sizeof(target) be?
target would be uint8_t, and the port accepts sizes of uint16_t.
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
So outportl writes a 32-bit value, but the data port only accepts 16-bit writes.
Re: How do I find a partition while in WSL2?
I fixed, this, but the problem still isn't solved. The disk still does not get saved when I restart the OS. But thanks for catching the error!Octocontrabass wrote:So outportl writes a 32-bit value, but the data port only accepts 16-bit writes.
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find a partition while in WSL2?
How are you checking whether the disk gets saved? Which LBA are you writing to?
Why aren't you waiting until the drive is ready before sending the next command?
Why aren't you waiting until the drive is ready before sending the next command?
Re: How do I find a partition while in WSL2?
I'm writing to LBA 0x0 and I'm checking that the disk gets saved by restarting the OS and reading LBA 0x0 again. Is there a better way to check if the disk saved or not?Octocontrabass wrote:How are you checking whether the disk gets saved? Which LBA are you writing to?
I added this, (I assume you mean to poll again) and it's still not saving when I restart the disk.Octocontrabass wrote:Why aren't you waiting until the drive is ready before sending the next command?