7

当我进入 WSL 时,C驱动器会自动安装在/mnt/c. 我还想将文件夹C:\D挂载到挂载点/mnt/d

的内容/etc/fstab

LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/mnt/c/D        /mnt/d  none    bind

的内容/etc/wsl.conf

# Enable extra metadata options by default
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = true

# Enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true

当我这样做时sudo mount -a,它会正确安装。但是,它不会在启动时挂载,并且运行mount -a报告“挂载:只有 root 可以使用“--all”选项”。

4

1 回答 1

8

这个问题很老,但如果有人仍然遇到这个问题,我在WSL 发行说明中找到了答案

WSL 现在在实例启动期间处理 /etc/fstab 文件 [GH 2636]。这是在自动安装 DrvFs 驱动器之前完成的;任何已被 fstab 挂载的驱动器都不会自动重新挂载,允许您更改特定驱动器的挂载点。

因此,在绑定挂载之前,必须为 Windows 驱动器添加挂载:例如:

# <file system> <dir> <type> <options> <dump> <pass>
C: /mnt/c drvfs rw,noatime,uid=1000,gid=1000,case=off,umask=0027,fmask=0137, 0 0
/mnt/c/directory/for/mount /where/to/mount none bind,default 0 0
于 2021-03-11T15:57:47.203 回答