Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsl mount vhd not working #8165

Closed
1 of 2 tasks
SquallATF opened this issue Mar 18, 2022 · 15 comments
Closed
1 of 2 tasks

wsl mount vhd not working #8165

SquallATF opened this issue Mar 18, 2022 · 15 comments
Labels

Comments

@SquallATF
Copy link

SquallATF commented Mar 18, 2022

Version

Microsoft Windows [Version 10.0.22000.556]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.102.1

Distro Version

Ubuntu 20.04

Other Software

No response

Repro Steps

wsl --mount --vhd workdata.vhdx
but if use Mount-VHD command, and mount with DiskPath will successful mount.

Expected Behavior

mount vhd successful

Actual Behavior

K:\>wsl --mount --vhd workdata.vhdx
拒绝访问。

Diagnostic Logs

No response

@benhillis
Copy link
Member

The --vhd option is only available via the Store version of WSL.

@SquallATF
Copy link
Author

SquallATF commented Mar 19, 2022

The --vhd option is only available via the Store version of WSL.

my wsl is store version @benhillis 拒绝访问 means access denied

wsl --version
WSL 版本: 0.56.2.0
内核版本: 5.10.102.1
WSLg 版本: 1.0.30
MSRDC 版本: 1.2.2924
Direct3D 版本: 1.601.0
Windows 版本: 10.0.22000.556

@leonidasthe300
Copy link

Same problem here. I´m getting access denied.

Versão do WSL: 0.56.2.0
Versão do kernel: 5.10.102.1
Versão do WSLg: 1.0.30
Versão do MSRDC: 1.2.2924
Versão do Direct3D: 1.601.0
Versão do Windows: 10.0.22000.556

@leonidasthe300
Copy link

Hi @SquallATF , try this:

If you mounted the disk in the past using wsl --mount, before installling the wsl preview from the store:

  1. run wsl --shutdown

  2. make a copy of the vhdx file

  3. try now wsl --mount --vhd 'vhdx copy'

Does it show the same error?

@benhillis
Copy link
Member

/logs

@benhillis benhillis reopened this Mar 21, 2022
@ghost
Copy link

ghost commented Mar 21, 2022

Hello! Could you please provide more logs to help us better diagnose your issue? You can find instructions on how to attach logs here, please make sure to post the link to the Feedback Hub item in this chat so we can see it.

Thank you!

@leonidasthe300
Copy link

leonidasthe300 commented Mar 21, 2022

Hello! Could you please provide more logs to help us better diagnose your issue? You can find instructions on how to attach logs here, please make sure to post the link to the Feedback Hub item in this chat so we can see it.

Thank you!

Just uploaded the logs with the feedback hub here: https://aka.ms/AAgbnmc

I recorded it not working, and following these steps I described here #8165 (comment) it works,

@SquallATF
Copy link
Author

SquallATF commented Mar 22, 2022

Hi @SquallATF , try this:

If you mounted the disk in the past using wsl --mount, before installling the wsl preview from the store:

1. run wsl --shutdown

2. make a copy of the vhdx file

3. try now wsl --mount --vhd 'vhdx copy'

Does it show the same error?

I have make a copy of the vhdx and mount successful. Then I tested create new vhd and vhdx, all of them can mount successful.
But I still have a question the vhdx file that cannot be mounted is actually a new one created by Disk Management. That vhdx file still mount failed.

I seem to have found the cause of the problem, if vhd/vhdx is created by Disk Management and did not detach from Disk Management, then run wsl --mount --vhd command to mount that vhdx will report access denied. Then detach that vhdx from Disk Management, wsl mount will always report access denied. After that, even delete the vhdx and then create a new vhdx with the same name, it still cannot be mounted. Even after reboot the computer.

Some test, message is translated from Chinese

K:\>wsl --mount --vhd test1.vhdx
access denied.


K:\>copy test1.vhdx test2.vhdx
         1 file(s) copied.

K:\>ren test1.vhdx test3.vhdx

K:\>wsl --mount --vhd test2.vhdx
Disk attached but mount failed: Operation not permitted.
For more information, run 'dmesg' in WSL2.
To detach the disk, run 'wsl.exe --unmount \\?\K:\test2.vhdx'.

K:\>wsl --mount --vhd test3.vhdx
access denied.

K:\>wsl --unmount test2.vhdx
The operation completed successfully.

K:\>ren test2.vhdx test1.vhdx

K:\>ren test3.vhdx test2.vhdx

K:\>wsl --mount --vhd test1.vhdx
Disk attached but mount failed: Operation not permitted.
For more information, run 'dmesg' in WSL2.
To detach the disk, run 'wsl.exe --unmount \\?\K:\test1.vhdx'.

K:\>wsl --mount --vhd test2.vhdx
access denied. 

Feedback Hub logs https://aka.ms/AAgczv8

@ghost ghost removed the needs-author-feedback label Mar 22, 2022
@leonidasthe300
Copy link

