microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.95k stars 798 forks source link

Mount a drive into WSL distro owned by a restricted user #9406

Open pelepelin opened 1 year ago

pelepelin commented 1 year ago

Is your feature request related to a problem? Please describe. I use Windows and WSL as a restricted user. However, mounting drives is only possible for Windows elevated admin account. I have access to admin account. However, it does not have access to restricted user's WSL distrubutions.

Describe the solution you'd like A way to mount a drive into restricted user WSL distributions, given user has access to elevated admin account.

Additional context

Restricted user:

C:\Users\User>wsl.exe -l -v
  NAME            STATE           VERSION
* Ubuntu          Running         2
  Alpine          Stopped         2
  Ubuntu-20.04    Stopped         2

C:\Users\User>wsl.exe --mount \\.\PHYSICALDRIVE1 --partition 1
Administrator access is needed to mount a disk.
Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK

If Admin has no installed distributions:

C:\Windows\system32>wsl.exe --mount \\.\PHYSICALDRIVE1 --partition 1
This operation is only supported by WSL2.
Error code: Wsl/Service/AttachDisk/WSL_E_WSL2_NEEDED

C:\Windows\system32>C:\Users\User\AppData\Local\Microsoft\WindowsApps\wsl.exe -l -v
Windows Subsystem for Linux has no installed distributions.

...

If Admin has installed distributions, mounting succeeds for Admin but disk is only visible in Admin's distributions.

Versions

>wsl --version
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.2364

Related/Duplicates

6147, #2979, #6414

massmog commented 1 year ago

I can confirm this issue on my installation of WSL2 and Ubuntu.

WSL version: 1.0.3.0 Kernel version: 5.15.79.1 WSLg version: 1.0.47 MSRDC version: 1.2.3575 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.2364

Lsblk shows drive only in WSL of elevated user. Mounting is only possible if elevated user has WSL installed.

meisenkaiser123 commented 1 year ago

I can confirm same problem:

As Admin

PS D:\WSL\shared> wsl --version WSL version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.2846 PS D:\WSL\shared> wsl --mount .\PhysicalDrive2 --bare

Error message: (I dont understand) _This operation is only supported by WSL2. Error code: Wsl/Service/AttachDisk/WSL_E_WSL2NEEDED

as user:

PS D:\WSL\shared> wsl -l -v NAME STATE VERSION

  • Ubuntu-18.04 Stopped 2 CentOS Running 2 EL8 Stopped 2 PS D:\WSL\shared> wsl --mount \.\PhysicalDrive2 --bare _Administrator access is needed to mount a disk. Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNTDISK PS D:\WSL\shared>
ramisedhom commented 1 year ago

Same here:

> wsl -v
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19044.2965

> wsl --mount \\.\PHYSICALDRIVE1
Administrator access is needed to mount a disk.
Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK
andrsmllr commented 1 year ago

Same here.

wsl -v WSL-version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22000.1574

wsl --mount \.\PHYSICALDRIVE1 Administrator access is needed to mount a disk. Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK

artarik commented 8 months ago

wsl 2 the same

PS C:\Users\user> wsl --mount \\.\PHYSICALDRIVE2
Administrator access is needed to mount a disk.
Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK
PS C:\Users\user> wsl -v
WSL-version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.3693
edumotya commented 3 weeks ago

wsl 2.2.4.0 the same :(

PS C:\Users\Eduardo> wsl --mount \\.\PHYSICALDRIVE1 --bare
Administrator access is needed to mount a disk.
Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK
PS C:\Users\Eduardo> wsl -v
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.19045.4529