2

Running Ubunutu 20.04 in WSL, windows disks are mounted as

/mnt/c
/mnt/d
/mnt/e

and so on.

In the bash shell, how can I get the volume label of, say, the disk at /mnt/d ?

lsblk and tune2fs /mnt/d don't give the volume label

1
  • Did you use something like: lsblk -o label,more options? Not sure how wsl works . Maybe those volumes actually do not have any label assigned. Nov 29, 2022 at 16:58

2 Answers 2

2

While most everything in @Edward's answer is true, there is a workaround in WSL that will allow you to read the volume names.

Since (by default, at least) WSL allows you to call command-line (and other) Windows executables, it's easy to use PowerShell (through WSL) to read Windows-specific data.

$ powershell.exe -c "(Get-Volume d).FileSystemLabel"
Crucial SSD 2TB

You can, of course, script it with something like (WSL2 specific, due to mounts):

mount | 
    grep "^drvfs on .* 9p" | 
    awk '{print $3}' |
    xargs -I{} bash -c '''
        mnt={}
        drv="${mnt:0-1}"
        echo -en "${mnt}\t"
        powershell.exe -c "(Get-Volume $drv).FilesystemLabel"
    '''
3
  • Brilliant, thanks! Dec 19, 2022 at 21:47
  • That just cost me 15 reputation but hat off to you, nice answer :-) +1
    – Edward
    Dec 20, 2022 at 10:42
  • @Edward Lol - Thanks! And there's 20 back ;-) Dec 20, 2022 at 13:33
1

WSL2 is in fact a VM running a Microsoft kernel:

root@test-ubuntu-wsl2:/home/edward# uname -a
Linux test-ubuntu-wsl2 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

You can connect disks using the Windows-side userspace wsl.exe, for an example see https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk or https://devblogs.microsoft.com/commandline/access-linux-filesystems-in-windows-and-wsl-2/.

It appears that the Windows filesystems are mounted using the 9p protocol:

root@test-ubuntu-wsl2:/home/edward# mount | grep '\\'
C:\ on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=8,wfd=8)
M:\ on /mnt/m type 9p (rw,noatime,dirsync,aname=drvfs;path=M:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=8,wfd=8)

The Windows host runs a 9p server, the WSL instances connect to that server. Therefore there is no direct device access (no hardware access): lsblk and tune2fs and all other direct-device userspace tools won't see the host drives.

Also see https://superuser.com/questions/1643551/windows-10-wsl-mount-creates-9p-filesystem-instead-of-drvfs.

TLDR; you need direct device access to see the disk label. From within WSL2, essentially a VM, that's not possible.

2
  • Can you clarify: your answer is basically "you can't see the volume name"? Nov 29, 2022 at 17:28
  • 1
    Yes, exactly. Just like in a regular VM. WSL2 can't see the disk label of the Windows host: for that it needs direct device access. I will circle back to your original question in my answer.
    – Edward
    Nov 29, 2022 at 17:35

You must log in to answer this question.

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