If your WSL2 suddenly throws an error like:
Failed to attach disk 'F:\ext4.vhdx' to WSL2: Access is denied.
Error code: Wsl/Service/CreateInstance/MountDisk/HCS/E_ACCESSDENIED
This usually happens because Windows lost permissions to access your WSL2 disk image (ext4.vhdx
). Here's a quick fix:
Step-by-Step Solution
- Open PowerShell as Administrator.
- Run these commands (replace
F:\ext4.vhdx
with your actual VHDX file location):$VhdPath = "F:\ext4.vhdx" wsl --shutdown icacls $VhdPath /grant:r 'SYSTEM:(F)' 'Administrators:(F)' /inheritance:e icacls $VhdPath /grant '*S-1-5-83-0:(M)' attrib +R $VhdPath
- This sets permissions properly for SYSTEM, Administrators, and WSL2 Virtual Machines.
- The
attrib +R
command makes the file read-only, preventing antivirus or backup software from interfering with permissions.
- Restart WSL2 by simply running:
wsl
Confirm the Fix
To double-check permissions:
icacls $VhdPath
You should see entries for SYSTEM
, Administrators
, and a group SID starting with S-1-5-83-0
.
That's it! Your WSL2 environment should now work smoothly after reboots or updates.
No comments:
Post a Comment
Hey, thank you for spending time leaving some thoughts, that would be really helpful as encouragement for us to write more quality articles! Thank you!