Where are config files located in WSL?

11,673

Solution 1

I found my etc folder in:

C:\Users\USER\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\etc

Note: I'm using WSL1 so as to be able to use VMware. WSL2 uses Hyper-V which is incompatible with other virtualization hypervisors. (Edit: This is no longer true.)

However, this is changing now and in the near future. Recently both VirtualBox and VMware have released versions that support Hyper-V and WSL2. You can learn more about it for VirtualBox and VMware. The VMware solution requires the soon to be released Windows 10 Build 20H1, while VirtualBox is possibly usable now.

This next version of Windows is also advertised as allowing greater integration between Windows and WSL, perhaps even solving the problem of concurrent updates of the same files from both subsystems.

Solution 2

Warning: do not edit WSL files on disk from Windows.

The files stored on disk in %LocalAppData%\Packages use special NTFS features to implement POSIX functionality/metadata (eg Linux permissions). Using standard Windows tools/apps to edit these files will corrupt your Linux environment.

Instead, WSL provides a mount that allows you to safely access and edit files inside your Linux environment. It is available under \\wsl$\.

See Do Not Change Linux Files Using Windows Apps and Tools

Share:
11,673

Related videos on Youtube

MShakeG
Author by

MShakeG

Software+Engineering.

Updated on September 18, 2022

Comments

  • MShakeG
    MShakeG over 1 year

    According to this answer global/system config files are generally stored under /etc in linux. Is this also the case for WSL? If so where is the /etc equivalent directory located, as I was unable to find it in the WSL installation directory shown below:

    C:\Users\user\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc
    

    Read the warning by @josh3736 in the answers below and don't make the mistake I made. Look at this to edit WSL files correctly.

  • dan1st
    dan1st about 4 years
    This does not work with WSL 2. There, the whole disk is located in a single file.
  • harrymc
    harrymc about 4 years
    @dan1st: WSL2 at the moment is a bit of a mess in that respect. The Windows/Linux interface supposedly will be improved in the next major Windows version. You can read all about the problem in bug report #4260 WSL2: can't access linux file system from windows.
  • dan1st
    dan1st about 4 years
    I use WSL2 since about half a year and had no problems.
  • harrymc
    harrymc about 4 years
    @dan1st: Some have and some haven't and this can change very suddenly. Read the bug report.
  • tvdo
    tvdo about 4 years
    Please edit in at least a note that these files should not be edited directly via those paths.
  • Khalid
    Khalid about 4 years
    If we can't edit WSL files directly from a host NTFS volume why isn't WSL just using a VHD/VHDX? Seems weird to expose the files if we can't do anything with them...
  • harrymc
    harrymc about 4 years
    @Bob: That depends on how the updates are done. Many of these files are intended to be updated by the user. The next version of Windows supposedly will allow dual updates of the same files from both Windows and Linux without problem.