From 83b0c87f52d7be7edfc73b9e65a8c841c32d705b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 May 2017 19:02:15 -0700 Subject: [PATCH 1/8] Support running Vagrant within the Windows Subsystem for Linux --- bin/vagrant | 7 ++ lib/vagrant/errors.rb | 4 + lib/vagrant/util/platform.rb | 87 +++++++++++++++++++++ lib/vagrant/util/ssh.rb | 2 +- plugins/providers/virtualbox/driver/base.rb | 6 ++ plugins/providers/virtualbox/provider.rb | 14 ++-- templates/locales/en.yml | 10 +++ 7 files changed, 124 insertions(+), 6 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 080b7a7c8..42c239f40 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -112,6 +112,13 @@ begin argv += argv_extra end + # If we are running with the Windows Subsystem for Linux do + # some extra setup to allow access to Vagrant managed machines + # outside the subsystem + if Vagrant::Util::Platform.wsl? + Vagrant::Util::Platform.wsl_init(logger) + end + # Create the environment, which is the cwd of wherever the # `vagrant` command was invoked from logger.debug("Creating Vagrant environment") diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 94bbe6371..6fb07803b 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -780,6 +780,10 @@ module Vagrant error_key(:vboxmanage_not_found_error) end + class VBoxManageNotFoundWSLError < VagrantError + error_key(:vboxmanage_not_found_wsl_error) + end + class VirtualBoxBrokenVersion040214 < VagrantError error_key(:virtualbox_broken_version_040214) end diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 09dcbbc16..24b315987 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -28,6 +28,27 @@ module Vagrant return @_cygwin end + def wsl? + if !defined?(@_wsl) + @_wsl = false + original_verbose = $VERBOSE + begin + $VERBOSE = nil + # Use PATH values to check for `/mnt/c` path indicative of WSL + if ENV.fetch("PATH", "").downcase.include?("/mnt/c") + # Validate WSL via uname output + uname = Subprocess.execute("uname", "-r") + if uname.exit_code == 0 && uname.stdout.downcase.include?("microsoft") + @_wsl = true + end + end + ensure + $VERBOSE = original_verbose + end + end + @_wsl + end + [:darwin, :bsd, :freebsd, :linux, :solaris].each do |type| define_method("#{type}?") do platform.include?(type.to_s) @@ -223,6 +244,72 @@ module Vagrant return @_platform end + # Determine if given path is within the WSL rootfs. Returns + # true if within the subsystem, or false if outside the subsystem. + # + # @param [String] path Path to check + # @return [Boolean] path is within subsystem + def wsl_path?(path) + wsl? && !path.to_s.downcase.start_with?("/mnt/") + end + + # Allow Vagrant to access Vagrant managed machines outside the + # Windows Subsystem for Linux + # + # @return [Boolean] + def wsl_windows_access? + if !defined?(@_wsl_windows_access) + @_wsl_windows_access = wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + end + @_wsl_windows_access + end + + # The allowed windows system path Vagrant can manage from the Windows + # Subsystem for Linux + # + # @return [Pathname] + def wsl_windows_accessible_path + if !defined?(@_wsl_windows_accessible_path) + access_path = ENV.fetch("VAGRANT_WSL_ACCESS_WINDOWS_USER_HOME_PATH", + "/mnt/c/Users/#{ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"]}") + @_wsl_windows_accessible_path = Pathname.new(access_path) + end + @_wsl_windows_accessible_path + end + + # Checks given path to determine if Vagrant is allowed to bypass checks + # + # @param [String] path Path to check + # @return [Boolean] Vagrant is allowed to bypass checks + def wsl_windows_access_bypass?(path) + wsl? && wsl_windows_access? && + path.to_s.start_with?(wsl_windows_accessible_path.to_s) + end + + # If running within the Windows Subsystem for Linux, this will provide + # simple setup to allow sharing of the user's VAGRANT_HOME directory + # within the subsystem + # + # @param [Logger] logger Optional logger to display information + def wsl_init(logger=nil) + if wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + if logger + logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}") + logger.warn("Vagrant will be allowed to control Vagrant managed machines within the user's home path.") + end + if ENV["VAGRANT_HOME"] || ENV["VAGRANT_WSL_DISABLE_VAGRANT_HOME"] + logger.warn("VAGRANT_HOME environment variable already set. Not overriding!") if logger + else + home_path = wsl_windows_accessible_path + ENV["VAGRANT_HOME"] = File.join(home_path, ".vagrant.d") + if logger + logger.info("Overriding VAGRANT_HOME environment variable to configured windows user. (#{ENV["VAGRANT_HOME"]})") + end + end + end + end + # @private # Reset the cached values for platform. This is not considered a public # API and should only be used for testing. diff --git a/lib/vagrant/util/ssh.rb b/lib/vagrant/util/ssh.rb index faa965c26..77cc1e911 100644 --- a/lib/vagrant/util/ssh.rb +++ b/lib/vagrant/util/ssh.rb @@ -28,7 +28,7 @@ module Vagrant def self.check_key_permissions(key_path) # Don't do anything if we're on Windows, since Windows doesn't worry # about key permissions. - return if Platform.windows? + return if Platform.windows? || Platform.wsl_windows_access_bypass?(key_path) LOGGER.debug("Checking key permissions: #{key_path}") stat = key_path.stat diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index c304d3efb..12c01eebe 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -66,6 +66,12 @@ module VagrantPlugins break end end + elsif Vagrant::Util::Platform.wsl? + @logger.debug("Linux platform detected but executing within WSL. Locating VBoxManage.") + @vboxmanage_path = Vagrant::Util::Which.which("VBoxManage") || Vagrant::Util::Which.which("VBoxManage.exe") + if !@vboxmanage_path + raise Vagrant::Errors::VBoxManageNotFoundWSLError + end end # Fall back to hoping for the PATH to work out diff --git a/plugins/providers/virtualbox/provider.rb b/plugins/providers/virtualbox/provider.rb index 6bde344d2..12170936a 100644 --- a/plugins/providers/virtualbox/provider.rb +++ b/plugins/providers/virtualbox/provider.rb @@ -84,11 +84,15 @@ module VagrantPlugins def state # We have to check if the UID matches to avoid issues with # VirtualBox. - uid = @machine.uid - if uid && uid.to_s != Process.uid.to_s - raise Vagrant::Errors::VirtualBoxUserMismatch, - original_uid: uid.to_s, - uid: Process.uid.to_s + if Vagrant::Util::Platform.wsl_windows_access_bypass?(@machine.data_dir) + @logger.warn("Skipping UID check on machine by user request for WSL Windows access.") + else + uid = @machine.uid + if uid && uid.to_s != Process.uid.to_s + raise Vagrant::Errors::VirtualBoxUserMismatch, + original_uid: uid.to_s, + uid: Process.uid.to_s + end end # Determine the ID of the state here. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 2bb312910..00ba09371 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1381,6 +1381,16 @@ en: log out and log back in for the new environmental variables to take effect. If you're on Linux or Mac, verify your PATH contains the folder that has VBoxManage in it. + vboxmanage_not_found_wsl_error: |- + The "VBoxManage.exe" command or one of its dependencies could not + be found. Please verify VirtualBox is properly installed. You can verify + everything is okay by running "VBoxManage.exe --version" and verifying + that the VirtualBox version is outputted. + + If you just installed VirtualBox, you have to log out and log back in for + the new environmental variables to take effect. Using the VirtualBox + provider within the WSL requires VirtualBox executables to be available + on the system PATH. virtualbox_broken_version_040214: |- Vagrant detected you have VirtualBox 4.2.14 installed. VirtualBox 4.2.14 contains a critical bug which prevents it from working with From 4df4f77bf6a7489be3f79ff2fc9e52270acc2178 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 10:06:27 -0700 Subject: [PATCH 2/8] Match WSL installed Vagrant with Windows installed Vagrant --- lib/vagrant/errors.rb | 4 ++++ lib/vagrant/util/platform.rb | 19 +++++++++++++++++++ templates/locales/en.yml | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 6fb07803b..b822644ea 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -891,5 +891,9 @@ module Vagrant class VMPowerOffToPackage < VagrantError error_key(:power_off, "vagrant.actions.vm.export") end + + class WSLVagrantVersionMismatch < VagrantError + error_key(:wsl_vagrant_version_mismatch) + end end end diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 24b315987..4b744c3e7 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -293,6 +293,7 @@ module Vagrant # @param [Logger] logger Optional logger to display information def wsl_init(logger=nil) if wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + wsl_validate_matching_vagrant_versions! shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] if logger logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}") @@ -310,6 +311,24 @@ module Vagrant end end + # Confirm Vagrant versions installed within the WSL and the Windows system + # are the same. Raise error if they do not match. + def wsl_validate_matching_vagrant_versions! + valid = false + result = Util::Subprocess.execute("vagrant.exe", "version") + if result.exit_code == 0 + windows_version = result.stdout.match(/Installed Version: (?.+$)/) + if windows_version + valid = windows_version[:version] == Vagrant::VERSION + end + end + if !valid + raise Vagrant::Errors::WSLVagrantVersionMismatch, + wsl_version: Vagrant::VERSION, + windows_version: windows_version ? windows_version[:version] : "unknown" + end + end + # @private # Reset the cached values for platform. This is not considered a public # API and should only be used for testing. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 00ba09371..8c08135f9 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1520,6 +1520,16 @@ en: VM must be running to open SSH connection. Run `vagrant up` to start the virtual machine. test_key: "test value" + wsl_vagrant_version_mismatch: |- + Vagrant cannot currently enable access to manage machines within the Windows + environment because the version of Vagrant installed on Windows does not + match this version of Vagrant running within the Windows Subsystem for Linux. + Please ensure both installation of Vagrant are the same. If you do not want + update your Vagrant installations you can disable Windows access by unsetting + the `VAGRANT_WSL_ACCESS_WINDOWS_USER` environment variable. + + Windows Vagrant version: %{windows_version} + Windows Subsystem for Linux Vagrant version: %{wsl_version} #------------------------------------------------------------------------------- # Translations for config validation errors From 9a06374d2944ba9bb610a7b7fd4bb1dca1110dac Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 15:20:21 -0700 Subject: [PATCH 3/8] Perform WSL check and init after environment is created --- bin/vagrant | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 42c239f40..cd924873e 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -112,18 +112,18 @@ begin argv += argv_extra end - # If we are running with the Windows Subsystem for Linux do - # some extra setup to allow access to Vagrant managed machines - # outside the subsystem - if Vagrant::Util::Platform.wsl? - Vagrant::Util::Platform.wsl_init(logger) - end - # Create the environment, which is the cwd of wherever the # `vagrant` command was invoked from logger.debug("Creating Vagrant environment") env = Vagrant::Environment.new(opts) + # If we are running with the Windows Subsystem for Linux do + # some extra setup to allow access to Vagrant managed machines + # outside the subsystem + if Vagrant::Util::Platform.wsl? + Vagrant::Util::Platform.wsl_init(env, logger) + end + if !Vagrant.in_installer? && !Vagrant.very_quiet? # If we're not in the installer, warn. env.ui.warn(I18n.t("vagrant.general.not_in_installer") + "\n", prefix: false) From e8e38a400785b38b459b332196e99606f957587d Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 15:21:39 -0700 Subject: [PATCH 4/8] Halt Vagrant if within WSL and attempting to operate out of rootfs --- lib/vagrant/errors.rb | 4 ++++ lib/vagrant/util/platform.rb | 40 +++++++++++++++++++++--------------- templates/locales/en.yml | 8 ++++++++ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index b822644ea..d8d4ba44b 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -895,5 +895,9 @@ module Vagrant class WSLVagrantVersionMismatch < VagrantError error_key(:wsl_vagrant_version_mismatch) end + + class WSLVagrantAccessError < VagrantError + error_key(:wsl_vagrant_access_error) + end end end diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 4b744c3e7..3e8d41057 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -290,22 +290,29 @@ module Vagrant # simple setup to allow sharing of the user's VAGRANT_HOME directory # within the subsystem # + # @param [Environment] env # @param [Logger] logger Optional logger to display information - def wsl_init(logger=nil) - if wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] - wsl_validate_matching_vagrant_versions! - shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] - if logger - logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}") - logger.warn("Vagrant will be allowed to control Vagrant managed machines within the user's home path.") - end - if ENV["VAGRANT_HOME"] || ENV["VAGRANT_WSL_DISABLE_VAGRANT_HOME"] - logger.warn("VAGRANT_HOME environment variable already set. Not overriding!") if logger - else - home_path = wsl_windows_accessible_path - ENV["VAGRANT_HOME"] = File.join(home_path, ".vagrant.d") + def wsl_init(env, logger=nil) + if wsl? + if ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + wsl_validate_matching_vagrant_versions! + shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] if logger - logger.info("Overriding VAGRANT_HOME environment variable to configured windows user. (#{ENV["VAGRANT_HOME"]})") + logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}") + logger.warn("Vagrant will be allowed to control Vagrant managed machines within the user's home path.") + end + if ENV["VAGRANT_HOME"] || ENV["VAGRANT_WSL_DISABLE_VAGRANT_HOME"] + logger.warn("VAGRANT_HOME environment variable already set. Not overriding!") if logger + else + home_path = wsl_windows_accessible_path + ENV["VAGRANT_HOME"] = File.join(home_path, ".vagrant.d") + if logger + logger.info("Overriding VAGRANT_HOME environment variable to configured windows user. (#{ENV["VAGRANT_HOME"]})") + end + end + else + if env.local_data_path.to_s.start_with?("/mnt/") + raise Vagrant::Errors::WSLVagrantAccessError end end end @@ -319,13 +326,14 @@ module Vagrant if result.exit_code == 0 windows_version = result.stdout.match(/Installed Version: (?.+$)/) if windows_version - valid = windows_version[:version] == Vagrant::VERSION + windows_version = windows_version[:version].strip + valid = windows_version == Vagrant::VERSION end end if !valid raise Vagrant::Errors::WSLVagrantVersionMismatch, wsl_version: Vagrant::VERSION, - windows_version: windows_version ? windows_version[:version] : "unknown" + windows_version: windows_version || "unknown" end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 8c08135f9..be8e38c75 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1530,6 +1530,14 @@ en: Windows Vagrant version: %{windows_version} Windows Subsystem for Linux Vagrant version: %{wsl_version} + wsl_vagrant_access_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 #------------------------------------------------------------------------------- # Translations for config validation errors From 328d1aa8afde4c9c2e6b9f02512e185163b32eef Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 15:22:23 -0700 Subject: [PATCH 5/8] Disable verbose output accessing PATH --- lib/vagrant/util/which.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/which.rb b/lib/vagrant/util/which.rb index 9a7ba5b23..12a07f327 100644 --- a/lib/vagrant/util/which.rb +++ b/lib/vagrant/util/which.rb @@ -29,11 +29,17 @@ module Vagrant exts = ENV['PATHEXT'].split(';') end - ENV['PATH'].encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').split(File::PATH_SEPARATOR).each do |path| - exts.each do |ext| - exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}" - return exe if File.executable? exe + current_verbose = $VERBOSE + $VERBOSE = nil + begin + ENV['PATH'].encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').split(File::PATH_SEPARATOR).each do |path| + exts.each do |ext| + exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}" + return exe if File.executable? exe + end end + ensure + $VERBOSE = current_verbose end return nil From 7e49c6a6093b5d50463976654d62b2b5067826aa Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 15:23:06 -0700 Subject: [PATCH 6/8] Add documentation for WSL --- website/source/docs/other/wsl.html.md | 118 ++++++++++++++++++++++++++ website/source/layouts/docs.erb | 1 + 2 files changed, 119 insertions(+) create mode 100644 website/source/docs/other/wsl.html.md diff --git a/website/source/docs/other/wsl.html.md b/website/source/docs/other/wsl.html.md new file mode 100644 index 000000000..0e5e3d46d --- /dev/null +++ b/website/source/docs/other/wsl.html.md @@ -0,0 +1,118 @@ +--- +layout: "docs" +page_title: "Vagrant and Windows Subsystem for Linux" +sidebar_current: "other-wsl" +description: |- + An overview of using Vagrant on Windows within the Windows Subsystem + for Linux. +--- + +# Vagrant and Windows Subsystem for Linux + +Windows has recently introduced a new feature called the Windows Subsystem +for Linux (WSL). This is a beta feature available in developer mode on recent +releases of Windows 10. It is important to note that this feature is still +in _beta_ on Windows, and Vagrant support should be considered _alpha_. + +
+ Warning: Advanced Topic! Using Vagrant within the Windows + Subsystem for Linux is an advanced topic that only experienced Vagrant users + who are reasonably comfortable with Windows, WSL, and Linux should approach. +
+ + +# Installation + +Installation requires WSL, Ubuntu on Windows, and Vagrant. Read on for installation +instructions for each item. + +## Windows Subsystem for Linux and Ubuntu on Windows + +First install the Windows Subsystem for Linux, followed by Ubuntu on Windows. This guide +from Microsoft walks through the process: + +* https://msdn.microsoft.com/en-us/commandline/wsl/install_guide + +## Vagrant Installation + +Vagrant _must_ be installed within Ubuntu on Windows. Even though the `vagrant.exe` +file can be executed from within the WSL, it will not function as expected. To +install Vagrant into the WSL, follow these steps: + +* Download the 64-bit Debian package from the downloads page. +* Open a `cmd` or `powershell` window +* Enter the command: `bash` +* Install vagrant: `sudo dpkg -i vagrant_VERSION_x86_64.deb` + +``` +C:\Users\vagrant> bash +vagrant@vagrant-10:/mnt/c/Users/vagrant$ sudo dpkg -i vagrant_VERSION_x86_64.deb +[sudo] password for vagrant: +(Reading database ... 31885 files and directories currently installed.) +Preparing to unpack vagrant_VERSION_x86_64.deb ... +Unpacking vagrant (1:VERSION) ... +Setting up vagrant (1:VERSION) ... +vagrant@vagrant-10:/mnt/c/Users/vagrant$ vagrant help +Usage: vagrant [options] [] +``` + +# Vagrant Usage + +Vagrant will detect when it is being run within the WSL and adjust how it +locates and executes third party executables. For example, when using the +VirtualBox provider Vagrant will interact with VirtualBox installed on +the Windows system, not within the WSL. It is important to ensure that +any required Windows executable is available within your `PATH` to allow +Vagrant to access them. + +## Windows Access + +Working within the WSL provides a layer of isolation from the actual +Windows system. In some cases, a user may be using Vagrant in a regular +Windows environment, and then transition to using Vagrant within the +WSL. Using Vagrant within the WSL will appear to be isolated from +the Windows system. A new `VAGRANT_HOME` directory will be created within +the WSL (meaning all boxes will require re-downloading). Vagrant will also +lose the ability to control Vagrant managed machines within Windows (due +to user ID mismatches). + +Vagrant supports enabling user access to provide seamless behavior and +control between Vagrant on Windows and Vagrant on WSL. By setting the +`VAGRANT_WSL_ACCESS_WINDOWS_USER` environment variable, Vagrant will +allow access to Vagrant managed machines in that user's home path, as +well as share the `VAGRANT_HOME` directory. Below is a demonstration +of the behavior: + +``` +C:\Users\vagrant> bash +vagrant@vagrant-10:/mnt/c/Users/vagrant$ mkdir test +vagrant@vagrant-10:/mnt/c/Users/vagrant$ cd test +vagrant@vagrant-10:/mnt/c/Users/vagrant/test$ vagrant init hashicorp/precisec4 +vagrant@vagrant-10:/mnt/c/Users/vagrant$ vagrant up +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 +vagrant@vagrant-10:/mnt/c/Users/vagrant$ export VAGRANT_WSL_ACCESS_WINDOWS_USER=vagrant +vagrant@vagrant-10:/mnt/c/Users/vagrant$ vagrant up +Bringing machine 'default' up with 'virtualbox' provider... +``` + +It is important to note that file permissions cannot be enforced when Vagrant +modifies the Windows file system. It is for this reason that you must explicitly +enable this functionality with the express knowledge of the implication. If you +are unsure of how this may affect your system, do not enable this feature. + +## Using Docker + +The docker daemon cannot be run in side the Windows Subsystem for Linux. However, +the daemon _can_ be run on Windows and accessed by Vagrant while running in the +WSL. Once docker is installed and running on windows, export the following +environment variable to give Vagrant access: + +``` +$ vagrant@vagrant-10:/mnt/c/Users/vagrant$ export DOCKER_HOST=tcp://127.0.0.1:2375 +``` diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index 5239cc8d6..59e16b863 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -211,6 +211,7 @@ From 10cb43b917079f0cfaa2db2e210b08e1957f0cea Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 17:03:38 -0700 Subject: [PATCH 7/8] Use helper module to silence warnings --- lib/vagrant/util/platform.rb | 6 +----- lib/vagrant/util/which.rb | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 3e8d41057..8996b3f80 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -31,9 +31,7 @@ module Vagrant def wsl? if !defined?(@_wsl) @_wsl = false - original_verbose = $VERBOSE - begin - $VERBOSE = nil + SilenceWarnings.silence! do # Use PATH values to check for `/mnt/c` path indicative of WSL if ENV.fetch("PATH", "").downcase.include?("/mnt/c") # Validate WSL via uname output @@ -42,8 +40,6 @@ module Vagrant @_wsl = true end end - ensure - $VERBOSE = original_verbose end end @_wsl diff --git a/lib/vagrant/util/which.rb b/lib/vagrant/util/which.rb index 12a07f327..0c8fd34d7 100644 --- a/lib/vagrant/util/which.rb +++ b/lib/vagrant/util/which.rb @@ -29,17 +29,13 @@ module Vagrant exts = ENV['PATHEXT'].split(';') end - current_verbose = $VERBOSE - $VERBOSE = nil - begin + SilenceWarnings.silence! do ENV['PATH'].encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}" return exe if File.executable? exe end end - ensure - $VERBOSE = current_verbose end return nil From 370e27b91957c3f1ff253fef6f17d7029e1a1fe9 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 10 May 2017 10:32:04 -0700 Subject: [PATCH 8/8] Update documentation for WSL --- website/source/docs/other/wsl.html.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/source/docs/other/wsl.html.md b/website/source/docs/other/wsl.html.md index 0e5e3d46d..6e3d88ee9 100644 --- a/website/source/docs/other/wsl.html.md +++ b/website/source/docs/other/wsl.html.md @@ -79,9 +79,9 @@ to user ID mismatches). Vagrant supports enabling user access to provide seamless behavior and control between Vagrant on Windows and Vagrant on WSL. By setting the `VAGRANT_WSL_ACCESS_WINDOWS_USER` environment variable, Vagrant will -allow access to Vagrant managed machines in that user's home path, as -well as share the `VAGRANT_HOME` directory. Below is a demonstration -of the behavior: +allow access to Vagrant managed machines in that user's home path in +Windows (`C:\Users\vagrant` for example), as well as share the `VAGRANT_HOME` +directory. Below is a demonstration of the behavior: ``` C:\Users\vagrant> bash @@ -108,9 +108,9 @@ are unsure of how this may affect your system, do not enable this feature. ## Using Docker -The docker daemon cannot be run in side the Windows Subsystem for Linux. However, +The docker daemon cannot be run inside the Windows Subsystem for Linux. However, the daemon _can_ be run on Windows and accessed by Vagrant while running in the -WSL. Once docker is installed and running on windows, export the following +WSL. Once docker is installed and running on Windows, export the following environment variable to give Vagrant access: ```