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 '<path_to>\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 <path_to>/<name>.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, 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/<device> # 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 <name> so that the partition/filesystem sera mounted in a known location. By par défaut, this sera /mnt/wsl/<name>.
-
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.