How to access a WSL instance from another?

Viewed 744

I am upgrading my WSL2 instance from Debian 10 to Ubuntu 20.04 LTS, because I need some newer packages.

How do I copy files and directories from Debian to Ubuntu, preserving the permissions and owner? (uid and gid are the same in the two Linuxes.)

Copying to windows first changes the permissions and owner of files.

explorer.exe also changes permissions and owner.

Preferably, I'd also like to avoid having to create a shared disk image file that I could mount from Debian and Ubuntu in turn.

I'd like something simpler, like accessing the second WSL instance directly from the first, e.g.,

    $ cp -a <Debian>/myfiles/ <Ubuntu>/myfiles

Is this possible?

2 Answers

Use tar. It will preserve all the file metadata.

In <Debian>, create myfiles.tar.gz:

tar zcvf myfiles.tar.gz myfiles

Copy myfiles.tar.gz to your windows drive e.g. with explorer.exe or with /mnt/c, and then copy myfiles.tar.gz to <Ubuntu>. In <Ubuntu>, untar it:

tar zxvf myfiles.tar.gz myfiles
Related