Vagrant is launching Windows executables straight from Linux. If Linux is running as the Windows Subsystem for Linux (WSL/WSL2) or as a Docker container under the Windows host, Vagrant from Linux will look for the PowerShell executable file powershell.exe in Windows. You only need to add the path of PowerShell to the PATH environment variable under Linux. For example, if you mount Windows drive C: as /mnt/c on Linux, add the following PATH variable:
export PATH="$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0"
You can add the above line to your ~/.profile file and reload it using the following commands:
nano ~/.profile
source ~/.profile
This way, Vagrant will be able to start.
Through the environment variable VAGRANT_WSL_ENABLE_WINDOWS_ACCESS, Vagrant understands that it may access the Windows system to run executable files and use functions such as synced folders. You can find more about this variable on a respective page at Vagrant official site. Thus, you may also need to add the following variable:
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
With this variable, Vagrant will start Windows executables files from Linux, including the Windows cmd.exe command-line interpreter. Therefore, you should also need to add path to cmd.exe:
export PATH="$PATH:/mnt/c/Windows/System32"
Otherwise, you will get the following error.
The executable 'cmd.exe' Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.
And if you are using VirtualBox installed in Windows Host, you will also need to add the path to it:
export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
Since Linux under WSL is running within a virtual machine, you will not be able to run a hypervisor for Linux like VirtualBox what would have run under WSL. So Vagrant from Linux will be using VirtualBox installed on the Windows host.
Please make sure that you are using the latest version of Vagrant, or at least 2.2.15, otherwise it may not be able to run Windows executables from Linux properly. Anyway, running Vagrant from Linux to create virtual machines in Windows VirtualBox does not always run smoothly, you may get errors like that:
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "a1d5c124-261b-4e4b-a11a-88f7bfdda6df", "--type", "headless"]
Stderr: VBoxManage.exe: error: Failed to get device handle and/or partition ID for
0000000001cf34e0 (hPartitionDevice=0000000000000a39, Last=0xc0000002/1)
(VERR_NEM_VM_CREATE_FAILED)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
To avoid these errors, and make Vagrant to work reliably, just run Linux under physical hardware, not from WSL or a docker container under Windows. In this case, VirtualBox will also be running from Linux, and Vagrant will not need to communicate between Linux and Windows by running Windows executables on Linux.
There is a YouTube video on how to install Vagrant under Ubuntu 18 in WSL1 for Windows 10 and VirtualBox. But since this video demonstrates the use of older software, newer software may not work as described in the video. You may run Vagrant with --debug command line option to figure out what's wrong, but this may not always help find the solution. Here is an example of running Vagrant with debug output:
vagrant --debug up