Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this the correct way to Import a WSL export, overwriting "default" installation?

I have created a WSL (version 1) Ubuntu 20.04 distro which I have exported, as a backup. I have made some changes to the original distro and want to revert back to export.

The original distro install is called: Ubuntu-20.04

wsl --list

Output:

Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)

The installation folder for Ubuntu is the default folder from installation:

C:\Users\<my user name>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_xxxxx

(I've changed the user name and UID)

I've looked at the import and export options and I can import the exported file into a new folder easily:

wsl --export Ubuntu-20.04 c:\temp\wcc-ubuntu-20-04-wsl.tar
wsl --import Ubuntu-20.04-New c:\wsl\ubuntu-new wcc-ubuntu-20-04-wsl.tar

That then appears in the list available:

wsl --list

Output:

Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
Ubuntu-20.04-New

If I want to use the "new" import I have to first set the default, then open access it from the command line:

wsl --setdefault Ubuntu-20.04-New
wsl -d Ubuntu-20.04-New -u myusername

If I use the Ubuntu icon in the start menu, it seems to ignore the "new" default and will open the original install. Not a problem, I can always start WSL from command line if needed.

I then looked into how to import over the original default install. My research showed that you can delete a distro using the "unregister" option, then import the file again to same location. So I ran the unregister command:

wsl --unregister Ubuntu-20.04

However, when I try the import again, setting the target to the setup folder I got issues with the folder is not empty.

C:\Users\<my user name>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_xxxxx\LocalState

Having looked at an imported WSL it only has two folders:

  • rootfs
  • temp

Following a unregister the rootfs folder is removed entirely and the temp remains. To overwrite the destination you have to delete the temp folder. Looking back at the original install folder these two folders exist under the "LocalState" subfolder. So I manually deleted these two folders.

I was then able to perform an import to the original folder. I was able to start the WSL via command line and also via the ubuntu icon in the start menu. The only thing I noticed was the command prompt had defaulted to the "root" user.

root@xxxxxxx:~#   

I am able to login as the correct user with the switch users "su" command.

su - myusername
myusername@xxxxxxx:~#

I haven't fully tested the imported WSL to make sure it does everything it needs. Not found any errors.

My worry is that this may cause issues I haven't seen down the line. I did read several posts and blogs that explicitly say don't change any files in the install folder. I was hoping that someone else out there has wanted to do the same thing and has no issues, done something different or found issues with the approach I have used.

I appreciate you taking time to ready this and any comments or advice.

like image 855
Mark Davies Avatar asked Aug 04 '20 17:08

Mark Davies


1 Answers

Here's what I did with mine:

List all distros and do wsl --unregister Ubuntu (Default) or any that you want to remove.

PS C:\Users\me> wsl --list
Windows Subsystem for Linux Distributions:
docker-desktop (Default)
docker-desktop-data

Do the import.

PS C:\Users\me> wsl --import Ubuntu C:\Users\me\wsl\Ubuntu E:\wsl\Ubuntu.tar

Verify that the distro has been imported.

PS C:\Users\me> wsl --list
Windows Subsystem for Linux Distributions:
docker-desktop (Default)
Ubuntu <--
docker-desktop-data

Change default user from root to you

PS C:\Users\me> ubuntu.exe config --default-user me

Set Ubuntu as the default for wsl

PS C:\Users\me> wsl --set-default Ubuntu

PS C:\Users\me> wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu (Default) <--
docker-desktop
docker-desktop-data

Source

I just recently did an import and everything has been working fine so far. My project was inside the wsl network so it was also included in the export.

like image 92
Dev Avatar answered Oct 15 '22 14:10

Dev