1

What is the location of the $HOME directory in Windows (WSL v2)?

i.e. What address can I type in Windows Explorer to get to the $HOME directory in my WSL installation.
... I created a test folder and then tried find this in command prompt but it didn't show up

Folder created in home directory, but apparently does not exist anywhere




External links / existing answers reviewed but did not answer question

  1. WSL for linux where are files stored S/U: Mentions %LOCALAPPDATA%\Packages\TheDebianProject but this path does not exist
  2. Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10 #1 S/O: References %LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\USER however this path does not exist (AFAIK this is an old approach that applied to WSL 1)
  3. Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10 #2 S/O: References %LocalAppData%\Lxss\home\USER however this path does not exist either.
  4. Set up a WSL development environment Microsoft.com: does not cover $HOME location in Windows
  5. WSL Frequently asked questions Microsoft.com: does not cover $HOME location in Windows
Martin
  • 1,506
  • 1
  • 7
  • 20
  • Try following what Microsoft says https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-windows-10-version-1903/#accessing-linux-files-from-windows – Yisroel Tech Jun 25 '23 at 18:55
  • Thanks @YisroelTech - I had read a few pages on learn.microsoft.com but not seen this one, and yeah that helped (and took me to the same path that DuncG mentioned). – Martin Jun 25 '23 at 19:20
  • This question has been asked and answered several times on this site: https://superuser.com/search?q=WSL+home+directory+folder – music2myear Jun 25 '23 at 20:18
  • 2
    Does this answer your question? [WSL for linux where are files stored](https://superuser.com/questions/1642403/wsl-for-linux-where-are-files-stored) – music2myear Jun 25 '23 at 20:20
  • assuming C: to be the home folder makes zero sense. There are multiple users, each have different permission so how can they all share C: as their home path? @YisroelTech that blog is for WSL1. The OP didn't specify if they use WSL1 or WSL2 at all. Those are completely different. WSL1 doesn't run in a VM and doens't use a disk image – phuclv Jun 26 '23 at 03:54
  • @phuclv -- I have updated the post to clarify this is about WSL2 | NB: At the time of posting I was not aware there were 2 different versions of WSL, or a "WSL1" and "WSL2" (generally speaking, Windows just refers to the feature as WSL / Windows Subsystem for Linux). – Martin Jun 26 '23 at 10:38
  • @phuclv "assuming C: to be the home folder makes zero sense" you have mis-understood my command. I did not think `C:\` would be the `$home` directory, it is however the root of the drive. To try and discover where the $home folder was located, I created a sub-folder in $home, thought Windows would then create this folder *somewhere* on the Windows / NTFS filesystem and so searched the the root (`C:\`) and all folders / sub-folders to try and locate the test folder. – Martin Jun 26 '23 at 21:14

3 Answers3

2

With WSL2 you're working in a virtual machine – the entire Linux environment is a VM running on Hyper-V, with a .vhdx image storing its Ext4-formatted disk (including all of the files at /home).

The image is located in some subdirectory of ~\AppData\Local\Packages, depending on which distribution you have installed (each of them is a separate "app"). See How to manage WSL disk space for more details.

Note that while you can attach a .vhdx directly in Windows, it still won't understand the Ext4 filesystem.

For WSL1, the Linux filesystem was stored as individual files in a rootfs directory (at the same location under AppData). However, the files are not meant to be accessed directly as they have hidden attributes storing the Linux-specific metadata (e.g. Linux file permissions); directly editing the files could lose the extended attributes.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks @user1686 -- Yeah so I had seen other posts talking about this but was a bit confusing (am guessing the paths changed a few times?)... https://stackoverflow.com/a/49196815/15919675 said `%LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home` -- but that didn't work for me... https://stackoverflow.com/a/40874518/15919675 said: `%LocalAppData%\Lxss\home` but that didn't work for me either ... I did come across the `.vhdx` file, but like you say couldn't open it so was a bit stuck! – Martin Jun 25 '23 at 19:26
0

Not sure if this helps your case. In my WSL1 instance the Linux folders are listed in a new "Linux" section of Windows Explorer. Clicking on the different installation instance names to explore or try dir with UNC path something like:

dir \\wsl.localhost\Ubuntu-20.04\home\youruserid

In explorer, just find the folder you want and "Copy Path" will provide the UNC path to same which you can paste into a Windows command prompt.

DuncG
  • 532
  • 1
  • 3
  • 8
  • Thanks DuncG -- Your post has the answer, more or less and typing `\\wsl.localhost\Ubuntu\home\{username}` into Windows Explorer was what I needed to do... Just to point out thought that I didn't have the "Linux" section in Windows Explorer (I know it's supposed to be there generally, but can't see it)... Also, I know what you're saying about the "Copy Path" thing to get the path of a sub-folder, etc but my point was that I was struggling to find the root/home directory to start with (so couldn't even get my explorer to the right point to start with) – Martin Jun 25 '23 at 19:18
0

$Home location

To access $home type: \\wsl.localhost\Ubuntu\home\{username} into Windows Explorer

Screenshot of Windows Explorer showing $Home folder

Notes:

  1. This answer applies to WSL2 (this is the default version installed since Windows 10 version 2004).
  2. Ubuntu is the version ('distribution') of Linux installed by default, if you chose to install a different 'distro', you need to change this part
  3. {username} is the user you specified as part of the WSL setup, not necessarily your Windows username
  4. The linux environment runs as a VM in Hyper-V and all files in the WSL are actually contained inside a virtual hard-drive (.vhdx file) however Windows exposes the contents of the .vhdx file as the virtual network path listed above.
  5. The .vhdx file is stored in: %LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState

Acknowledgements

• @DuncG's answer (used as a base and then clarified and extended)
• @Yisroel-tech's devblogs link (would recommend this to any other new WSL users)
• @user1686 for your additional info and explanation of the .vhdx situation

Martin
  • 1,506
  • 1
  • 7
  • 20
  • 1
    Generally we try to avoid commentary, like “thanking” users for their answers, in contributions and just quote and cite them organically – Ramhound Jun 25 '23 at 21:55
  • see [No Thanks, Damn It!](https://meta.stackoverflow.com/q/288160/995714) – phuclv Jun 26 '23 at 03:55
  • [Switching from default style to (AFAICT) preferred *professional/to-the-point* style] @Ramhound, phuclv -- Your comments are not related to the question being asked however I reviewed the link provided. FYI: I use a more friendly/informal style as am mindful that written comments lack any 'tone of voice' & can come across as cold/harsh, however the [No thanks](https://meta.stackoverflow.com/q/288160/15919675) style does feel more in-keeping with my general experience on this site, so will try and use that instead if it's preferred [Post updated] T̶h̶a̶n̶k̶ ̶y̶o̶u̶ ̶f̶o̶r̶ ̶t̶h̶e̶ ̶i̶n̶f̶o̶ – Martin Jun 26 '23 at 10:26
  • `WSL installs since Win10 v2004` that's completely wrong. WSL1 and WSL2 are independent and you can switch between them depending on what you need. WSL2 has better IO but WSL1 doesn't depend on virtualization so it's faster – phuclv Jun 26 '23 at 15:56
  • @phuclv -- As advised previously, I am new to WSL so my knowledge is limited. AFAIU though, WSL2 is the default version that gets installed when following the [Microsoft WSL install steps](https://learn.microsoft.com/en-gb/windows/wsl/setup/environment#:~:text=wsl%20%2D%2Dinstall) and [WSL2 replaced WSL1 as the default, when it was introduced as part of Windows 10, version 2004](https://devblogs.microsoft.com/commandline/wsl2-will-be-generally-available-in-windows-10-version-2004) -- hence, if you run the command `WSL --install` on W10 v2004 or later, you will get WSL2 installed. – Martin Jun 26 '23 at 21:27