For those thinking of changing their Linux files on Windows 11/10, there’s something you want to know. According to Microsoft, creating or changing Linux files from Windows will likely result in data corruption and might damage your Linux environment, requiring you to uninstall & reinstall your distro.
Do not change Linux files on Windows 11/10
This means that all your Linux files or those files stored under ‘%localappdata%\lxss‘ should not be created or edited using any of the Windows tools, or you might have to face some serious losses.
Let’s explore the reasons for this issue.
If the WSL or Windows Subsystem for Linux can’t find your stored Linux file metadata for a given file, it automatically assumes the file is corrupted or damaged on the system. This is because all the file metadata is stored and represented differently in Linux compared to Windows. WSL stores all Linux data in NTFS folders and thus calculates and persists their metadata in its NTFS extended attributes.
On the other side, apps on Windows 11/10 do not have the required algorithm to re-calculate & persist this Linux metadata each time they create/modify a file stored under the root link (%localappdata\lxss\). Thus, if you happen to use a Windows 11/10 app or tool to modify any Linux files, they simply won’t have any of the previous metadata in their attributes due to the non-compatibility of the NTFS format.
Another aspect of these Windows tools is that they don’t generally edit the original file instantly. Rather, they work by deleting the original, re-creating them on the app and then restoring it to the user with all required edits. This process deprives the Linux file of all the NT files and metadata, and NT file extended properties often do not persist and are lost. Thus, if your Linux file has no or incorrect file metadata, Windows apps will tend to deem it as corrupt and probably convert it into an unusable file.
Prevention
To work on files that use a hybrid of Windows 11/10 and Linux apps, prefer working on and storing those files in your Windows filesystem and access them from both Windows and from Bash Shell via /mnt/<drive>/path. Using both services to access your Linux files will help Windows recognize all the NT filesystem elements. This helps you access the same files using both Windows tools and Bash tools without having to copy files back and forth between filesystems.
Says Rich Turner, Senior Program Manager at Microsoft – Be sure to follow these two rules in order to avoid losing files, and/or corrupting your data:
- DO store files in your Windows filesystem that you want to create/modify using Windows tools AND Linux tools
- DO NOT create/modify Linux files from Windows apps, tools, scripts or consoles.
For a full read, read this blog post on Microsoft.
Where are Linux files stored in Windows?
If you want to access Windows Subsystem for Linux files on Windows 11 or Windows 10, you need to go to this path: %userprofile%\AppData\Local\Packages. Alternatively, you can use the WSL Terminal to open the same folder in File Explorer. For that, you need to enter the explorer.exe command.
How do I view Linux files on Windows?
There are two ways to view Windows Subsystem for Linux files in Windows 11/10 PCs. First, you can use the WSL Terminal. To use it, you need to enter the explorer.exe command. On the other hand, you can navigate to C:\Users\user-name\AppData\Local\Packages in the File Explorer.