hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.23k stars 4.43k forks source link

WSL2 Vagrant Failing To Execute Any Vagrant Commands - Permission Denied #13212

Open ghost opened 1 year ago

ghost commented 1 year ago

When using WSL2 on Windows 11 (Ubuntu 22.04 LTS Distro), and installing both Vagrant on the Windows Machine and WSL2, setting up the environment variables and running any vagrant command. I get a permission denied issue. Virtual Box and Vagrant are both installed on the windows machine, I'm running WSL2 as an admin.

Debug output

/opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:160:in `rescue in execute': Permission denied - /mnt/c/Program Files/powershell (Vagrant::Util::Subprocess::LaunchError)
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:153:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:22:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:191:in `version'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:212:in `validate_install!'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:113:in `execute_cmd'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:82:in `block in windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:84:in `windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/providers/hyperv/provider.rb:20:in `usable?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:378:in `block in default_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:49:in `block in each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:48:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:48:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:364:in `default_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:968:in `guess_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:980:in `find_configured_plugins'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:1008:in `process_configured_plugins'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:189:in `initialize'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:211:in `new'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:211:in `<main>'
/opt/vagrant/embedded/gems/gems/childprocess-4.1.0/lib/childprocess/unix/fork_exec_process.rb:66:in `launch_process': Permission denied - /mnt/c/Program Files/powershell (ChildProcess::LaunchError)
        from /opt/vagrant/embedded/gems/gems/childprocess-4.1.0/lib/childprocess/abstract_process.rb:81:in `start'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:155:in `block in execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:26:in `block (2 levels) in safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:25:in `chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:25:in `block in safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:24:in `synchronize'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:24:in `safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:154:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:22:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:191:in `version'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:212:in `validate_install!'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:113:in `execute_cmd'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:82:in `block in windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:84:in `windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/providers/hyperv/provider.rb:20:in `usable?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:378:in `block in default_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:49:in `block in each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:48:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/registry.rb:48:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:364:in `default_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:968:in `guess_provider'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:980:in `find_configured_plugins'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:1008:in `process_configured_plugins'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:189:in `initialize'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:211:in `new'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:211:in `<main>'

https://gist.github.com/DaneParcJr/3a938d7eb241d406410517f32c36ea3b

Expected behavior

Actual behavior

Expected Vagrant to run without a permission denied error.

Reproduction information

Vagrant version

2.3.7 Linux 2.3.7 Windows

Host operating system

Windows 11

Guest operating system

Ubuntu 22.0.4 LTS

Steps to reproduce

  1. Install WSL2
  2. Install Vagrant on Windows Machine
  3. Install Virtualbox on Windows Machine
  4. Install Vagrant (matching version) on WSL2
  5. Set VAGRANT_WSL_ENABLE_WINDOWS_ACCESS variable to "1"
  6. Set PATH variable to export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
  7. Run any vagrant command

Vagrantfile

# Copy-paste your Vagrantfile here. Remove any sensitive information such as passwords, authentication tokens, or email addresses.
vtimbadiya commented 1 year ago

i have the same issue and i have set

Set VAGRANT_WSL_ENABLE_WINDOWS_ACCESS variable to "1" Set PATH variable to export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"

but not luck

javelwill commented 1 year ago

Hi @DaneParcJr @vtimbadiya have you been able to resolve this issue?

vtimbadiya commented 1 year ago

@javelwill No it still has the issue ,but the root cause is security software, which blocks the sub process Lunch. Tested in another machine where it worked

javelwill commented 1 year ago

@DaneParcJr @vtimbadiya I had a similar issue. The error I encountered was:

Permission denied - /mnt/c/Program Files/Microsoft System Center/Service Manager//powershell (Vagrant::Util::Subprocess::LaunchError)

It seems Vagrant was trying to find powershell and found /mnt/c/Program Files/Microsoft System Center/Service Manager/powershell which was appended from the Windows PATH before it could find the actual powershell.exe executable in its correct location.

I removed that path by appending the following line at the end of my .bashrc file - nano ~/.bashrc:

export PATH=$(echo $PATH | sed 's|:/mnt/c/Program Files/Microsoft System Center/Service Manager/||g')

After doing so I loaded the changes - source ~/.bashrc and my issue was resolved.

I hope this helps!

Gjovani commented 1 year ago

I had the same issue but in my case I added export VAGRANT_DEFAULT_PROVIDER="virtualbox" in the .bashrc file and it worked!

Now I have another error but that's not related to this issue 😅

edit: the other issue was related to some host path, but that was fixed using: issues/10576

vtimbadiya commented 1 year ago

This is working after export VAGRANT_DEFAULT_PROVIDER="virtualbox" Thanks @Gjovani

helarnl commented 1 year ago

Looks like this is not working for hyperv export VAGRANT_DEFAULT_PROVIDER="hyperv"

abh80 commented 1 year ago

Same issue here with windows 11 and WSL2 and using hyperv

Gjovani commented 1 year ago

hey @helarnl and @abh80 , do you have the same version of Vagrant installed on WSL and Windows? If so, you could also try and add export PATH="$PATH:/mnt/c/ProgramData/Microsoft/Windows/Hyper-V" in the .bashrc file (don't forget to load the changes with the command source ~/.bashrc, as mentioned above)

abh80 commented 1 year ago

@Gjovani Thanks for the reply. Just tested it both my Windows and WSL are using Vagrant 2.3.7. The error is still same after adding it to PATH.

/opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:160:in `rescue in execute': Permission denied - /mnt/c/Windows/system32/powershell (Vagrant::Util::Subprocess::LaunchError)
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:153:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:22:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:191:in `version'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:212:in `validate_install!'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:113:in `execute_cmd'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:82:in `block in windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:84:in `windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/providers/hyperv/provider.rb:20:in `usable?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:156:in `machine_config'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:49:in `machine'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:740:in `machine'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:180:in `block in with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:204:in `block in with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:in `with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/commands/up/command.rb:87:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/cli.rb:67:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:301:in `cli'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:248:in `<main>'
/opt/vagrant/embedded/gems/gems/childprocess-4.1.0/lib/childprocess/unix/fork_exec_process.rb:66:in `launch_process': Permission denied - /mnt/c/Windows/system32/powershell (ChildProcess::LaunchError)
        from /opt/vagrant/embedded/gems/gems/childprocess-4.1.0/lib/childprocess/abstract_process.rb:81:in `start'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:155:in `block in execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:26:in `block (2 levels) in safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:25:in `chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:25:in `block in safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:24:in `synchronize'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/safe_chdir.rb:24:in `safe_chdir'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:154:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:22:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:191:in `version'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:212:in `validate_install!'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:113:in `execute_cmd'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:82:in `block in windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:84:in `windows_admin?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/providers/hyperv/provider.rb:20:in `usable?'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:156:in `machine_config'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:49:in `machine'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:740:in `machine'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:180:in `block in with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:204:in `block in with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:in `with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/commands/up/command.rb:87:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/cli.rb:67:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:301:in `cli'
        from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:248:in `<main>

I have also tried running wsl as admin and it dosent work still

abh80 commented 1 year ago

@DaneParcJr @vtimbadiya any update on this? I am trying this with WSL2 and Windows 11 with hyper v. The details are above

vtimbadiya commented 1 year ago

@abh80 try this

  add this :WSLInterop:M::MZ::/init:PF  to  /usr/lib/binfmt.d/WSLInterop.conf
  sudo systemctl restart systemd-binfmt
  sudo apt update
  sudo apt install binfmt-support
  sudo ls -Fal /proc/sys/fs/binfmt_misc
helarnl commented 1 year ago

Same issue

/opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:160:in rescue in execute': Permission denied - /mnt/c/WINDOWS/system32/powershell (Vagrant::Util::Subprocess::LaunchError) from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:153:inexecute' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/subprocess.rb:22:in execute' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:191:inversion' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:212:in validate_install!' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/powershell.rb:113:inexecute_cmd' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:82:in block in windows_admin?' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/util/platform.rb:84:inwindows_admin?' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/providers/hyperv/provider.rb:20:in usable?' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:156:inmachine_config' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/vagrantfile.rb:49:in machine' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:740:inmachine' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:180:in block in with_target_vms' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:204:inblock in with_target_vms' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:in each' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/plugin/v2/command.rb:186:inwith_target_vms' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/plugins/commands/up/command.rb:87:in execute' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/cli.rb:67:inexecute' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/lib/vagrant/environment.rb:301:in cli' from /opt/vagrant/embedded/gems/gems/vagrant-2.3.7/bin/vagrant:248:in

'

My VARS

export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1" export PATH="$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0" export PATH="$PATH:/mnt/c/WINDOWS/system32" export VAGRANT_DEFAULT_PROVIDER="hyperv" export PATH="$PATH:/mnt/c/ProgramData/Microsoft/Windows/Hyper-V"