After successfully moving WSL to another drive as described in WSL: move to another drive, the next logical step is to share the Linux server among different users. This approach eliminates the need for each user to configure the system repeatedly, making the process straightforward and efficient.
Steps to Share WSL Virtual Hard Disk
- Install WSL for Each User: Each user can either install WSL anew, as detailed in WSL: PowerShell Installing, or map it to the existing .vhdx file.
- Login with the User Who Installed WSL: Access the user account that has WSL installed.
- Open the Registry Editor: Launch the Windows Registry Editor by typing
regedit.exein the Run or Search menu and pressing Enter. - Navigate to the WSL Registry Path: Go to ComputerHKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionLxss. You will see folders with random names like {2d42cb50-bbf8-497a-950d-edb1cbebd24c}.
- Copy the BasePath Value: Locate the String Value named BasePath and copy its value, which might look like
?C:UsersDatasWSL2UbuntuorC:UsersDatasWSL2Ubuntuext4.vhdx. - Switch to the User Who Will Use the Shared OS: Log in to the user account that will use the shared OS or Virtual Hard Disk.
- Open the Registry Editor Again: Repeat the process of opening the Registry Editor.
- Locate the WSL Registry Path for the New User: Navigate to ComputerHKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionLxss and find the folder with a different random name.
- Replace the BasePath Value: Replace the existing BasePath value with the one copied earlier.
- Modify Permissions for the Virtual Hard Disk: Go to the path of the Virtual Hard Disk (
C:UsersDatasWSL2Ubuntuext4.vhdx) and adjust the permissions to allow the new user to read and write. - Repeat for All Users: Follow steps 6 to 10 for each user who needs access to the shared OS.
- Restart Windows: After completing the setup for all users, restart your Windows system.
Common Errors and Solutions
After setting up, check if each user can access the shared OS. Here are common errors and their solutions:
- Error: Failed to attach disk ‘C:UsersDatasWSL2Ubuntuext4.vhdx’: Access is denied.
This indicates that the user does not have read/write permissions. Go back and adjust the permissions for the Virtual Hard Disk. - Error: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_SHARING_VIOLATION.
This error suggests that the Virtual Hard Disk is locked by another user. Ensure that no other user is logged in or using the system.
Conclusion
Sharing a WSL Virtual Hard Disk among multiple users simplifies the setup process and reduces configuration redundancy. By following the steps outlined above, you can efficiently share your Linux server with other users, ensuring smooth collaboration and streamlined operations.