Installing/Moving WSL packages on another drive or folder than the default one

If you haven't installed your Ubuntu yet, then first install it. Then we can move it.

In case, in any case, if you want to move your WSL packages to a drive other than where it is installed by default, you can do that. You can move it from you C:/ drive to any drive or folder you want. This also actually takes only 3 steps, if your WSL instances are not running. Let's go through all the steps to move WSL ubuntu package from default location to another drive or directory.


Open you command prompt and start following the steps.

1. First check if your ubuntu is running or not. If running then we will have to stop it first

wsl --list -v

It will show you something like the following if the instances are running.

 



 

 

Here, my instance is running, so I will need to stop it first.

2. Stop running instance (optional)

wsl -t Ubuntu

 

 

 

Now my instance has stopped.

 

3. Now we will export the instance. Manually create a folder for the exported zipped data to be stored, no need if you want to store it directory drive letter such as D:/. Anyway, lets say that we are going to store in D:/exported-wsl folder, so we run the following command

wsl --export Ubuntu "D:\exported-wsl\ubuntu-ex.tar"

After a while it will confirm the process has completed, you can check there in the target directory.

4. Now we will unregister the existing Ubuntu from WSL. It will also delete the folder from it's default directory, so you won't have to do it manually. No worries, if you exported successfully, everything is now safe.

wsl --unregister Ubuntu

5. All done, its now time to import the exported zipped data, this will register the Ubuntu to WSL and everything will be back as previous. Before that, please create a folder manually where you want to install the Ubuntu. For example, D:\wsl2-instances\Ubuntu and run the following command

wsl --import Ubuntu "D:\wsl2-instances\Ubuntu" "D:\exported-wsl\ubuntu-ex.tar"

As you can see, here the first path is where we install the Ubuntu now. and the second path is where previously exported Ubuntu.

 

That's all. You can safely do this. I didn't lost anything in Ubuntu after exporting and importing, everything I had there installed was there as it was.

Comments

Popular posts from this blog

Create user and SEO friendly URL slugs for your website in PHP