如何关闭wsl2和windows用户共享文件夹?

WSL2 预设包含 /mnt/c/Users/UserName windows 共享资料夹.
我想要关闭两个OS系统的这种连接,因为这特别危险,尤其是rm指令,可以从 WSL2 的 linux os 影响 windows 的资料

image.png

阅读 8.9k
2 个回答

询问 WSL 官方得到以下方式

By "close the link between two os system", if you mean to disable automatically mount Windows partitions, then add the following in /etc/wsl.conf file in that GNU/Linux distribution in WSL: [automount] enabled=false For further information, see this blog post: Automatically Configuring WSL

From https://github.com/microsoft/WSL/issues/5870

无法关闭。

本质上来说只有一个 Windows 文件系统,所谓的 Linux 盘符都是 WSL2 虚拟出来的,并不真实存在一个 Linux 文件系统。(这也是 WSL2 文件系统被诟病慢的原因)

不过你可以手动 umount /mnt/c 取消掉挂载。

自己写个批处理,放到 WSL2 启动项里吧。

P.S. WSL1 时代有个配置项,在 /etc/wsl 下可选择配置 enabledfalse 来禁用自动挂载 Windows 盘符(但 /mnt/c 盘符还会在,只是变成了一个空目录),不清楚 WSL2 里是否依然可用,手头没机器测试。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题