- WSL for linux where are files stored
- 2 Answers 2
- Where are files saved when created in a WSL terminal window?
- 2 Answers 2
- Method 1
- Method 2
- Warning
- Do not change Linux files using Windows apps and tools
- DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your %LOCALAPPDATA% folder using Windows apps, tools, scripts, consoles, etc.
- Where is the Ubuntu file system root directory in Windows Subsystem for Linux and vice versa?
- 6 Answers 6
- CAUTION
- Interoperability with Windows
WSL for linux where are files stored
I have been using Windows Subsystem for Linux (WSL) and when I create a file in the home directory of WSL, where does it actually exist in file explorer, also, since my C: drive is in /mnt/c/ does that mean Linux is on a seperate partition or mount? When I run list directory in root for WSL:
bin boot dev etc home init lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
%LOCALAPPDATA%\Lxss\rootfs or %LOCALAPPDATA%\Packages\
\\wsl$\
2 Answers 2
Ack- No! Regarding the comment and your corresponding self-answer, please never access files directly through %LOCALAPPDATA%\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState\rootfs . While it is true that, for WSL1, the files are stored there by WSL, accessing them directly can cause WSL corruption. Also note that for WSL2, the files are inside a virtual HDD ( ext4.vhdx ), so it prevents you from using this technique at all.
There is one hard-and-fast rule when it comes to WSL on Windows:
DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your %LOCALAPPDATA% folder using Windows apps, tools, scripts, consoles, etc. Opening files using some Windows tools may read-lock the opened files and/or folders, preventing updates to file contents and/or metadata, > essentially resulting in corrupted files/folders.
Creating/changing Linux files in your Appdata folder from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro!
The correct answer is also found in that page. WSL provides a \\wsl$\ pseudo-network-share that will allow you to safely access the WSL filesystem from Windows. Note that the WSL instance does need to be running in order to show up in \\wsl$\ .
Where are files saved when created in a WSL terminal window?
I recently installed Ubuntu in WSL on my Windows 10 system following the steps at How to install Windows Subsystem for Linux (WSL) on Windows 10 | Windows Central. I created files in a Terminal window but I don’t know how to access them via folder. How can I find and open such a file?
2 Answers 2
Method 1
While in the Ubuntu terminal enter:
Note the . at the end. This will open a File Explorer window where you are at in Ubuntu.
Method 2
Open File Explorer in Windows the usual way:
Note: Text files created in Ubuntu uses different conventions for new lines as compared with Windows. If you edit these files using Windows tools they may not work as before in Ubuntu. Messing with Ubuntu system files via Windows Explorer may corrupt those files.
Warning
Do not change Linux files using Windows apps and tools
DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your %LOCALAPPDATA% folder using Windows apps, tools, scripts, consoles, etc.
Opening > files using some Windows tools may read-lock the opened files > and/or folders, preventing updates to file contents and/or metadata, > essentially resulting in corrupted files/folders.
Creating/changing Linux files in your Appdata folder from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro!
Where is the Ubuntu file system root directory in Windows Subsystem for Linux and vice versa?
I have installed Ubuntu subsystem on Windows 10 (after enabling feature in settings), but where is the Ubuntu file system root directory located in the drive?
PLEASE NOTE We (the WSL team) STRONGLY recommend you do NOT spelunk into the Linux distro data folders ). If you do, data loss and/or corruption is VERY likely We are working to improve this interop scenario and will announce any progress on our blog: blogs.msdn.microsoft.com/commandline
@RichTurner I’ve found there’s a very specific (and annoying) reason — corporate policies marking the .ssh folder with the wrong permissions repeatedly means needing to mark the structure as «off limits» to the corporate scripts. But generally — I’d agree with you.
@DannyStaple If you need to change the permissions on files/folders in your Linux distro from Windows, use wsl.exe , e.g. wsl chmod 600 ~/.ssh/id* — do not copy files into these folders via the Windows filesystem.
@mehrdad WSL implements a P9 fileserver, exposing/marshalling files from/to the distro’s filesystem as any P9 fileserver would. This way there is no NTFS metadata to marshal. Please watch Craig Loewen & Ben Hillis’ session at Build 2919 for more info
6 Answers 6
For Ubuntu installed from the Windows store:
Each distribution you install through the store is installed to that application’s appdata directory. For example: C:\Users\\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState — benhillis
For WSL2 you can access to home directory from windows (Windows 10 build 18342) like this :
In earlier iterations of Windows Subsystem for Linux, the Ubuntu file system was at %localappdata%\Lxss (e.g., C:\Users\Username\AppData\Local\Lxss — replace the Username with your Username on Windows). See the WSL blog post on File System Support:
The primary file system used by WSL is VolFs. It is used to store the Linux system files, as well as the content of your Linux home directory. As such, VolFs supports most features the Linux VFS provides, including Linux permissions, symbolic links, FIFOs, sockets, and device files.
VolFs is used to mount the VFS root directory, using %LocalAppData%\lxss\rootfs as the backing storage. In addition, a few additional VolFs mount points exist, most notably /root and /home which are mounted using %LocalAppData%\lxss\root and %LocalAppData%\lxss\home respectively. The reason for these separate mounts is that when you uninstall WSL, the home directories are not removed by default, so any personal files stored there will be preserved.
CAUTION
Creating/modifying any files within the Linux subsystem using Windows apps & tools can cause Data corruption and data loss in Ubuntu subsystem! (Thanks to Rich Turner for suggesting these words of caution!) This is absolutely not supported. From the same blog post:
Interoperability with Windows
While VolFs files are stored in regular files on Windows in the directories mentioned above, interoperability with Windows is not supported. If a new file is added to one of these directories from Windows, it lacks the EAs needed by VolFs, so VolFs doesn’t know what to do with the file and simply ignores it. Many editors will also strip the EAs when saving an existing file, again making the file unusable in WSL.
Your Windows file system is located at /mnt/c in the Bash shell environment.