I am new to Windows and have installed WSL2 based on the instructions provided here, but I cannot locate where it has been installed on my computer.
The output for pwd
is home/nkp68
.
How do I access files in my Windows machine from WSL2?
3 Answers
Locating the Installation Directory of WSL on Your Computer
When you install Windows Subsystem for Linux (WSL) on your computer, you may wonder where it is installed. This is because WSL is not installed in a traditional sense like other software. WSL is installed as a feature on Windows 10 and is not a standalone application.
To locate the installation directory of WSL on your computer, you can use the following steps:
- Launch Command Prompt or PowerShell on your Windows machine.
- Type the command
wsl --list --verbose
and press Enter. This command will list all the installed distributions of WSL on your computer. - Find the distribution you installed and note the value under the “Location” column. This value will be the installation directory of the WSL on your computer.
Once you have located the installation directory of WSL on your computer, you can access it like any other directory on your Windows machine.
Accessing Files in Your Windows Machine from WSL2
When you use WSL2 on your computer, you may want to access files on your Windows machine from WSL2. This is possible using the following steps:
- In WSL2, navigate to the directory where you want to access the files from your Windows machine.
- Type the command
explorer.exe .
and press Enter. This command will open the current directory in Windows File Explorer. - You can now access files on your Windows machine from the File Explorer window.
Alternatively, you can access files in your Windows machine from WSL2 by using the Windows network path. To do this, use the following steps:
- In WSL2, navigate to the directory where you want to access the files from your Windows machine.
- Type the command
cd /mnt/c/
and press Enter. This command will navigate to the C drive of your Windows machine. - You can now access files in your Windows machine by navigating to the appropriate directory using the Windows file path. For example, to access a file located at
C:UsersUsernameDocumentsfile.txt
, you can navigate to/mnt/c/Users/Username/Documents/
and access the file using thecat
orvi
command.
Using WSL2 as a Development Environment
WSL2 is a great development environment for developers who prefer to use Linux-based tools and applications. With WSL2, you can run Linux-based tools and applications on your Windows machine without the need for a virtual machine or dual-boot setup.
To use WSL2 as a development environment, you can follow these steps:
- Install WSL2 on your Windows machine.
- Choose a Linux distribution and install it on WSL2. You can choose from popular distributions like Ubuntu, Debian, and Kali Linux.
- Install your preferred development tools and applications on the Linux distribution installed on WSL2.
- You can now use the Linux-based tools and applications installed on WSL2 to develop and test your applications.
Configuring WSL2
WSL2 comes with several configuration options that you can use to customize your experience. Some of the common configuration options include:
- Changing the default user for WSL2
- Changing the default distribution for WSL2
- Configuring the amount of memory allocated to WSL2
- Enabling or disabling the Virtual Machine Platform feature
- Configuring the default WSL2 version
To configure WSL2, you can use the following steps:
- Launch PowerShell or Command Prompt on your Windows machine.
- Type the command
wsl --list --verbose
and press Enter. This command will list all the installed distributions of WSL on your computer. - Find the distribution you want to configure and note its name.
- Type the command
wsl --set-version [DistributionName] [VersionNumber]
and press Enter. This command will set the version of the distribution to the specified version number.
Updating WSL2
To ensure that you have the latest features and bug fixes in WSL2, you should update it regularly. To update WSL2, you can use the following steps:
- Launch PowerShell or Command Prompt on your Windows machine.
- Type the command
wsl --list --verbose
and press Enter. This command will list all the installed distributions of WSL on your computer. - Find the distribution you want to update and note its name.
- Type the command
wsl --update [DistributionName]
and press Enter. This command will update the distribution to the latest version.
Conclusion
WSL2 is a powerful tool that allows you to run Linux-based tools and applications on your Windows machine. With WSL2, you can access files on your Windows machine from Linux, use Linux-based tools and applications, and customize your experience with configuration options. By following the steps outlined in this post, you can get started with WSL2 and take advantage of its many features.
The Windows Subsystem for Linux (WSL) is installed as a Windows feature, so it does not have a specific location on your computer in the same way that a normal application would. Instead, it is integrated with the Windows operating system and can be accessed through the Windows Command Prompt or PowerShell.
To access files on your Windows machine from within WSL, you can use the \\wsl$\
directory. For example, if you want to access the C:\Users\Username\Documents
folder on your Windows machine from within WSL, you can navigate to \\wsl$\c\Users\Username\Documents
in the WSL terminal.
Alternatively, you can also access Windows files from within the WSL environment by mounting a Windows drive. To do this, you can use the mount
command in the WSL terminal, followed by the path to the Windows drive you want to mount. For example:
mount -t drvfs C: /mnt/c
This will mount the C:
drive on your Windows machine at the /mnt/c
directory in the WSL environment. You can then access the files on your Windows drive by navigating to the /mnt/c
directory in the WSL terminal.
Keep in mind that the Windows file system is case-insensitive, while the Linux file system used by WSL is case-sensitive. This means that you need to be careful about the case of filenames when accessing them from within WSL.
If you are asking me directly, there may be a few different questions you have regarding WSL2 and accessing files. First, you may want to know where your WSL Ubuntu instance is installed on your machine. In my experience, the actual files are stored in a virtual disk named ext4.vhdx
, which can typically be found under %userprofile%\AppData\Local\Packages\Canonical...\LocalState\ext4.vhdx
. Your %userprofile%
is typically something like C:\Users\<username>
. However, the “where” of the installation isn’t crucial at this point since it’s a virtual drive.
If you have multiple distributions installed or even multiple instances of the same distribution, you can quickly copy a distribution, test something out, and throw away the test without polluting your “good” daily distribution with packages, tests, or other things that may create “cruft” over the long-term. To see all the distributions you have installed, you can go to PowerShell and run:
Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse
To access files in WSL2 from Windows, you can use the \\wsl$\Ubuntu
path (or whatever your distribution is named). Here, you’ll find \\wsl$\Ubuntu\home\nkp68
, where you can safely copy in and out files.
If you are in Ubuntu and need access to a file on a Windows drive (e.g. C:
), then you’ll find those are (by default) auto-mounted for you. There are some nuances in working with files on a Windows drive from within WSL, especially around permissions and performance. You’ll typically want to keep any project files inside the Ubuntu ext4 filesystem (e.g. under your /home/nkp68
directory). But you can certainly access, copy, and move files around between the drives as needed.