Windows Subsystem for Linux

Sept. 8, 2023

Avoid slow file performance in WSL

Running Linux on Windows feels like magic at first. But you may discover some things are not as convenient as they first appear. One such inconvenience is the slow performance of sharing files between the Linux subsystem and your main Windows file system. Within the Linux subsystem you'll see your drives automatically under /mnt/, for example /mnt/c/ is your C:\ drive. It's tempting to run development projects from Linux using /mnt/ but unfortunately it's rather slow, especially for things like Python virtual environments. The best workaround I've found for this is to keep the files within the Linux container (eg. /home/) and automatically sync them to other drives under /mnt/.

What's the problem?

  1. My files are on Windows drives, but I want to develop inside WSL
  2. Running projects over /mnt/ is slow in WSL
  3. Accessing the files inside the WSL container from Windows isn't clear

What's the solution?

  1. Keep all dev files within the WSL containers
  2. Access and sync the files from Windows using \\wsl$


Once you have at least one WSL container, enter \\wsl$ into the address bar in File Explorer on your Windows machine to access the file systems for all your containers.

\\wsl$

wsl_location


There are many ways to go from here. The easiest may be to schedule and run sync software from Windows, pulling down the files from \\wsl$ and copying them to your usual Windows location. Eg. C:\my_projects\

sync \\wsl$\ubuntu\home\dev to C:\Users\You\YourProjects\dev


free_file_sync

One such Windows sync software is https://freefilesync.org. In this case use the Windows Scheduler to execute the Free File Sync configuration you setup for your specific use case. This could include a two way sync or other various options.


taskschd.msc
task_scheduler2

task_scheduler3

For more info see: https://freefilesync.org/manual.php?topic=schedule-batch-jobs

If this is too 'Windows' looking for you I understand. There may be a way to schedule a cron from within WSL and run some simple rsync commands. Keep in mind the WSL container doesn't have cron ability by default. That may be a relatively new feature but let me know if anyone figures that out or recommends any other file sync software.

Return to blog