Where are the files inside wsl2 physically stored?

本小妞迷上赌 提交于 2021-02-04 17:48:15

问题


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?


回答1:


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 et4 (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



来源:https://stackoverflow.com/questions/64185560/where-are-the-files-inside-wsl2-physically-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!