Copy Files from Windows to Windows Subsystem for Linux (Wsl)

Copy Files from Windows to Windows Subsystem for Linux (WSL)

You should be able to access your windows system under the /mnt directory. For example inside of bash, use this to get to your pictures directory:

cd /mnt/c/Users/<windows.username>/Pictures

Hope this helps!

How can I get access to files transferred from Windows to WSL-2 Ubuntu?

For starters, this belongs on Super User since it doesn't deal directly with a programming question. But since you've already provide an answer here that may be slightly dangerous (and even in your question), I didn't want to leave this unanswered for other people to find inadvertently.

If you used the first method in that link, you are using a WSL1 instance, not WSL2. Only WSL1 made the filesystem available in that way. And it's a really, really bad idea:

There is one hard-and-fast rule when it comes to WSL on Windows:

DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your %LOCALAPPDATA% folder using Windows apps, tools, scripts, consoles, etc.

Opening files using some Windows tools may read-lock the opened files and/or folders, preventing updates to file contents and/or metadata, essentially resulting in corrupted files/folders.

I'm guessing you probably went through the install process for WSL2, but you installed your distribution before setting wsl --set-default-version 2 or something like that.

As you can see in the Microsoft link above, there's now a safe method for transferring and editing files between Windows and WSL - the \\wsl$\ tmpfs mounts. Note that as a tmpfs mount stored in memory, it's really more for transferring files over. They will disappear when you reboot or shutdown WSL.

But even if you'd used the second method in that article (/mnt/c), you probably would have run into permissions issues. If you do, the solution should be to remount the C: drive with your uid/gid as I describe here.

Moving files between different WSL2 instances?


How to share data between different WSL instances

1. Create shared directory which is not included in any WSL instances

(WARNING the shared directory's filesystem lives in memory and thus a wsl.exe --shutdown would wipe them from existence.)

mkdir /mnt/wsl/share

This will create /mnt/wsl/share directory shared across all WLS instances but not included in any WSL instances.

You can share data via this shared directory.

However, it is still impossible to directly copy/paste data between WSL instances.

2. Create shared directory included in a WSL instance

You can make existing directory in WSL instance shared across other WSL instances by using bind mount.

For example, you have two WSL instances, Ubuntu-A and Ubuntu-B.

1. Open ~/.profile in Ubuntu-A and add below code.

# bind mount shared directory
if [ ! -d /mnt/wsl/share-a ]; then
mkdir /mnt/wsl/share-a
wsl.exe -d Ubuntu-A -u root mount --bind / /mnt/wsl/share-a/
fi

2. Open ~/.profile in Ubuntu-B and add below code.

# bind mount shared directory
if [ ! -d /mnt/wsl/share-b ]; then
mkdir /mnt/wsl/share-b
wsl.exe -d Ubuntu-B -u root mount --bind / /mnt/wsl/share-b/
fi

This will automatically mount the root directory (/) of Ubuntu-A to /mnt/wsl/shared-a/ and do the same thing for Ubuntu-B when you launch WSL.

https://jinsuxpark.blogspot.com/2021/01/how-to-share-data-between-different-wsl-instances-eng.html

Unable to transfer local file wsl ubuntu terminal to remote server using windows subsystem

scp /mnt/c/Users/test/test1.zip user1@stuff:/home/test/codes/ is the closest attempt to working. The error you get could be due to one of two reasons:

Firstly user1 does not have permissions to write to /home/test on stuff - makes sense as usually only the test user would be able to write there. (Note that the test user on your WSL instance is not the same profile the test user on the remote.)

Secondly the /home/test/codes/ folder may not even exist yet.

Instead (if you know test's password) copy as the test user :

scp /mnt/c/Users/test/test1.zip test@stuff:/home/test/codes/

Or copy to user1's home directory (after ensuring you have created /home/user1/codes/

scp /mnt/c/Users/test/test1.zip user1@stuff:/home/user1/codes/


Related Topics



Leave a reply



Submit