0

I have WSL (Linux subsystem on Windows 10) installed with ubuntu 21.04 (not from the store, it's the first version that appeared on Windows 10), how can I migrate to version 2 (with an actual kernel) while keeping all my files (system and user), if possible without reinstalling everything ?

EDIT wsl -l -v gives:

  NAME            STATE           VERSION
* Legacy          Running         1
  Ubuntu-20.04    Stopped         2

Which is WSL 1. I would like to go to WSL 2.

Soleil
  • 374
  • You run wsl --set-default-version 2. Full Documentation Here. What part of the process are you stuck on exactly? – Ramhound Nov 02 '21 at 19:47
  • @Ramhound As mentioned, I'm not using the regular ubuntu distribution from the store, but the previous one (from before they appeared on the store), so it's not clear how to achieve what I want. I also updated the post. – Soleil Nov 02 '21 at 21:53
  • It shouldn't matter. Have you tried running wsl --set-default-version 2 and then starting the instance? – Ramhound Nov 02 '21 at 23:38
  • @Ramhound yes, but uname -r still gives "4.4.0-19041-Microsoft" (ie., WSL 1). – Soleil Nov 02 '21 at 23:41
  • Provide the output of the command I gave you, then after that output, include the output of wsl -l -v. If wsl --set-default-version 2 does "nothing" then you have forgotten to install something. Just to confirm you are running 21H1+? – Ramhound Nov 02 '21 at 23:44
  • @Ramhound I still have "There is no distribution with the supplied name." and Legacy is still set to WSL1. – Soleil Nov 02 '21 at 23:46
  • So you don't have an instance named Ubuntu 2 you have an instance called Ubuntu-20.04 which is already WLS2 by the way. It is currently NOT running. – Ramhound Nov 02 '21 at 23:47
  • I suggest changing the title to WSL Legacy to 2 migration (replacing "1" with "Legacy"). Why? The fact that wsl -l -v says Legacy is "version 1" is very misleading. – It's not! The response should have said "version 0" or "version beta" or something else that clarifies that Legacy is pre version 1. This also explains why this answer got it all wrong. Given the title WSL 1 to 2 migration, that answer is perfectly fine. One has to know that Legacy is a special case in order to understand and answer your question correctly. – Henke - Нава́льный П с м Aug 05 '22 at 12:09
  • 1
    @Henke In the MSFT naming system, legacy is the name, 1 is the version (see my output of wsl -l -v). – Soleil Aug 07 '22 at 22:32
  • By adding "legacy" to the title you are helping readers understand that it's a special case (unlike normal version 1). – Henke - Нава́льный П с м Aug 08 '22 at 11:40

3 Answers3

1

That's not possible:

wsl --set-version Legacy 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
The Legacy distribution does not support WSL 2.

For migration of files to another distribution, there are two possible ways.

  1. First check if wsl.exe --help shows a --export options. If yes then export the installed distribution to a tar file. For example the command will be: wsl.exe --export Legacy myfile.tar. Then uninstall the Legacy distribution with wsl.exe --unregister Legacy command. And reinstall the distribution with wsl.exe --import command.

  2. Or run the Legacy distribution and tarball the whole distribution, see this answer. Then uninstall Legacy distribution and reinstall it from that tarball.

From github and thanks to Ramhound.

Soleil
  • 374
0

That’s super trivial, though reading the docs should come first.

$ wsl --help
…
    --set-version <Distro> <Version>
        Changes the version of the specified distribution.

So just do wsl --set-version MyDistro 2, wait a little, and that’s it.

Daniel B
  • 62,883
0

It might be required to fire up a PowerShell that is Run as Administrator and enter:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Reboot and enter:

wsl --set-default-version 2
wsl --set-version Ubuntu 2         (use the name of your distribution)

If you have any problems, please let us know.

You could also do the upgrade manually by downloading and executing the WSL kernel latest package from WSL2 Linux kernel update package for x64 machines.

Before starting I suggest backing up the Linux distribution. See the article Export and Import WSL Linux Distro in Windows 10 and also to create a Windows System Restore save.

harrymc
  • 480,290
  • From wsl --set-version Ubuntu 2 I get "There is no distribution with the supplied name." – Soleil Nov 02 '21 at 21:53
  • @Soleil - So run wsl -l -v and update your question so this answer can be updated. – Ramhound Nov 02 '21 at 23:40
  • @harrymc - You are on the correct track. I am exhausted so I can't submit my own answer. Here is the exact issue the author is facing. Here is where Microsoft suggests just removing and replacing. Here is the correct link to the documentation the second GitHub issue links to. It should be as simple as, export, unregister, import. The author should backup their home directory just in the event the export doesn't cover it. – Ramhound Nov 03 '21 at 00:04
  • @Ramhound: Thanks for the info. I'm aware of the fact that export/import/tarball might be a solution, but there are also downsides. In any case, the poster used this in his own answer, so his problem is solved using your comment. – harrymc Nov 03 '21 at 09:24