Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables natively on Windows 10 and 11. WSL2 is an updated version of WSL that uses a real Linux kernel to provide better performance and compatibility. One of the features of WSL2 is the ability to run a full Linux distribution inside a virtual machine (VM).
File sharing between the host Windows system and the WSL2 Linux VM can be a bit tricky to set up, but it is necessary for seamless integration between the two systems. In this article, we will go over the steps to fix file sharing on WSL2 Linux VM for Windows-11.
Check the WSL2 Integration Service
The WSL2 Integration Service is a Windows service that enables file and network sharing between the host and the WSL2 Linux VM. To check if the service is running, follow these steps:
- Press the Windows key and type "Services".
- Scroll down and find "WSL2 Integration Service".
- Right-click on the service and select "Properties".
- Make sure the service is set to "Automatic" and is currently running.
If the service is not running, start it and set it to "Automatic" so that it starts automatically when the system boots up.
Share the WSL2 Distribution Files
The WSL2 distribution files are stored in a directory on the host Windows system. To share the distribution files with the WSL2 Linux VM, follow these steps:
- Open File Explorer and navigate to the directory where the WSL2 distribution files are stored. The default location is
C:\Users\%USERNAME%\AppData\Local\Microsoft\WSL\. - Right-click on the distribution directory and select "Properties".
- Go to the "Sharing" tab and click on "Advanced Sharing".
- Check the "Share this folder" option and click on "Permissions".
- Make sure the "Everyone" group is selected and has "Read" permissions.
- Click "OK" to close the "Permissions" dialog.
- Click "OK" to close the "Advanced Sharing" dialog.
- Click "Close" to close the "Properties" dialog.
The WSL2 distribution files are now shared with the WSL2 Linux VM.
Mount the WSL2 Distribution Files in the VM
The WSL2 distribution files need to be mounted in the WSL2 Linux VM so that they can be accessed from the Linux system. To mount the distribution files, follow these steps:
- Open the WSL2 Linux terminal.
- Type the following command to open the
/etc/wsl.conffile in a text editor:
sudo nano /etc/wsl.conf
- Add the following lines to the
[automount]section of the file:
[automount]
options = "metadata"
- Save the file and exit the text editor.
- Restart the WSL2 Linux VM by typing the following command:
wsl --shutdown
The WSL2 distribution files are now mounted in the WSL2 Linux VM and can be accessed from the Linux system.
Test File Sharing
To test file sharing between the host Windows system and the WSL2 Linux VM, follow these steps:
- Create a file on the host Windows system in the shared directory.
- Open the WSL2 Linux terminal.
- Navigate to the shared directory on the Linux system.
- Verify that the file created in step 1 is present in the shared directory.
- Create a file on the WSL2 Linux system in the shared directory.
- Switch to the host Windows system.
- Navigate to the shared directory.
- Verify that the file created in step 5 is present in the shared directory.
If both files are present, file sharing is working correctly between the host Windows system and the WSL2 Linux VM.
In this article, we have gone over the steps to fix file sharing on WSL2 Linux VM for Windows-11. By following these steps, you can ensure seamless integration between the host Windows system and the WSL2 Linux VM.
References
| Title | URL |
|---|---|
| WSL2 Documentation | https://docs.microsoft.com/en-us/windows/wsl/wsl2-index |
| WSL2 Integration Service | https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel |