4

I'm using eclipse on windows to connect to files on a wsl, and I have run into what is apparently an eclipse bug which file names such as \wsl$\folder1\pom.xml get mangled. https://bugs.eclipse.org/bugs/show_bug.cgi?id=577938

A comment in the bug report suggests a possible workaround

A workaround is to map the UNC path to a drive letter, but this shouldn't be necessary

How would I do that?

3

2 Answers 2

12

I did it this way (drive j: was available)

net use j: \\wsl$\Ubuntu

Note that this is persistent, and if not deleted can cause wsl2 to restart by itself. After doing this I was able to access files on the Ubuntu distro from windows emacs.

to delete it:

net use /del j:
Sign up to request clarification or add additional context in comments.

2 Comments

Also make sure you don't use a trailing backslash: `net use j: \\wsl$\Ubuntu` fails. It also seems that mounting a subdirectory doesn't work either.
It works in PowerShell/cmd, but going to it in explorer says "Windows can't find j:"
3

As answered here, the command-line tool

subst

Associates a path with a drive letter.

SUBST [drive1: [drive2:]path]
SUBST drive1: /D

  drive1:        Specifies a virtual drive to which you want to assign a path.
  [drive2:]path  Specifies a physical drive and path you want to assign to
                 a virtual drive.
  /D             Deletes a substituted (virtual) drive.

Type SUBST with no parameters to display a list of current virtual drives.

Source: A very similar question/answer


In my specific case;

  1. Listing the available disks in Windows
  • PowerShell: GET-CimInstance -query "SELECT * from Win32_DiskDrive"
  • Command Prompt:wmic diskdrive list brief

.

> wmic diskdrive list brief
Caption                                    DeviceID            Model                                      Partitions  Size
SK hynix PC801 HFS001TEJ9X101N             \\.\PHYSICALDRIVE0  SK hynix PC801 HFS001TEJ9X101N             3           1234567890120
Samsung SSD 840 PRO Seri SCSI Disk Device  \\.\PHYSICALDRIVE1  Samsung SSD 840 PRO Seri SCSI Disk Device  6           256128643216
  1. Mounting the drive to expose it to WSL2

.

> wsl --mount \\.\PHYSICALDRIVE1 --bare
The operation completed successfully.
  1. From with in WSL2 : List the partitions and their types and mount it from within WSL

.

~~~@~~~~~:/$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 388.4M  1 disk
sdb      8:16   0     4G  0 disk [SWAP]
sdc      8:32   0     1T  0 disk /snap
                                 /mnt/wslg/distro
                                 /
sdd      8:48   0 238.5G  0 disk
├─sdd1   8:49   0   499M  0 part
├─sdd2   8:50   0   300M  0 part
├─sdd3   8:51   0   128M  0 part
├─sdd4   8:52   0 190.1G  0 part
├─sdd5   8:53   0    31G  0 part
├─sdd6   8:54   0  15.4G  0 part
└─sdd7   8:55   0  1024M  0 part
~~~@~~~~~:/$ sudo blkid -s TYPE /dev/sdd4
/dev/sdd4: TYPE="ntfs"
~~~@~~~~~:/$ sudo blkid -s TYPE /dev/sdd5
/dev/sdd5: TYPE="ext4"
~~~@~~~~~:/$ ls /mnt/
c  d  wsl  wslg
~~~@~~~~~:/$ sudo mkdir /mnt/g
~~~@~~~~~:/$ sudo mount -t ext4 /dev/sdd5 /mnt/g
  1. Navigate on Windows explorer to the folder of interest and give it a Virtual Drive name with command subst in an Admin Command Prompt:
  • > subst g: \\wsl.localhost\Ubuntu\mnt\g\

2 Comments

It works in PowerShell/cmd, but going to it in explorer says "Windows can't find j:"
this is the best alternative without using the net use command. I am just wondering which can be faster (if there's any differences)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.