When using Windows Subsystem for Linux (WSL) 2, you might encounter a common error message: "UNC paths are not supported. Defaulting to Windows folder." This message indicates that WSL 2 is unable to access the Universal Naming Convention (UNC) paths, which can lead to confusion, especially if you're trying to work across both Windows and Linux environments.
Original Problem Scenario
$ cd //servername/share/path
UNC paths are not supported. Defaulting to Windows folder.
In this situation, the command line is attempting to change directories to a UNC path that references a network share. However, WSL 2 does not support such paths natively, resulting in the error message and a fallback to a default Windows directory.
What are UNC Paths?
UNC paths are used in Windows to access shared files and folders over a network. They are typically formatted as follows:
\\servername\sharename\path\to\folder
While these paths are useful for Windows applications and users, WSL 2 does not handle UNC paths effectively due to the underlying architecture differences between Windows and Linux. WSL 2 runs a complete Linux kernel and interacts with the Windows file system differently.
Why Does WSL 2 Default to the Windows Folder?
WSL 2 defaults to the Windows folder because it is unable to interpret the UNC format directly. This limitation arises from WSL's design, where it focuses on file paths formatted in the Linux style, which uses forward slashes instead of backward slashes.
Solutions to the UNC Path Issue
To work with files on a network share within WSL 2, consider the following alternatives:
-
Map Network Drives: Before running WSL, map the UNC path to a network drive in Windows. For example, you can map
\\servername\sharename
to a drive letter like Z:. Once mapped, you can access the files in WSL using the/mnt/z
directory.$ cd /mnt/z/path/to/folder
-
Use Windows Path Format: Directly use the Windows file path in your WSL environment. For instance, instead of using the UNC path, you can convert it to a Windows-style path:
$ cd /mnt/c/Users/YourUsername/path/to/folder
-
Use the
wslpath
Command: If you're scripting or need to convert paths frequently, you can utilize thewslpath
command to convert between Windows and WSL paths.$ wslpath '\\servername\sharename\path\to\folder'
Example Scenario: Accessing Files on a Network Share
Imagine you are a developer who needs to access files stored in a shared directory on a server for your project. Instead of using the UNC path directly in WSL, follow these steps:
-
Map the Network Drive:
- Right-click on "This PC" in File Explorer.
- Select "Map network drive."
- Choose a drive letter, and enter the UNC path.
-
Open WSL:
- Launch your WSL terminal.
-
Change Directory:
- Use the mapped drive letter to navigate to your files:
$ cd /mnt/z/path/to/files
Conclusion
The error message "UNC paths are not supported. Defaulting to Windows folder." is a common hurdle for users of WSL 2 when accessing network resources. By understanding UNC paths and implementing the workarounds above, you can seamlessly access your network shares without interruption.
Additional Resources
By following these tips, you can enhance your productivity in WSL 2 and easily handle network resources without hassle.