问题描述
在Linux的Windows Subsytem中,当我处于.exe
文件结构下时,似乎可以运行/mnt/c/...
文件,但是当我处于/home/...
文件结构下时,则不能运行。当我的密码在.exe
下时,是否可以访问/home/...
文件?
$ pwd
/mnt/c
$ "/c/Program Files/R/R-4.0.2/bin/Rscript.exe" -e "print('hello')"
[1] "hello"
$ cd ~
# pwd
/home/mpettis
$ "/c/Program Files/R/R-4.0.2/bin/Rscript.exe" -e "print('hello')"
(nothing run or returned)
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 498799612 133929648 364869964 27% /
none 498799612 133929648 364869964 27% /dev
none 498799612 133929648 364869964 27% /run
none 498799612 133929648 364869964 27% /run/lock
none 498799612 133929648 364869964 27% /run/shm
none 498799612 133929648 364869964 27% /run/user
cgroup 498799612 133929648 364869964 27% /sys/fs/cgroup
C: 498799612 133929648 364869964 27% /c
解决方法
创建/etc/wsl.conf
并在其中定义以下内容:
[automount]
enabled = true
options = "metadata,uid=1000,gid=1000,umask=0022,fmask=11,case=off"
mountFsTab = false
crossDistro = true
[network]
generateHosts = true
generateResolvConf = true
[filesystem]
umask = 0022
[interop]
enabled = true
appendWindowsPath = true
明确将其设为true的interop部分可以解决此问题。如果您同时运行WSL2并使用systemd hack,请务必牢记,Windows互操作将中断,并且无法执行exe文件。