13

How would you go about cloning a WSL distro? I have a Debian WSL distribution running under Windows 10 x64 and I would like to clone the distribution without affecting my original one. I have read several documentation over at Microsoft but could not find one explaining this process or if it is even available and can be done. Could anyone please explain how and if it is even possible to clone a fresh WSL distribution of Linux?

Joe
  • 257
  • 1
  • 3
  • 15

2 Answers2

23

How would you go about cloning a WSL distro?

You first must export the WSL distribution you wish to clone.

  1. wsl.exe --export OriginalDistributionName FileName
  • OriginalDistributionName is the name of the distribution you wish to export.

  • FileName is the full path to a tar file that will be created.

You must now import the distribution you just cloned with the following command:

  1. wsl.exe --import ClonedDistributionName InstallLocation FileName
  • ClonedDistributionName is the name of the new distribution that will be created.

  • InstallDirectory is path to the folder the distribution will be installed to.

  • FileName is the full path file to the tar file you created in the previous step.

You can start the cloned distribution by running the following command:

  1. wsl --distribution ClonedDistributionName

Source:

Ramhound
  • 41,734
  • 35
  • 103
  • 130
  • 1
    Please note that if the distribution you're cloning is currently running, it'll be stopped without warning. – gtirloni Apr 11 '22 at 22:52
  • 1
    @Michael - The `InstallLocation` is wherever you decide you want it. `wsl.localhost` absolutely isn't correct. `wsl.localhost` is how you access files contained within the WSL distribution. **If you have a question, submit a question, I don't answer questions submitted as a comment under answers to questions.** This will be my last response, any additional questions you might have, submitted as a comment under this answer will be flagged and ignored. – Ramhound Jul 05 '23 at 15:22
  • @Rahmound, how's that a "separate question"? It's absolutely isn't self-explanatory, what that parameter is, given that you never had to specify that when installing the original distro, AFAICR, and it's natural to assume (especially on Windows) that if the OS could (wanted to) decide it then, it would (want to) decide it now, too. It's also out-of-character for Windows to let users invent locations for "system components" like a WSL instance willy-nilly. At the very minimum, that param. should be optional. If it isn't, it's an expected source of confusion. (Sorry if I'm missing sg. obvious!) – Sz. Aug 03 '23 at 13:43
  • @Sz. - I cannot answer questions submitted as a comment by a user other than the author. Michael if they have a question, must ask a question, instead of using temporary commentary to ask it. **What you don't see is the question that they asked as a comment since it was deleted.** You are coming into a conversation, that happened over a month ago, without understand the context. Michael never asked a question, so I could never answer their question, by submitting an answer. – Ramhound Aug 03 '23 at 14:36
1

You may intall and manage multiple Linux distros under WSL. This is detailed here.

As you say you are seeking to clone a "fresh" distro, the way to do this would be to register the same distro a second time in WSL.

Reinstalling from the store will install a clean copy of the distribution.

EDIT: Do note that the above approach is for replacing your existing distro with a fresh one. To clone an additional copy, the third approach below (cli) is needed. Note too that like many technologies, WSL has changed and will continue to change, and you should always check the documentation for the version you are using.

You may also sideload a custom distro, which may be a way to achieve more control over the naming of your distros and hence register similar distros under the name of your choice.

And you may use the cli to export and import copies of your distros:

enter image description here

Reg Edit
  • 4,671
  • 2
  • 17
  • 35