Windows access linux file

A Deep Dive Into How WSL Allows Windows to Access Linux Files

Three months ago, we announced that the Windows Subsystem for Linux will be able to access Linux files from Windows in the blog post: What’s new for WSL in Windows 10 version 1903, and in today’s post we will be showing you how we made these changes possible.

Let’s jump in!

We’re continuing our whiteboard series of deep dives (you can find the full list here) with a new video where Sven Groot and Craig Loewen explain the full architecture behind this new feature. You can expect to learn about how WSL currently accesses Linux files, how we’ve added a 9P file server into the init process of each Linux distro, and how Windows interacts with that 9P file server to interact with Linux files inside of your distro. So, grab a coffee and a snack, sit down, relax, and enjoy this look behind the scenes of WSL!

How does this story fit in with WSL 2?

We don’t explicitly mention WSL 2 in the video above as at the time of filming we were still finalizing the details behind WSL 2, and ultimately there are very little changes to our explanation of how Linux files are accessed from Windows with the new architecture. The only difference from the explanation in the video, is where the Linux files themselves are stored. In WSL 1, these Linux files are stored in the Windows drive (which uses the NT file system), while in WSL 2 these Linux files are stored in a virtual hard disk which uses the EXT4 file system. Every other detail on how the files are accessed remains the same.

What would you like to see next?

If you have more questions about how we use a 9P file server, accessing Linux files, or just about WSL in general you can find a list of our team members on twitter here! Please feel free to reach out to ask us any questions, and give suggestions on any other deep dives that you’d be interested in seeing.

Читайте также:  Linux кому принадлежит файл

Источник

Access Linux filesystems in Windows and WSL 2

Starting with Windows Insiders preview build 20211, WSL 2 will be offering a new feature: wsl —mount . This new parameter allows a physical disk to be attached and mounted inside WSL 2, which enables you to access filesystems that aren’t natively supported by Windows (such as ext4). So, if you’re dual booting with Windows & Linux using different disks, you can now access your Linux files from Windows!

Getting started

wmic diskdrive list brief 

terminal with wsl text

The disks paths are available under the ‘DeviceID’ columns. Usually under the \\.\\\.\PHYSICALDRIVE* format. Below is an example of mounting a specific partition of a given hard disk into WSL and browsing its files.

Accessing these files with File Explorer

Accessing an EXT4 partition with file explorer

Once mounted, it’s also possible to access these disks through the Windows explorer by navigating to \wsl$ and then to the mount folder.

Limitations

By default, wsl —mount attempts to mount the disk as ext4. To specify a filesystem, or for more advanced scenarios, check out Mount a disk in WSL 2. Also please note that this feature comes with the limitation that only physical disks can be attached to WSL 2. At this time, it’s not possible to attach a single partition. More details on the limitations here.

Give us your feedback!

If you run into any issues, or have feedback for our team please file an issue on our Github , and if you have general questions about WSL you can find all of our team members that are on Twitter on this twitter list.

Источник

File Permissions for WSL

This page details how Linux file permissions are interpreted across the Windows Subsystem for Linux, especially when accessing resources inside of Windows on the NT file system. This documentation assumes a basic understanding of the Linux file system permissions structure and the umask command.

When accessing Windows files from WSL the file permissions are either calculated from Windows permissions, or are read from metadata that has been added to the file by WSL. This metadata is not enabled by default.

WSL metadata on Windows files

When metadata is enabled as a mount option in WSL, extended attributes on Windows NT files can be added and interpreted to supply Linux file system permissions.

Читайте также:  Отформатировать диск linux windows

WSL can add four NTFS extended attributes:

Attribute Name Description
$LXUID User Owner ID
$LXGID Group Owner ID
$LXMOD File mode (File systems permission octals and type, e.g: 0777)
$LXDEV Device, if it is a device file

Additionally, any file that is not a regular file or directory (e.g: symlinks, FIFOs, block devices, unix sockets, and character devices) also have an NTFS reparse point. This makes it much faster to determine the kind of file in a given directory without having to query its extended attributes.

File Access Scenarios

Below is a description of how permissions are determined when accessing files in different ways using the Windows Subsystem for Linux.

Accessing Files in the Windows drive file system (DrvFS) from Linux

These scenarios occur when you are accessing your Windows files from WSL, most likely via /mnt/c .

Reading file permissions from an existing Windows file

The result depends on if the file already has existing metadata.

DrvFS file does not have metadata (default)

If the file has no metadata associated with it then we translate the effective permissions of the Windows user to read/write/execute bits and set them to the this as the same value for user, group, and other. For example, if your Windows user account has read and execute access but not write access to the file then this will be shown as r-x for user, group and other. If the file has the ‘Read Only’ attribute set in Windows then we do not grant write access in Linux.

The file has metadata

If the file has metadata present, we simply use those metadata values instead of translating effective permissions of the Windows user.

Changing file permissions on an existing Windows file using chmod

The result depends on if the file already has existing metadata.

chmod file does not have metadata (default)

Chmod will only have one effect, if you remove all the write attributes of a file then the ‘read only’ attribute on the Windows file will be set, since this is the same behaviour as CIFS (Common Internet File System) which is the SMB (Server Message Block) client in Linux.

chmod file has metadata

Chmod will change or add metadata depending on the file’s already existing metadata.

Please keep in mind that you cannot give yourself more access than what you have on Windows, even if the metadata says that is the case. For example, you could set the metadata to display that you have write permissions to a file using chmod 777 , but if you tried to access that file you would still not be able to write to it. This is thanks to interoperability, as any read or write commands to Windows files are routed through your Windows user permissions.

Читайте также:  TODO supply a title

Creating a file in DriveFS

The result depends on if metadata is enabled.

Metadata is not enabled (default)

The Windows permissions of the newly created file will be the same as if you created the file in Windows without a specific security descriptor, it will inherit the parent’s permissions.

Metadata is enabled

The file’s permission bits are set to follow the Linux umask, and the file will be saved with metadata.

Which Linux user and Linux group owns the file?

The result depends on if the file already has existing metadata.

User file does not have metadata (default)

In the default scenario, when automounting Windows drives, we specify that the user ID (UID) for any file is set to the user ID of your WSL user and the group ID (GID) is set to the principal group ID of your WSL user.

User file has metadata

The UID and GID specified in the metadata is applied as the user owner and group owner of the file.

Accessing Linux files from Windows using \\wsl$

Accessing Linux files via \\wsl$ will use the default user of your WSL distribution. Therefore any Windows app accessing Linux files will have the same permissions as the default user.

Creating a new file

The default umask is applied when creating a new file inside of a WSL distribution from Windows. The default umask is 022 , or in other words it allows all permissions except write permissions to groups and others.

Accessing files in the Linux root file system from Linux

Any files created, modified, or accessed in the Linux root file system follow standard Linux conventions, such as applying the umask to a newly created file.

Configuring file permissions

You can configure your file permissions inside of your Windows drives using the mount options in wsl.conf. The mount options allow you to set umask , dmask and fmask permissions masks. The umask is applied to all files, the dmask is applied just to directories and the fmask is applied just to files. These permission masks are then put through a logical OR operation when being applied to files, e.g: If you have a umask value of 023 and an fmask value of 022 then the resulting permissions mask for files will be 023 .

Feedback

Submit and view feedback for

Источник

Оцените статью
Adblock
detector