Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the files inside wsl2 physically stored? [closed]

I've installed wsl2 on my windows machine and I was not able to figure out where the files are actually stored.
Note, that I don't mean that I wanna browse them inside the file explorer - I know it can be done by typing in the explorer \\wsl$\.
If I would have to guess I would say the files are stored in the same hard-drive that the os is stored.

So actually I have two related questions.

  1. Where the files are stored?
  2. If they are stored in the hard drive of my os, can I somehow relocate my wsl to another hard drive?

EDIT:
I was able to locate the installation path, in my machine the path is:
C:\Users\Eliran\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState

Is there a way to mount this to another location?

like image 200
Eliran Turgeman Avatar asked Oct 03 '20 14:10

Eliran Turgeman


People also ask

Where WSL2 files are stored?

You can access WSL2 Linux files from the network path \\wsl$\ . Enter it in the File Explorer address bar or any file open dialog.

Where do WSL files get saved?

File storage and performance across file systems For example, when storing your WSL project files: Use the Linux file system root directory: \\wsl$\Ubuntu\home\<user name>\Project. Not the Windows file system root directory: /mnt/c/Users/<user name>/Project$ or C:\Users\<user name>\Project.


1 Answers

All the files are stored in a ext4.vhd files in the installation directory, which you can't mount directly onto windows as it is in ext4 (obv)

There's two ways to change the location of the above mentioned vhd file the official, tedious way and an unofficial quick and dirty way

The official tedious way

  1. Export the distro to a location with wsl.exe --export <Distro> <FileName> from CMD/PowerShell
  2. Import the distro to a different location with wsl.exe --import <Distro> <InstallLocation> <FileName> [Options]

The problems with this is it's quite time consuming and after you do this, pray that it exported and imported several gigabytes worth of thousands of files without any problems

The quick and dirty way

This involes an unofficial opensource WSL manager called lxrunoffline

To install it (takes like a min at max) read through the instructions by the dev here

If you installed it by manually downloading the binaries from the release page, make sure to install it to a directory in PATH, like C:\Windows

Now the process is simple as lxrunoffline move -n <distroname> -d <destination-folder>

For example lxrunoffline move -n Ubuntu-20.04 -d G:\wsl\

Hope I helped

Edit: typo

like image 190
zwxi Avatar answered Sep 27 '22 01:09

zwxi