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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityWhile 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"
'''
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.
lsblk -o label,more options
? Not sure how wsl works . Maybe those volumes actually do not have any label assigned.