9

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
7
  • 1
    Try following what Microsoft says devblogs.microsoft.com/commandline/… Jun 25, 2023 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, 2023 at 19:20
  • This question has been asked and answered several times on this site: superuser.com/search?q=WSL+home+directory+folder Jun 25, 2023 at 20:18
  • 2
    Does this answer your question? WSL for linux where are files stored Jun 25, 2023 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, 2023 at 3:54

3 Answers 3

14

$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

3
  • 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, 2023 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 and WSL2 replaced WSL1 as the default, when it was introduced as part of 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, 2023 at 21:27
  • I had to replace wsl.localhost with wsl$.
    – victorlin
    15 hours ago
4

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.

1
  • 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?)... stackoverflow.com/a/49196815/15919675 said %LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home -- but that didn't work for me... 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, 2023 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.

1
  • 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, 2023 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .