Open dot-mike opened 1 year ago
Turns out I had more than one WSL distribution installed as shown below and the fact that rootfs
is no longer available in WSL2 is causing issues. (see issue https://github.com/microsoft/WSL/issues/6221)
To fix this I updated the script to first find the registry path for the current distro and then query the BasePath for the distro GUID using the newly found registry path 😄
Update line 1-5 as follows:
#!/bin/bash
# Get the Windows registry path for the current WSL distro
wsl_distro_regpath=$(reg.exe query "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Lxss" /s /f DistributionName 2>&1 | sed -e 's|\r||g' | grep -B1 -e "$WSL_DISTRO_NAME$" | head -n1)
# Get path for WSL storage
wslroot=$(wslpath $(reg.exe query $wsl_distro_regpath /s /v BasePath | awk 'BEGIN { FS = "[ \t]+" } ; /BasePath/{print $4}' | tr -d "[:cntrl:]"))
Comment out the if-clause for the floopy-disk check so it becomes:
# Packer tries to create floppy in the linux /tmp folder which is not representable in Windows. Replace it with direct storage path
#if [[ $argument == /tmp/* ]]; then
#argument="$wslroot/rootfs$argument"
#fi
Issue showing multiple WSL distros:
$ reg.exe query "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Lxss" /s /f DistributionName
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{2917863d-fe64-4014-ae04-f3121232474d}
DistributionName REG_SZ docker-desktop
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{ef66b4e7-1c22-4297-b9e9-5f84bd69a473}
DistributionName REG_SZ docker-desktop-data
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{fe915138-9e0c-44a0-bc0c-165279ae48ca}
DistributionName REG_SZ Ubuntu-22.04
#!/bin/bash
# Get the Windows registry path for the current WSL distro
wsl_distro_regpath=$(reg.exe query "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Lxss" /s /f DistributionName 2>&1 | sed -e 's|\r||g' | grep -B1 -e "$WSL_DISTRO_NAME$" | head -n1)
# Get path for WSL storage
wslroot=$(wslpath $(reg.exe query $wsl_distro_regpath /s /v BasePath | awk 'BEGIN { FS = "[ \t]+" } ; /BasePath/{print $4}' | tr -d "[:cntrl:]"))
# Initialize defaults
is_next_path=0
args=()
for argument; do
# If the current argument is --medium expect path of the medium in next argument
if [ "$argument" == 'none' ]; then
is_next_path=0
elif [ "$argument" = '--medium' ]; then
is_next_path=1
elif [ $is_next_path = 1 ]; then
# Packer tries to create floppy in the linux /tmp folder which is not representable in Windows. Replace it with direct storage path
#if [[ $argument == /tmp/* ]]; then
#argument="$wslroot/rootfs$argument"
#fi
# Convert WSL paths to Windows path
argument=$(wslpath -w "$argument")
is_next_path=0
fi
args+=("\"$argument\"")
done
# Redirect to Windows VBoxManage and convert Windows paths back to WSL paths
echo "${args[@]}" | xargs /mnt/c/Program\ Files/Oracle/VirtualBox/VBoxManage.exe | sed -r '/[A-Za-z]:\\.*$/{h; s/(.*)([A-Za-z]:\\.*)$/\2/; s/(.+)/wslpath "\1"/e; H; x; s/(([A-Za-z]:\\.*)\n(.+))/\3/ }'
# /[A-Za-z]:\\.*$/ # Find lines that end with Windows paths
# { # For each line
# h; # Copy to hold storage
# s/(.*)([A-Za-z]:\\.*)$/\2/; #Remove everything except the path
# s/(.+)/wslpath "\1"/e; #Convert the path to WSL path
# H; # Append to the hold storage
# x; # Swap pattern storage with hold storage
# # Pattern storage have 2 lines now:
# # SAMPLE C:\Windows\Temp
# /mnt/c/Windows/Temp
# s/(([A-Za-z]:\\.*)\n(.+))/\3/ # Replace Windows path in the first line with the WSL path in the second line
#
This is how the path for the floppy-disk looks like to VirtualBox: This is a valid UNC path (https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats)
Hello, I'm using this and seeing floppy disk is failing to attach with WSL2.
Error log:
Version info: