Thursday, May 2, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 465  / 2 Years ago, thu, december 16, 2021, 5:23:21

I am updating my Ubuntu distribution from 18.04 to 22.04. I exported the Ubuntu 18.04 instance with wsl --export Ubuntu-18.04 <file.tar> to a tarball and am trying to figure out how to effectively extract the files I need from it into my new 22.04 instance.


I know I can...



  • view the contents of the tarball with tar -tvf <file.tar> (t: view contents, v: verbose, f: next arg is filename)

  • extract the whole thing with tar -xvf <file.tar> (x: extract)

  • extract a file or folder with tar -xvf <file.tar> <filename_or_folder>


But I probably have over 1k files when I list them and I figure there has to be a more efficient way to go through them than listing and manually reading over ALL the files. I'm honestly not sure what all is in there, but I'm at least wanting to move over the relevant files for python and java projects and any config files.


I have already run the following, so using a different approach might be hard at this point:



  • wsl --terminate Ubuntu-18.04

  • wsl --unregister Ubuntu-18.04


More From » command-line

 Answers
0
First, an answer to the question itself (but see below for a potentially better option)

I would start by doing a wsl --import into a new (temporary) distribution.


Similar to my other answer, start in PowerShell and create a new directory for the temporary distribution:


mkdir "$env:USERPROFILEwslconiferous_ubuntu_old"
cd "$env:USERPROFILEwslconiferous_ubuntu_old"

Then:


wsl --import coniferous_ubuntu_old "$env:USERPROFILEwslconiferous_ubuntu_old" <path_to_tarball> --version 2


  • The first argument to --import is the name of the new distribution.

  • Second is the directory for the new distribution

  • Third is the tarball created from the --export

  • Finally, --version 2 is just a good practice to make sure that WSL2 is used.


With that in place, see my answer on Super User for information on accessing the files in one distribution from the other. Option #1 is still preferred.


(Possible) Preferred Alternative


I'd probably just delete your new 22.04 distribution if you haven't done too much with it (using --unregister) and --import the old one back in as mentioned above.


This would ultimately have the same end result as this answer that you missed. You could then do the upgrade from 18.04 to 20.04, then 20.04 to 22.04. (Although it sounds like there's a chance that already completed, even).


Naming the distribution without a version number, again, will correct your original problem.


Notes on other alternatives


If you extract the tarball of the old distribution inside the new one, then keep in mind that the size will grow quite a bit. WSL2 distributions will grow in side to accommodate the files inside, but do not (automatically) shrink when the files are deleted.


[#61] Saturday, December 18, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
panshow

Total Points: 454
Total Questions: 98
Total Answers: 122

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;