So Windows 2004 update is here, and I was really excited about this update. Because it brings WSL2 as a production-ready product to our daily drivers. With all the excitement I downloaded it, and when I did
cd into my project I quickly realized that something is wrong. Git performance was really, really slow.
So I started searching around web and I discovered this issue and it seems like this issue in only appearing in the
/mnt directory. Sadly the only workaround I found was to move your projects into the WSL filesystem. But I knew I want something more pleasing. So I created a Symlink for it. Now, this took me a great 6 hours, to figure out all the things you need to do, so if you're stuck on the same issue, I hope my guide will help.
You need to create a batch script that will take care of the symlink. Unfortunately, you can't do a symlink from WSL to windows, which is my plan. Create a symlink from
$HOME/Code to your User Directory. So you can start up CMD/PowerShell/Bash/WSL and
cd right into code directory.
Open up notepad and paste the following lines in here. Make sure you'll change you usernames
@echo off START /B "" pushd \\wsl$\<Your WSL Version>\ rmdir C:\Users\<Your Windows Username>\Code /s /q mklink /d C:\Users\<Your Windows Username>\Code Z:\home\<Your WSL Username>\Code
Well, it's fairly easy. Just open up your WSL, type
cd $HOME and then
explorer.exe .. In the location bar type cmd like so
This will open WSL Filesystem in Windows explorer. Now click on the adress bar again and you should see something like this
The part that we need is that
Ubuntu-20.04 in my case but that could be
Ubuntu in your case.
Basically it will just mount your WSL as a network drive, and then it will create Windows Symlink, which will work in both Windows and WSL. Unlike the WSL symlinks which work only in WSL.
When we have our script done go to File > Save as, and then choose a location where you know that your script will be safe, so you don't accidentally delete it, and name it
Now when we have our script we need to run it every time we boot into our machine. We also need to do that with the highest privileges because you need to be an admin to make a symlink from network drive to your base drive.
So go ahead and search for Task Scheduler. On the left sidebar you will see Task Scheduler Library. Click on it and on the right sidebar click on Create Task....
Now make sure you'll give a name to your task, then write a little description and Check "Run with highest privileges". Also make sure you'll change Configure for: To Windows10
Next click on Triggers tab and add new trigger. This will look fairly simple, Just make sure it's like this, and click OK.
Next click on Actions add New and Select the
.bat script we created earlier.
Now when we restart our computer the network drive will be available in "This PC" and Code directory symlink to WSL will be in your User Directory. With significantly faster I/O Operations and git. Enjoy ✌