Wsl Other Disk

broken image


Hello, I have recently enabled/installed WSL on Win 10 Home Edition. I can see the c drive under /mnt/c/ but I cannot see a the D drive. D in this case happens to be an SD Card which is visible. Using a new parameter wsl -mount, you can attach a Linux format disk and access its content which is available in WSL 2. Here, WSL 2 mounts the device as ext4 filesystem by default, which you may. WSL 2 uses a Virtual Hard Disk (VHD) to store your Linux files. In WSL 2, a VHD is represented on your Windows hard drive as a.vhdx file. The WSL 2 VHD uses the ext4 file system. This VHD automatically resizes to meet your storage needs and has an initial maximum size of 256GB.

Wsl Other Disk Game

Windows 10 is my daily driver at home so I need a way to use some Linux command-line utilities (e.g. git) without having to boot-up a virtual machine. I used Cygwin in the past but I really like the familiarity of the Ubuntu toolchain. Fortunately Microsoft introduced Windows Subsystem for Linux (WSL) a while ago so I can now have my cake and eat it too.

I have not done a ton of research but it appears that the emulated Linux filesystem is sandboxed and is stored on actual disk in some place that is not human friendly. The good news is that WSL can “mount” Windows drives under /mnt, the bad news is that it does an awful job of emulating anything near good Linux file permissions. What this means in practice is that every file has permissions 0777 which causes me issues because git will preserve the execute bit on tracked files.

The fix has two pieces: fixing how WSL mounts Windows drives and then fixing the permissions for newly created files.

Fixing WSL Mount Permissions

Move Wsl To Other Disk

The short version is to add this section to your WSL instance’s /etc/wsl.conf (the file probably does not exist, just create it):

What it Does

You can read the “official” Microsoft documentation on their Dev Blog but here is my explanation line-by-line:

  • The automount section changes the settings for drives that are automounted under /mnt
  • The enabled key is probably unnecessary but it explicitly turns on automounting (default is true)
  • The options key is a bit more interesting:
  • metadata turns on a mostly parallel of file permission metadata that allows WSL file permissions changes to be persisted. It partially affects the underlying Windows permissions; for more details see the Dev Blog link above.
  • umask value masks out (i.e. unsets) the group and others write bit for both files and directories
  • fmask value masks out the group and others execute bit for just files

Files should now show up with a comfortable permission setting of 0644 and directories with 0755 if they’re mounted under /mnt.

Fixing Bad Default Permissions

Other

This is kind of separate from the mounting problem but newly created files and directories in the “real” Linux directory structure also get a bad set of default permissions: 0666 for files and 0777 for directories. This is controlled by the umask value which defaults to 0000 in WSL. There is a decently long bug report about this issue but the fix is easy enough. Add to your ~/.profile:

Wsl Other Disk Drive

Similar to the umask setting that we used in our /etc/wsl.conf the value of 0022 masks out the group and others write bit for both files and directories.





broken image