1

I have the windows 10 Dev channel insiders preview (technically it's windows 11), I usually mount my ssd ext4 drives manually for wsl2

The goal: sometimes when you have something that won��t work on windows and you want it always to work on wsl2 it becomes tedious to redo the same thing over and over, that is why I would like to automate mounting ext4 fs devices to wsl2 with no interaction from me in the powershell, is that possible?

Background: I'm totally new to powershell, and still in the very basics, I'm not planning to waste lot of time on it, because I do have work to do and I have a goal to achieve, forgive my lack of knowledge in windows, I'm a mac and linux guy, but curiosity is a key for learning.

The problem: I wonder if there is any command that is similar to the command df -Th in linux, that shows all filesystem types either supported by windows like "NTFS/FAT32/FAT16/EXFAT/etc..." or unsupported as "EXT4/EXT3/EXT2/Any other linux based fs type".

df -Th sample result:

img: https://linuxhandbook.com/content/images/2020/06/screenshot_7-1.png

I don't have enough reputation to post it... Image Source

Least Expected behaviour: I want the result to show ext*, basically I wonder if there is a way to distinguish a linux drive in powershell.

Result structure doesn't matter of how it's displayed, either json or table or list or plain text, no problem as long as I get any valuable result regarding filesystem type.

1 Answer 1

3

Listing Disks

The closest command Windows has to df -Th is:

$ wmic logicaldisk get caption, description, providername, volumename, filesystem, size, deviceid

which yields, for example1:

$ wmic logicaldisk get caption, description, providername, volumename, filesystem, size, deviceid

Caption Description FileSystem ProviderName Size VolumeName DeviceID
C: Local Fixed Disk NTFS 499099860992 OS \\.\PHYSICALDRIVE0
Q: Network Connection NTFS \\dc1\c$ 42580570112 \\.\PHYSICALDRIVE1
X: Network Connection NTFS \\kfb\HomeFolders\home\stromd 1000202039296 Venus Drive \\.\PHYSICALDRIVE0

For more information on wmic's logicaldisk operation, see here.

Mounting Disks

Once you find a disk, you can mount it via2:

wsl --mount <DiskPath>

Use the DeviceID you found using wmic logicaldisk as the DiskPath.

For example, wsl --mount \\.\PHYSICALDRIVE3. By default, the filesystem is ext4, but if you wish to specify a filesystem, use the --type flag.3

Unmounting Disks

You may unmount a mounted disk via the

wsl --unmount <DiskPath>

command.4 If you omit DiskPath, all attached disks are unmounted and detached.5

13
  • 1
    But will wmic logicaldisk get filesystem work for ext4 disks, like the OP is asking? I see in your example that they are all NTFS, and I'm kind of doubting that Windows can identify a filesystem it doesn't know about. But can it? Commented Aug 6, 2021 at 3:50
  • I wish the answer would give me any result over ext4 specifically, but this only lists the mounted drives in windows such as “C/D/X”, if an unmounted drive was connected I wouldn’t be able to see it, nor knowing it’s fs data type for the purpose of my automation, btw I’ve gone through the docs about mounting and therefore I’m asking a better way to auto mount each to it’s specific correct place, windows fs to windows and Linux fs to Linux, I do appreciate your time for answering my question by the way 😊🙌🏻
    – mr.xed
    Commented Aug 6, 2021 at 23:04
  • 1
    @NotTheDr01ds yes, wmic logicaldisk will list ext4 filesystems (multiple filesystems may exist in separate partitions of the same disk), so this answer fulfills the main question that the OP is asking, "determining a linux filesystem drive types in powershell for automounting"
    – Ntechhh
    Commented Aug 6, 2021 at 23:23
  • 1
    Just because you have to run a command under wsl doesn't mean you have to manually run it, you can set up a powershell script that runs on windows and invokes the appropriate commands as necessary.
    – Ntechhh
    Commented Aug 7, 2021 at 0:45
  • 1
    In that case, wsl's wslact may be of use to you instead of trying to reinvent the wheel: github.com/wslutilities/wslu
    – Ntechhh
    Commented Aug 7, 2021 at 1:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .