Using Ubuntu Bash in Windows Creators' Update with Vagrant

When Microsoft announced the Windows Subsystem for Linux, now seemingly rebranded as Bash on ubuntu on Windows, I was excited at the possibility of having Drupal VM (and other similarly command-line-friendly open source projects) work better in a Windows environment. But unfortunately, the Anniversary update's version of WSL/Ubuntu Bash was half-baked, and there were a lot of little issues trying to get anything cohesive done between the Windows and Ubuntu Bash environments (even with cbwin).

Then, a year or so later, Microsoft finally announced that tons of improvements (including upgrading Ubuntu in the WSL from 14.04 to 16.04!) would be included in the 'Creators Update' to Windows 10, dropping tomorrow, April 11.

One of the major improvements would be the ability to call out to Windows executables from within Ubuntu Bash, which was added in October 2016, but only available to those willing to run Microsoft's bleeding-edge 'Insider' builds. This feature is going to be included with the rest of the improvements in the Creator's update, so I thought I'd update early and explore whether this is the panacea I dreamt of when I first heard about WSL/Ubuntu Bash.

tl;dr: It's not a panacea. But it is something. And things are improved significantly from where we were one year ago, as far as open source devs who develop in Windows (by choice or by dictum).

How to update to Windows 10 'Creators Update'

If it's April 11 or later, you can just use Windows Auto Update mechanism to upgrade to the Creators Update version of Windows 10. It seems the ISO images are already on microsoft.com, and it's only April 10 where I live, so I'm not sure when your particular computer will see the update become available for install.

How to Install WSL/Ubuntu Bash

Note: If you've previously installed Ubuntu Bash on an older version of Windows, and want to get the new version running Ubuntu 16.04 instead of 14.04, you need to run Powershell as administrator, and enter the command lxrun /uninstall /full.

  1. Run lxrun /install /y
  2. After installation is finished, enter 'Ubuntu' in Cortana/search and open "Bash on Ubuntu on Windows"
  3. Confirm you're on Ubuntu 16.04 by running lsb_release -a

Use Vagrant with Ubuntu Bash

  1. Add Windows executables to your Ubuntu $PATH: `export PATH=$PATH:/mnt/c/Windows/System32/
  2. Test that Vagrant is callable by running vagrant.exe status
  3. Change directories to a location that's accessible to Windows (e.g. cd /mnt/c/Users/yourusername).
  4. Clone a Vagrant-based project locally: git clone https://github.com/geerlingguy/drupal-vm.git
  5. Change directories into the project dir: cd drupal-vm
  6. Run vagrant.exe up.

Note that, currently, you can't run vagrant.exe ssh from within Ubuntu Bash. You have to either use Cmder or a similar CLI for that, or run vagrant.exe ssh-config, then run a manual SSH command (ssh -p [port] vagrant@127.0.0.1) to connect to your VM from within Ubuntu Bash.

Necessary improvements

I'm hopeful that Microsoft may be able to find ways to allow Windows executables (like Vagrant) see and use binaries in the WSL environment (e.g. Vagrant.exe can call out to Ubuntu's ssh). In lieu of that, I wonder if Vagrant itself may be able to make some improvements to make it easier for Windows users to do things like vagrant ssh and other esoteric commands without resorting to Cygwin.

I'm still working through some of these issues and trying to find the best path forward (especially for beginners) in the Drupal VM issue queue: Update docs for Windows with WSL Windows Interoperability improvements.

I've also left feedback in the Vagrant project's issue dealing with the WSL (Use Linux Subsystem on Windows), but I think as more developers start using Vagrant and WSL together, we may find clever ways of working around the current limitations.

You could also just run Linux or macOS as your desktop OS, and avoid these issues entirely ;-)

Comments

Don't forget apt update && apt upgrade after installing 16.04.

Have you tried to use nfs shared folder via WSL like on linux or macOS ?

I didn't try it myself, but what about installing vagrant for Ubuntu instead?

There is a way to hack it to work with VirtualBox.exe, but it requires a lot of annoying setup that would need to be redone any time you upgraded Vagrant in the future.

Jeff, Drupal VM already works great with native Windows, VirtualBox, and Vagrant (without any WSL). I'm not understanding what would be the benefit of running it this way by calling the Windows vagrant.exe from within WSL?

Thanks!
--Tony

In some instances, e.g. where your project requires Composer to be used just to do the initial setup, it can be easier to use Composer (and maybe even something like Node.js) inside the WSL. And if that's the case, then being able to also call vagrant.exe up in WSL saves the step of having a second terminal window up just to manage the VM.

Hi All,
I install and run Ubuntu fine. I even install Xming server and be able to run eclipse, firefox, ... Except one more thing!! I can not play any sound as Ubuntu does not recognize the audio devices on my laptop!!
henry@henry-lenova1:~$ aplay -l
aplay: device_list:268: no soundcards found...
henry@henry-lenova1:~$

Any solution for this problem yet?
Henry

I haven't tried using any hardware devices in the Ubuntu Bash environment... but it looks like it might be unsupported, or at least hard to do properly. See https://github.com/Microsoft/BashOnWindows/issues/1200.

Thanks for the pointer. But the solutions are basically simulations. I wonder how VirtualBox can access directly to the device?

Hey Jeff thanks first of all for the great write up above. Finding this blog really helped me start to get set up with vagrant and ansible on Windows 10. One thing I'm still not sure about however and the various other guides I've found are not explicit on this front. I note the slight change from above is that now Vagrant 1.9.5 version is supported natively in WSL per this link:

https://github.com/mitchellh/vagrant/blob/v1.9.5/CHANGELOG.md

I can see you've been commenting in there too hence how I found it :) I installed latest version of vagrant (1.9.5) within Bash on Ubuntu on Windows (clunkiest name ever...) and removed the windows version.

Now however when I run vagrant status I get error:

Vagrant will not operate outside the Windows Subsystem for Linux unless explicitly
instructed. Due to the inability to enforce expected Linux file ownership and
permissions on the Windows system, Vagrant will not make modifications to prevent
unexpected errors. To learn more about this, and the options that are available,
please refer to the Vagrant documentation:

https://www.vagrantup.com/docs/other/wsl

If I navigate into an existing vagrant build and run "vagrant up" I get:

The executable 'vagrant.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.

So it would appear that the native WSL version of vagrant is still trying to call the Windows installed variant which in my case is no longer installed. Has anyone managed to get vagrant working in this way *without* the native Windows version or is the Windows version still needed?

This link references issues with "vagrant up" command also on 1.9.5 and there mentions that both Windows and WSL vagrant versions are installed. Some clarity here would be good.

https://github.com/mitchellh/vagrant/issues/8604

cheers, Kiweegie.

Yeah, I'm trying to get some time to mess around with 1.9.5 soon—I just haven't had time to tinker with it since it was released :(

Based on my head-against-brick-walling today, I can verify that Vagrant 1.9 needs to be installed both in the WSL and on Windows, after which it works perfectly (with the VAGRANT_WSL_ENABLE_WINDOWS_ACCESS env var set to 1).

Hi Jeff!

I started experimenting with WSL and Vagrant as well. I also noticed that you have to have Vagrant installed in both environments. At first I was able to access the Windows Vagrant from bash with, for example, "vagrant.exe --version", but now bash just reports "stdin is not a tty" to me and nothing else. I'm able to access the executable normally via Windows cmd.

Have you had any similar problems? I can't seem to find anything on the web related to this issue.