berkshelf / vagrant-berkshelf

A Vagrant plugin to add Berkshelf integration to the Chef provisioners
Other
379 stars 100 forks source link

Plugin is broken in WSL after Windows 10 Fall Creators Update #323

Open poma opened 6 years ago

poma commented 6 years ago

When Ubuntu is installed from the App Store it gives the following error:

    homestead-7: /tmp/vagrant-chef/3c87ec80ba1f244bd8a309748dc7991f/cookbooks => /root/.berkshelf/vagrant-berkshelf/shelves/berkshelf20171022-18024-1spu6ki-homestead-7
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 v-csc-c77bf3bcf /tmp/vagrant-chef/3c87ec80ba1f244bd8a309748dc7991f/cookbooks

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: Protocol error

Which is likely caused by the fact that VirtualBox mounts

\\?\C:\Users\Poma\AppData\Local\lxss\root\.berkshelf\vagrant-berkshelf\shelves\berkshelf20171022-18024-1spu6ki-homestead-7

folder which does not exist because now Windows supports multiple Linux installations and path to this folder is different

Temporary workaround - create a directory junction in the old location

mklink /J C:\Users\%username%\AppData\Local\lxss C:\Users\%username%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

Should be executed from elevated command prompt

Maybe instead of trying to detect where the new linux filesystem is located it is better to vendor cookbooks to /mnt/c/Users/%username%/.berkshelf/....? It is generally a bad practice to access WSL filesystem from within windows.

BR0kEN- commented 6 years ago

For more precise and general way the PowerShell could be used.

$WSLREGKEY="HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss"
$WSLDEFID=(Get-ItemProperty "$WSLREGKEY").DefaultDistribution
$WSLFSPATH=(Get-ItemProperty "$WSLREGKEY\$WSLDEFID").BasePath
New-Item -ItemType Junction -Path "$env:LOCALAPPDATA\lxss" -Value "$WSLFSPATH\rootfs"
BR0kEN- commented 6 years ago

After investigating I can confirm the problem this issue describes. WSL's rootfs will be in %LOCALAPPDATA%\lxss only if it has been installed via lxrun /install /y. This way of installation is not recommended if OS build number is equal or later than 16215 (check https://docs.microsoft.com/en-us/windows/wsl/install-win10).

It seems to me like Vagrant issue (https://github.com/hashicorp/vagrant/blob/v2.0.1/lib/vagrant/util/platform.rb#L286-L289).