WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Symlinks on the mounted Windows directories are not compatible with native.

Open tinysun212 opened this issue 10 years ago • 68 comments

On build 14341,

I created a symbolic link to a file on a mounted Windows directory in BASH.

tinysun@TEST-PC:/mnt/c/Temp$ ln -s origfile.txt symlink.txt
tinysun@TEST-PC:/mnt/c/Temp$ ls -l
total 0
-rwxrwxrwx 1 root root 39 May  4 01:48 origfile.txt
lrwxrwxrwx 1 root root 12 May 13 02:58 symlink.txt -> origfile.txt
tinysun@TEST-PC:/mnt/c/Temp$

In the command prompt CMD.exe, the file appeared as a JUNCTION and can not be accessed.

C:\Temp>dir
 Volume in drive C has no label.
 Volume Serial Number is EAE0-0FD9

 Directory of C:\Temp

05/13/2016  11:58 AM    <DIR>          .
05/13/2016  11:58 AM    <DIR>          ..
05/04/2016  10:48 AM                39 origfile.txt
05/13/2016  11:58 AM    <JUNCTION>     symlink.txt [...]
               2 File(s)             51 bytes
               2 Dir(s)  194,170,494,976 bytes free

C:\Temp>type symlink.txt
The file cannot be accessed by the system.

C:\Temp>

It should be displayed as follows.

05/13/2016  11:58 AM    <SYMLINK>     symlink.txt [origfile.txt]

I think the 'JUNCTION' can be used when the link references a directory not a file.

tinysun212 avatar May 13 '16 03:05 tinysun212

Looks like cmd.exe does not (yet?) know WSL symlinks and it treats every unknown reparse point as a junction. But actually this is not a junction. It is a new type of reparse point whose reparse tag is 0xA000001D. Hopefully it will be documented in the future Windows 10 Anniversary SDK.

Unlike Windows symlinks/junctions, no filesystem/filter drivers resolve WSL symlinks automatically. I guess this is an intentional decision to prevent Windows apps from bypassing SeCreateSymbolicLinkPrivilege by using WSL symlinks.

vyv03354 avatar May 13 '16 11:05 vyv03354

I do owe some documentation on this one. Should get that up in the next few days.

@vyv03354 is correct that the primary reason we are not adding symlinks to Windows is because of the privilege required. As of now, symlinks created in WSL are only usable within WSL. This is something we will be looking at in later releases.

russalex avatar May 17 '16 16:05 russalex

@russalex Can it not be the case that if the user running WSL has the SeCreateSymbolicLinkPrivilege that WSL creates NTFS format symbolic links instead of a custom link type?

ned14 avatar Jul 14 '16 10:07 ned14

Sven covers this question a little bit in his video on the WSL File system Blog post. There have been some discussions on doing this in the next release, but there are some questions and behavior that we would need to work out first.

I know there is a user voice page on this very request. Right now it only has 3 votes.

russalex avatar Jul 14 '16 15:07 russalex

Personally, coming from Linux and OSX the entire SeCreateSymbolicLinkPrivilege situation is one that has repeatedly caused me headache and grief. I was hoping against hope that BoW would finally fix the issue but, alas, it seems instead of making symlinks work properly in user space, MS has decided to just make a new standard? I can't follow any of the symlinks created in the linux subsystem even in windows exporer, much less in my IDE or other windows host apps. This makes me sad. :(

ricketyboo avatar Aug 03 '16 05:08 ricketyboo

@rcuddy It is very straightforward to award any user group the SeCreateSymbolicLinkPrivilege and then you can create symbolic links to your heart's content! Note that any user with the ability to escalate to administrator still cannot create links, so you'll need to make your user an ordinary user, not administrator capable user for this to work.

ned14 avatar Aug 03 '16 11:08 ned14

@ned14 Sure, I can add that privilege, but as you've pointed out, I then lose the ability for that user to escalate privileges. That doesn't seem a fair trade. ;)

ricketyboo avatar Aug 04 '16 00:08 ricketyboo

Is there any workaround to this issue? I now ran into a problem there when I tried to do a backup of a folder using robocopy. It's a development folder and npm (under WSL) created a few symlinks from node_modules/.bin/xxx to something, and now robocopy chokes on these "files" because it perceives it ias "access denied" and keeps retrying - which is something I would like to have for files actually looked or so, but not for "broken" symlinks, so I would prefer not to have to disable the error handling in robocopy...

CherryDT avatar Apr 05 '17 09:04 CherryDT

Repost of the suggestion I just posted on Issue #1475:

lxss symlinks also break my win32 backup tools.
+1 for the urgent need to unify lxss symlinks and win32 symlinks.

The tools on both sides of the programming world should be able to view and copy directory trees created on the other side, with all links in the copy usable by both sides as well.
=> The win32 and Linux subsystems must hide to user-mode programs what target path is really written on disk, and instead return to them converted targets they can understand.
For relative links this is pretty straightforward: Simply change all slahes to backslashes for the Win32 SS, or forward slahes for the Linux SS.
For absolute links, the problem is that the targets don't refer to the same root. Yet that root can be identified by the kind of slash written by the link creator:

  • If the link contains back slashes, it was created by a Win32 process relative to a Windows volume.
  • If it contains forward slashes, it was created by a Linux process, relative to the Linux FS root.

Then the subsystems can convert the link targets to absolute paths formatted as their respective user-mode programs expect.

JFLarvoire avatar Apr 10 '17 14:04 JFLarvoire

Would also like to see this. I've tried it both ways (link and target both on Windows file system):

  1. Creating a symlink via ln -s from Bash/WSL.
  2. Creating a symlink via mklink in Windows cmd.

With approach 1 I observe the behaviour mentioned here. Also the link will simply not appear in my editor on the Windows side (VS Code). In Windows Explorer it will appear but give an error upon trying to open it. However it works with everything on the WSL side.

With approach 2 everything works on the Windows side (as you would expect), but the symlink isn't visible and doesn't work on the WSL side. However, subsequently trying approach 1 results in this error: ln: failed to create symbolic link 'link.txt': File exists, and doing an rm will actually remove it, so it does exist at some level in WSL.

So to sum things up, a symlink created on either side cannot be effectively utilised by the other side, kinda breaking the file system interoperability promise. I would expect DriveFS to correctly handle symlinks created with mklink at least.

Thanks for your consideration.

noinkling avatar Apr 13 '17 00:04 noinkling

Bash also doesn't see Windows symlinks(or at least ls refuses to list them). Though you can technically cd inside(it doesn't say No such file or directory as it would with an actual non-existing file/dir). None of the contents are there though.

And yea... it gets worse with git.

martixy avatar Jul 03 '17 13:07 martixy

I have a mess of utilities installed redundantly on Windows and Ubuntu due to this issue. Hopefully it will get resolved at some point.

rhyek avatar Jul 03 '17 19:07 rhyek

I would also like this. Currently on the Bash side we're using Yarn for dependency management. We're sharing files between Windows and Bash by using /mnt/c/... . Yarn ends up using symlinks and works well if you're entirely in the Bash side. However, these symlinks are not seen on the windows side properly, which breaks development tools over there.

Note: if i manually make a junction or symlink on the Windows side (i use the Link Shell extension here: http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html) then the Bash side sees things fine. So there does appear to be interoperable symlinks, it's just that "ln -s" doesn't make them inside Bash. Fixing this would be a godsend. Thanks!

Note: I'm on 16251.

CyrusNajmabadi avatar Sep 13 '17 19:09 CyrusNajmabadi

I was sad to hear that you could not create/edit files in the wsl system from Windows. The workaround was said to be that we should create files (for example, from git/npm/yarn) on the Windows side of things, and then access those files from Windows and WSL. Well when doing what is suggested, you run into this issue with symlinks very quickly. The first thing I tried was log into bash, cd into my windows home directory, do a git checkout, then set up some symlinks (just like with what yarn/npm) would do - so that I could edit these files from windows or WSL. But when trying to access the files from Windows, nothing worked because symlinks weren't respected on Windows' side.

So accessing WSL files from Windows doesn't work (okay, I was sad but got over it), but then I discovered that in practice, the encouraged workflow (access Windows files from both Windows and WSL) doesn't work in practice either because many of the kinds of files/repos/projects you want to setup on the Windows mount, require symlinks to work correctly.

Do the BashOnWindows developers agree that this is a major issue?

Thank you very much for your investment in WSL - I'm very excited about the long term potential of this project, and I consider this to be the final blocker to actually using WSL instead of Cygwin/MSys for day to day project development.

jordwalke avatar Sep 21 '17 23:09 jordwalke

@jordwalke The way I work around that is to have separate build directories for each source project, one for WSL, one for Windows.

ned14 avatar Sep 22 '17 01:09 ned14

@ned14 yeah, I imagine something like that would be possible, but at that point, I would just rather consider rsyncing two directories between the two systems which pretty much treats WSL like a VM but faster. I just think WSL could be so much more than that if Windows would just support Linux created symlinks from the windows drive to the windows drive. (I'm not even asking for the ability for Windows to create/touch Linux files - it should be fine as long as we can create files on the Windows drive using the Linux command line (including symlinks) which Windows will respect).

jordwalke avatar Sep 22 '17 05:09 jordwalke

@jordwalke - @SvenGroot is working on unifying the symlinks story between WSL and Windows so that WSL will create symlinks in a way that Windows can understand them.

sunilmut avatar Sep 22 '17 17:09 sunilmut

Are you addressing the absymally slow file performance as well :) ?

There's only so much they can do about that. On native Windows, opening a file is approx 15x slower than Linux. 4Kb i/o is approx 3x slower, and so on. Those figures are for warm cached filesystem.

Now, WSL is many times slower again, but ultimately there is only so much they can do. You will have to accept that filesystem heavy Linux programs will always run under WSL at a fraction of Linux.

ned14 avatar Sep 22 '17 17:09 ned14

File system performance is always a priority for us, and we are working on several ways to improve this. We've already made significant strides in RS3 (the upcoming Fall Creator's Update), and are continuing to work to improve this further.

There are limits to what we can do due to requirements of application and file system filter compatibility, but we're very much aware that file system performance is a pain point for WSL (and Windows as a whole) and are working to improve the situation.

SvenGroot avatar Sep 22 '17 17:09 SvenGroot

@SvenGroot - Thanks for addressing this issue. If you're looking for a beta tester, I volunteer. Or you might try it with one of my directory management tools, such as dirc.exe (A directory comparison tool), available in SysTools.zip there: https://github.com/JFLarvoire/SysToolsLib/releases Like cmd.exe itself, the latest version of dirc.exe detects LXSS links, but can't display their target.

JFLarvoire avatar Sep 25 '17 10:09 JFLarvoire