For those thinking of changing their Linux files on Windows 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 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 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 10 app or tool to modify any Linux files, they simply won’t have any of the previous metadata in their attributes due to non-compatibility of 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 are often not persisted and are lost. Thus, if your Linux file has no or incorrect file metadata, Windows apps will tend to deem them as corrupt and probably convert them into an unusable file.
To work on files that use a hybrid of Windows 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 the 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 MSDN.