* Fix localization text, Intune capitalization, ADMX indentation, unused import - distributions/validate.py: Remove unused 'import base64' - en-US/en-GB Resources.resw: Fix word order 'the list distribution' -> 'the distribution list' in MessageCouldFetchDistributionList - en-US/en-GB Resources.resw: Remove trailing space from MessageCorruptedDistroRegistration value - intune/en-US/WSL.adml: Fix 'For Linux' -> 'for Linux' capitalization (5 occurrences) to match official product name - intune/WSL.admx: Fix inconsistent 3-space indent to 4-space on AllowWSL1 and CustomKernelUserSettingConfigurable policies * Fix grammar, typos, and formatting in docs and source code - WmiService.h: Fix duplicated word 'of of' -> 'is of' in WQL comment - drvfs.md: Fix 'which tell' -> 'which tells' (subject-verb agreement), double space, second 'tell' -> 'tells' - systemd.md: Fix 'tries synchronizes' -> 'tries to synchronize' - wslhost.exe.md: Fix 'processes terminates' -> 'process terminates' - boot-process.md: Add missing 'in' preposition, fix C:/ -> C:\, fix lowercase 'linux' to 'Linux' (4 occurrences), fix misplaced parenthesis - init.md: Fix double space before hvsocket backtick - session-leader.md: Fix heading level ## -> ### to match sibling section - CONTRIBUTING.md: Fix double period after bold security notice - debugging.md: Fix missing word 'be' in 'can enabled', fix 'process' -> 'processes' - index.md: Add missing period at end of sentence - technical-documentation/index.md: Fix 'API's' -> 'APIs' (remove incorrect apostrophe) - relay.md: Fix lowercase 'linux' to 'Linux' (3 occurrences) - localhost.md: Fix lowercase 'linux' to 'Linux' - plan9.md: Fix lowercase 'linux' to 'Linux' * update errormessages testcase --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2.6 KiB
Accessing Windows drives from Linux
WSL offers mountpoints to access Windows drives from Linux. These mountpoints are mounted under /mnt by default, and point to the root of Windows drives.
Elevated vs non-elevated mountpoints
Within a distribution, WSL separates between Linux processes that have been created from an elevated (as in administrator level) and from a non-elevated (user level) context.
This is done by having two separate mount namespaces within the distribution. One of them offers an elevated access to Windows drives, and the other offers a non-elevated access to Windows drives.
When a Linux process is created, wslservice.exe determines its elevation status, and then tells init to create the process in the appropriate mount namespace.
Mounting a Windows drive
*Note: This section only applies to WSL2 distributions. *
When a session leader is created, wslservice.exe starts a plan9 file server. This file server can be connected to from the WSL2 virtual machine to mount Windows drives.
When the WSL distribution is created, wslservice.exe uses the LX_INIT_CONFIGURATION_INFORMATION message to indicate whether the process that created the distribution is elevated or not. Based on this, init will mount either the elevated, or un-elevated version of the plan9 server.
Later when the first command is created in the namespace that hasn't been mounted yet, (either elevated, or non-elevated), wslservice.exe sends a LxInitMessageRemountDrvfs to init, which tells init to mount the other namespace.
See: src/windows/service/exe/WslCoreInstance.cpp and src/linux/drvfs.cpp.
Mounting a drive from Linux
As long as the Windows plan9 server is running, drives can be mounted simply by calling mount. For instance mounting the C: drive manually can be done via:
mount -t drvfs C: /tmp/my-mount-point
Internally, this is handled by /usr/sbin/mount.drvfs, which is a symlink to /init. When /init starts, it looks at argv[0] to determine which entrypoint to run. If argv[0] is mount.drvfs, then /init runs the mount.drvfs entrypoint (see MountDrvfsEntry() in src/linux/init/drvfs.cpp).
Depending on the distribution configuration, mount.drvfs will either mount the drive as drvfs (WSL1), or plan9, virtio-plan9 or virtiofs (WSL), depending on .wslconfig.