Hi @SquallATF , try this:
If you mounted the disk in the past using wsl --mount, before installling the wsl preview from the store:

1. run wsl --shutdown

2. make a copy of the vhdx file

3. try now wsl --mount --vhd 'vhdx copy'

Does it show the same error?

I have make a copy of the vhdx and mount successful. Then I tested create new vhd and vhdx, all of them can mount successful. But I still have a question the vhdx file that cannot be mounted is actually a new one created by Disk Management. That vhdx file still mount failed.

I seem to have found the cause of the problem, if vhd/vhdx is created by Disk Management and did not detach from Disk Management, then run wsl --mount --vhd command to mount that vhdx will report access denied. Then detach that vhdx from Disk Management, wsl mount will always report access denied. After that, even delete the vhdx and then create a new vhdx with the same name, it still cannot be mounted. Even after reboot the computer.

Some test, message is translated from Chinese

K:\>wsl --mount --vhd test1.vhdx
access denied.


K:\>copy test1.vhdx test2.vhdx
         1 file(s) copied.

K:\>ren test1.vhdx test3.vhdx

K:\>wsl --mount --vhd test2.vhdx
Disk attached but mount failed: Operation not permitted.
For more information, run 'dmesg' in WSL2.
To detach the disk, run 'wsl.exe --unmount \\?\K:\test2.vhdx'.

K:\>wsl --mount --vhd test3.vhdx
access denied.

K:\>wsl --unmount test2.vhdx
The operation completed successfully.

K:\>ren test2.vhdx test1.vhdx

K:\>ren test3.vhdx test2.vhdx

K:\>wsl --mount --vhd test1.vhdx
Disk attached but mount failed: Operation not permitted.
For more information, run 'dmesg' in WSL2.
To detach the disk, run 'wsl.exe --unmount \\?\K:\test1.vhdx'.

K:\>wsl --mount --vhd test2.vhdx
access denied. 

Yes, you can run
wmic diskdrive get Availability,Capabilities,CapabilityDescriptions,DeviceID,InterfaceType,MediaLoaded,MediaType,Model,Name,Partitions
and check the states of the disks after a restart to see it.

@SquallATF
Copy link
Author

Yes, you can run
wmic diskdrive get Availability,Capabilities,CapabilityDescriptions,DeviceID,InterfaceType,MediaLoaded,MediaType,Model,Name,Partitions
and check the states of the disks after a restart to see it.

vhdx is not show in that list

@leonidasthe300
Copy link

Yes, you can run
wmic diskdrive get Availability,Capabilities,CapabilityDescriptions,DeviceID,InterfaceType,MediaLoaded,MediaType,Model,Name,Partitions
and check the states of the disks after a restart to see it.

vhdx is not show in that list

Yes, the same happens here. Even if the disk is not mounted, we get the message access denied. I uploaded the logs with the 2 scenarios.

@SquallATF
Copy link
Author

SquallATF commented Mar 23, 2022

I found the reason for wsl return access denied. if the vhd is created under the user profile directory , the vhd owner is BUILTIN\Administrators and access is NT AUTHORITY\SYSTEM. But if the vhd is created outside the user profile directory, the vhd access will changed to BUILTIN\Administrators, then wsl --mount --vhd will get access denied. when make a copy of that vhd the owner will changed to local user and mount will succeed.

image

image

After fix vhd acl, the vhd can be mounted successfully.

@leonidasthe300
Copy link

I found the reason for wsl return access denied. if the vhd is created under the user profile directory , the vhd owner is BUILTIN\Administrators and access is NT AUTHORITY\SYSTEM. But if the vhd is created outside the user profile directory, the vhd access will changed to BUILTIN\Administrators, then wsl --mount --vhd will get access denied. when make a copy of that vhd the owner will changed to local user and mount will succeed.

image

image

After fix vhd acl, the vhd can be mounted successfully.

I just checked th ACL on the vhdx files like you said.

But my vhdx files always are created and kept outside user profile directory.

I tried New-VHD and the Disk Manager for creating the files, both creates it with the same ACL.

I wonder, isn´t the original ACL the correct way? Should we really changed it? For now, it works.

@SquallATF
Copy link
Author

I just checked th ACL on the vhdx files like you said.

But my vhdx files always are created and kept outside user profile directory.

I tried New-VHD and the Disk Manager for creating the files, both creates it with the same ACL.

I wonder, isn´t the original ACL the correct way? Should we really changed it? For now, it works.

There is a small mistake in the previous explanation, the local user has access rights to the vhdx created in the user profile directory but does not have access rights to the vhdx created outside the user profile directory.
图片
图片

@OneBlue
Copy link
Collaborator

OneBlue commented Apr 20, 2022

Thanks for reporting this @SquallATF.

Looking at the logs, WSL is getting access denied when trying to attach the disk to the VM, which shows that the ACL on the file don't allow full control the user.

Closing since this is by-design (WSL can't bypass the filesystem ACL when mounting vhd's).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants