15

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
  • 2,276

5 Answers5

21

$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
  • 2,276
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.

grawity
  • 501,077
1

In a Windows 11 environment with WSL2 and Ubuntu 24.04 version installed you can find the Linux subsystem folder in the next path:

\\wsl.localhost\Ubuntu-24.04

If you want to enter your home folder you can find in:

\\wsl.localhost\Ubuntu-24.04\home\<<user_name>>

If you want to find the virtual volume disk you can find it here:

C:\Users\<<user_name>>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu24.04LTS_79rhkp1fndgsc\LocalState
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
  • 582
0

Easiest way, by far, is to just type \\wsl$

This way you do not need to know the version of ubuntu installed, the username etc. Then just drill down into your home directory.

Usually though, in windows, if you open up your file explorer, just scroll down to "Network", from there you can also see your WSL folder. If it is not automatically there, just right click and map network drive, type in \\wsl$