Determining a linux filesystem drive types in powershell for automounting

filesystemsmountpowershellwindowswindows-subsystem-for-linux

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.

Best Answer

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