Photo by Gabriel Heinzer on Unsplash
Streamlining Data Sharing Between Windows and WSL for Effortless Development
Solving Data Transfer Woes
Picture this: you're working with a massive 2.5GB dataset, which you've just downloaded as a tar file (data.tar.gz) using Chrome on your Windows machine. However, your preferred Python environment is on Ubuntu WSL. The question is, how do you get that data into your WSL environment with ease? The answer is simpler than you might think: a shared folder.
Creating a Shared Folder
Here's a step-by-step guide:
Create a shared folder in your preferred location on your Windows machine. Give it a memorable name, like "WSL Share."
Copy the absolute path of this folder (e.g.,
C:\Users\JaneDoe\WSL Shared Folder
). Now, navigate to your WSL Ubuntu distro. (I won't delve into the details here.)In your WSL terminal, use the following commands:
sudo mkdir /mnt/shared/
sudo mount 'C:\Users\JaneDoe\WSL Shared Folder' /mnt/shared
And just like that, you have a shared folder. Any changes you make in the Windows folder will immediately reflect in the /mnt/shared
folder on your WSL environment. It's as seamless as it gets.
Simplifying the Process
But here's the cherry on top: You don't want to keep mounting the folder every time you need access to your Windows files, do you? Not to worry, I have a solution for you. You can modify your .bashrc file (the startup script for your WSL environment).
Using a text editor like Nano, open the .bashrc file:
nano ~/.bashrc
Scroll to the very end of the file and add the following lines:
# Check if the shared folder is already mounted
# Mount Windows Shared Folder if not mounted already
output=$(mount | grep -F "path=C:\Users\JaneDoe\WSL" | wc -l)
if [ "$output" -eq 0 ]; then
sudo mount -t drvfs 'C:\Users\JaneDoe\WSL Shared Folder' /mnt/shared
fi
With this script in place, you won't have to manually mount the folder every time you use WSL. It will run automatically as soon as you open your terminal, saving you time and effort.
Conclusion
In the world of developers, where time is precious and simplicity is king, the solution to sharing data between your Windows and WSL environments can make your workflow smoother and more efficient. So, there you have it—a handy trick that streamlines your development process. Say goodbye to unnecessary complexities, and welcome the ease of data sharing between your Windows and Ubuntu WSL worlds.
Happy coding!
Like and comment if you found this useful :)