Windows 10: Do not change Linux files using Windows apps and tools

  1. Brink's Avatar
    Posts : 33,210
    64-bit Windows 10 Pro build 18262
       19 Nov 2016 #1

    Do not change Linux files using Windows apps and tools

    There is one hard-and-fast rule when it comes to Bash on Windows:

    DO NOT, under ANY circumstances, create and/or modify Linux files using Windows apps, tools, scripts, consoles, etc.

    Creating/changing Linux files from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro!

    Note: Your “Linux files” are any of the files and folders under %localappdata%\lxss – which is where the Linux filesystem – distro and your own files – are stored on your drive

    Do not create/modify Linux files from Windows apps/tools!

    Why is this?

    If WSL can’t find Linux file metadata for a given file, it assumes the file is corrupted/damaged, and will likely fail to open/read the file correctly, causing apps, tools, etc. to fail and in some cases, delete files seen as “corrupt”!

    File metadata (e.g. permissions, ownership, timestamps, etc.) is represented differently in Linux than in Windows. Because stores your Linux files in an NTFS folder, WSL calculates and persists each Linux file’s metadata in its NTFS extended attributes.

    However, Windows apps do not know how to (nor that they should) re-calculate & persist this Linux metadata each time they create/modify a file stored under your distro’s root (%localappdata\lxss\).

    Therefore, if you use a Windows app/tool/console to create and/or modify a file under your distro root, it won’t have any Linux file metadata (e.g. permissions, owner, timestamps, etc.) stored in its extended attributes.

    Also, several Windows tools implement different strategies to handle file updating and don’t actually edit files in-place. When apps/tools save changes to a file, the original files are often deleted and re-created, or cloned edited and then copied over the original file, etc. During such operations, NT file extended properties are often not persisted and are “lost”.

    Thus, if a file has no/incorrect Linux file metadata, WSL may not be able to correctly open/read/write the file, and will likely cause apps to assume the file is corrupt … or even overwrite file contents actually corrupting data!

    So what SHOULD I do?

    To work on files using both Windows and Linux tools, store & work on those files in your Windows filesystem, and access them from both Windows and from Bash via /mnt/<drive>/path (e.g. /mnt/c/dev/project/...)

    When you access files on your Windows filesystem from within Bash, WSL honors the NT filesystem behaviors (e.g. case-insensitivity), permissions, etc. so you can easily access the same files using both Windows tools and Bash tools without having to copy files back and forth between filesystems.

    Therefore, be sure to follow these two rules in order to avoid losing files, and/or corrupting your data:

    1. DO store files in your Windows filesystem that you want to create/modify using Windows tools AND Linux tools
    2. DO NOT create / modify Linux files from Windows apps, tools, scripts or consoles

    Remember: There’s a reason we gave the %localappdata%\lxss\ folder ‘hidden’ & ‘system’ attributes

    For more background into how the WSL filesystem infrastructure works, be sure to read/watch this AWESOME blog & video which explains things in much more detail.

    Please help us share this guidance far and wide – tweet, post and blog linking to this post!!


    Source: Do not change Linux files using Windows apps and tools Windows Command Line Tools For Developers
      My ComputersSystem Spec

  2.    20 Nov 2016 #1

    I often edit a python file on my PC, that I run on my Raspberry Pi? I use sneaker net and a thumb drive to transfer it from one to the other. No issues so far. It's a py file so I guess its not really a Linux file?
      My ComputerSystem Spec


Related Threads
So. I used a linux live disk to hard delete the windows 10 "windows apps" folder from my file system. I didn't want windows to run any of them so why not? 64965 . . . Only, I don't have a network or system tray icons on my taskbar.Now this is...
Read more: Windows 10 build 14251 has Linux subsystem files, but what could it mean? WinBeta
Source: What’s New in Visual Studio Tools for Universal Windows Apps
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:01.
Find Us