I have a folder in WSL2-Ubuntu whose path is \\wsl.localhost\Ubuntu\home\akira\project
. I want to sync this folder with Dropbox. The Dropbox folder on Windows 11 is C:\Users\Akira\Dropbox
. I tried
mklink /J "C:\Users\Akira\Dropbox\projects" "\\wsl.localhost\Ubuntu\home\akira\projects"
This command does not work and returns the message Local volumes are required to complete the operation
. From this answer, we can create a soft link with
New-Item -ItemType SymbolicLink -Path "C:\Users\Akira\Dropbox\projects" -Target "\\wsl.localhost\Ubuntu\home\akira\projects"
The difference between soft and hard links is
There are two type of symbolic links: Hard and soft. Soft symbolic links work similarly to a standard shortcut. When you open a soft link to a folder, you will be redirected to the folder where the files are stored. However, a hard link makes it appear as though the file or folder actually exists at the location of the symbolic link, and your applications won't know any better. That makes hard symbolic links more useful in most situations.
Could you explain how to create the desired hard link?
I just went through a similar exercise for a WSL directory to be backed up. In my case via OneDrive rather than Dropbox but I imagine they function similarly. In my case creating a soft/symbolic link as you describe worked fine.
In powershell:
New-Item -ItemType SymbolicLink -Path "C:\Users\YOUR_WINDOWS_USER\OneDrive\Documents\wsl_documents" -Target "\\wsl`$\Ubuntu-22.04\home\YOUR_WSL_USER\documents\"
Keep in mind that your distro name for WSL may be different and can be seen via the following in powershell:
> wsl.exe -l
Windows Subsystem for Linux Distributions:
Ubuntu-22.04 (Default)
I now see this in an explorer window (sync is pending):
Notice that the type is File folder
rather than Shortcut
, I believe this is the indicator that windows applications like OneDrive will treat it like any other folder and will follow your link to backup the contained files.