четвъртък, май 20, 2021

Access files between WSL instances

 Preamble:

C:\Users\Ivan Popov>ver && wsl --list
Microsoft Windows [Version 10.0.19041.985]
Windows Subsystem for Linux Distributions:
Debian (Default)
kali-linux

ToDo: access files in $HOME on Debian wsl instance from kali-linux wsl instance 

Dunno how (and don't care actually) rootfs is mounted in Windows, but files are located here: 

C:\Users\%USERNAME%\AppData\Local\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState\rootfs\home

(TheDebianProject.DebianGNULinux depends of installed distro)

In WSL current disk partitions are already mounted under /mnt/Disk_Letter

To access my debian_home from kali I executed: 

echo "sudo mount -B /mnt/c/Users/My\ Current\ WinUserName/AppData/Local/Packages/TheDebianProject.DebianGNULinux_76v4gfsz19hv4/LocalState/rootfs/ /mnt/deb/
" >> ~/.bashrc

[fstab entry should be in format /old_dir /new_dir none bind but for some reason didn't work]

The result:

$ls /mnt/deb/
total 620
drwxr-xr-x 1 root root   4096 May  3 23:31 .
drwxr-xr-x 1 root root   4096 May 20 15:59 ..
drwxr-xr-x 1 root root   4096 May 17 19:04 bin
drwxr-xr-x 1 root root   4096 Mar 20 00:44 boot
drwxr-xr-x 1 root root   4096 Apr  6 14:47 dev
drwxr-xr-x 1 root root   4096 May 17 19:04 etc
drwxr-xr-x 1 root root   4096 May  3 23:33 home
-rwxr-xr-x 1 root root 632048 May  5 00:48 init
drwxr-xr-x 1 root root   4096 Apr  6 14:48 lib
drwxr-xr-x 1 root root   4096 Apr  6 14:47 lib64
drwxr-xr-x 1 root root   4096 Apr  6 14:47 media
drwxr-xr-x 1 root root   4096 May  5 22:31 mnt
drwxr-xr-x 1 root root   4096 Apr  6 14:47 opt
drwxr-xr-x 1 root root   4096 Mar 20 00:44 proc
drwx------ 1 root root   4096 May  3 23:35 root
drwxr-xr-x 1 root root   4096 Apr  6 14:47 run
drwxr-xr-x 1 root root   4096 May  3 23:31 sbin
drwxr-xr-x 1 root root   4096 Apr  6 14:47 srv
drwxr-xr-x 1 root root   4096 Mar 20 00:44 sys
drwxrwxrwt 1 root root   4096 May 20 14:49 tmp
drwxr-xr-x 1 root root   4096 Apr  6 14:47 usr
drwxr-xr-x 1 root root   4096 Apr  6 14:47 var