Getting an accès refusé trying to mount a VHDX to wsl on Windows 11

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Getting an accès refusé trying to mount a VHDX to wsl on Windows 11

Message par ForumBot »

I créé a nouveau VHDX using disk manager, and J'essaie de mount it to WSL2 (version 1.0.3), running the following command:

```
wsl -d Ubuntu-22.04 --mount --vhd D:\wsl2\wsl2-drive.vhdx --bare

```

It fails avec:

```
Failed to attach disk '\\?\D:\wsl2\wsl2-drive.vhdx' to WSL2: Access is denied.
Error code: Wsl/Service/AttachDisk/MountVhd/E_ACCESSDENIED

```

Things J'ai essayé which n'a pas make a difference:

- Run it from an elevated PowerShell

- Créez un VHD à la place of a VHDX

- Leaving out `--bare`

- Leaving out `-d Ubuntu-22.04`

- Having the VHDX is various different states:

- "Not Initialized / Unallocated": the state après creating in disk manager

- Choose 'Initialize disk' in Disk Manager

- Créez un partition (but that feels wrong, depuis it ne devrait pas be NTFS for Linux?)

- Detach it altogether in Disk Manager
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Getting an accès refusé trying to mount a VHDX to wsl on Windows 11

Message par ForumBot »

*Solved via the comments, so moving the information to an answer (avec some additional info).*

The (relatively) nouveau WSL erreur messages were useful in this case. The `Wsl/Service/AttachDisk/MountVhd/E_ACCESSDENIED` indicated a autorisations problème of *some* sort.

Normally, as far as Je peux tell, a `.vhdx` fichier créé through Disk Management sera owned by the local Administrators group. In most cases, the local utilisateur that installé and runs WSL is a member of this group, so il y a autorisations problèmes.

Cependant, in this case, that *seems* not to be the case, depuis changing the owner du `.vhdx` ultimately résolu the `ACCESSDENIED` erreur.

A few additional items:

-

The virtual disk *does* need to be detached from Disk Management (Right-Click -> *Detach VHD*) or the following erreur will occur:

```
Failed to attach disk '\wsl2-drive.vhdx' to WSL2: The process cannot access the file because it is being used by another process.
Error code: Wsl/Service/AttachDisk/MountVhd/0x80070020

```

-

I personally recommend creating the `.vhdx` from an Administrative PowerShell compte using:

```
new-vhd -Dynamic -SizeBytes 100gb -BlockSizeBytes 1mb -path /.vhdx

```

The block size turns out to be pretty important in how quickly the dynamic disk will grow. The 1 mb block size is what WSL uses for its built-in virtual disks.

-

Également, `--bare` is required as long as il n'y a pas de filesystem sur le drive that WSL can handle. Your next step is going to be to créez un filesystem on that virtual drive from *within* WSL. As mentioned dans le [WSL doc](https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk#attaching-the-disk-without-mounting-it), use `lsblk` to identify the newly mounted disk.

Ce n'est pas a bad idea to be completely sure that you are formatting the proper périphérique by unmounting, `lsblk`, ensuite remount and `lsblk` again. The nouveau périphérique sera obvious in that case. Of course, a unique drive size is a valid way to identify it également.

Once you've identified the périphérique, vous allez use quelque chose like:

```
sudo mkfs.ext4 /dev/ # e.g. sde

```

-

Après you créez un filesystem sur le périphérique, as long as the filesystem is one that WSL2 recognizes (`ext4`, `btrfs`, and probably a few others), vous pouvez skip the `--bare` option on future mounts.

At that point, c'est a good idea to switch to using `--name ` so that the partition/filesystem sera mounted in a known location. By par défaut, this sera `/mnt/wsl/`.

-

The `-d Ubuntu-22.04` in this case is a no-op. Je suis un bit surprised that it ne generate an erreur, but the périphérique is toujours mounted into *all* distributions, regardless of whether you specify a distro using `wsl -d` or not.
Répondre

Revenir à « Windows 11 »