Vagrant 2.2.5 和VirtualBox6.1不兼容问题解决办法
1 在安装完毕vagrant和virtualbox后,执行命令 vagrant up时出现
No usable default provider could be found for your system.Vagrant relies on interactions with 3rd party systems, known as"providers", to provide Vagrant with resources to run developmentenvironments. Examples are VirtualBox, VMware, Hyper-V.The easiest solution to this message is to install VirtualBox, whichis available for free on all major platforms.If you believe you already have a provider available, make sure itis properly installed and configured. You can see more details aboutwhy a particular provider isn‘t working by forcing usage with`vagrant up --provider=PROVIDER`, which should give you a more specificerror message for that particular provider.
出现此错误提示未安装virtualbox,但实际已安装完毕。查资料发现存在版本兼容问题。
需要修改三处内容
1 在C:\software\Vagrant\embedded\gems\2.2.5\gems\vagrant-2.2.5\plugins\providers\virtualbox\plugin.rb的文件内新增红色部分 (添加 下面62 行内容autoload :Version61, File.expand_path(“../driver/version_6_1”, __FILE))
require "vagrant"module VagrantPluginsmodule ProviderVirtualBoxclass Plugin < Vagrant.plugin("2")name "VirtualBox provider"description <<-EOFThe VirtualBox provider allows Vagrant to manage and controlVirtualBox-based virtual machines.EOFprovider(:virtualbox, priority: 6) dorequire File.expand_path("../provider", __FILE__)Providerendconfig(:virtualbox, :provider) dorequire File.expand_path("../config", __FILE__)Configendsynced_folder(:virtualbox) dorequire File.expand_path("../synced_folder", __FILE__)SyncedFolderendprovider_capability(:virtualbox, :forwarded_ports) dorequire_relative "cap"Capendprovider_capability(:virtualbox, :nic_mac_addresses) dorequire_relative "cap"Capendprovider_capability(:virtualbox, :public_address) dorequire_relative "cap/public_address"Cap::PublicAddressendprovider_capability(:virtualbox, :snapshot_list) dorequire_relative "cap"Capendendautoload :Action, File.expand_path("../action", __FILE__)# Drop some autoloads in here to optimize the performance of loading# our drivers only when they are needed.module Driverautoload :Meta, File.expand_path("../driver/meta", __FILE__)autoload :Version_4_0, File.expand_path("../driver/version_4_0", __FILE__)autoload :Version_4_1, File.expand_path("../driver/version_4_1", __FILE__)autoload :Version_4_2, File.expand_path("../driver/version_4_2", __FILE__)autoload :Version_4_3, File.expand_path("../driver/version_4_3", __FILE__)autoload :Version_5_0, File.expand_path("../driver/version_5_0", __FILE__)autoload :Version_5_1, File.expand_path("../driver/version_5_1", __FILE__)autoload :Version_5_2, File.expand_path("../driver/version_5_2", __FILE__)autoload :Version_6_0, File.expand_path("../driver/version_6_0", __FILE__)autoload :Version_6_1, File.expand_path("../driver/version_6_1", __FILE__)endmodule Modelautoload :ForwardedPort, File.expand_path("../model/forwarded_port", __FILE__)endmodule Utilautoload :CompileForwardedPorts, File.expand_path("../util/compile_forwarded_ports", __FILE__)endendend
2 在C:\software\Vagrant\embedded\gems\2.2.5\gems\vagrant-2.2.5\plugins\providers\virtualbox\driver 下添加如下内容( 67行添加 内容”6.1” => Version_6_1,)
require "forwardable"require "thread"require "log4r"require "vagrant/util/retryable"require File.expand_path("../base", __FILE__)module VagrantPluginsmodule ProviderVirtualBoxmodule Driverclass Meta < Base# This is raised if the VM is not found when initializing a driver# with a UUID.class VMNotFound < StandardError; end# We use forwardable to do all our driver forwardingextend Forwardable# We cache the read VirtualBox version here once we have one,# since during the execution of Vagrant, it likely doesn't change.@@version = nil@@version_lock = Mutex.new# The UUID of the virtual machine we representattr_reader :uuid# The version of virtualbox that is running.attr_reader :versioninclude Vagrant::Util::Retryabledef initialize(uuid=nil)# Setup the basesuper()@logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta")@uuid = uuid@@version_lock.synchronize doif !@@version# Read and assign the version of VirtualBox we know which# specific driver to instantiate.begin@@version = read_versionrescue Vagrant::Errors::CommandUnavailable,Vagrant::Errors::CommandUnavailableWindows# This means that VirtualBox was not found, so we raise this# error here.raise Vagrant::Errors::VirtualBoxNotDetectedendendend# Instantiate the proper version driver for VirtualBox@logger.debug("Finding driver for VirtualBox version: #{@@version}")driver_map = {"4.0" => Version_4_0,"4.1" => Version_4_1,"4.2" => Version_4_2,"4.3" => Version_4_3,"5.0" => Version_5_0,"5.1" => Version_5_1,"5.2" => Version_5_2,"6.0" => Version_6_0,"6.1" => Version_6_1,}if @@version.start_with?("4.2.14")# VirtualBox 4.2.14 just doesn't work with Vagrant, so show errorraise Vagrant::Errors::VirtualBoxBrokenVersion040214enddriver_klass = nildriver_map.each do |key, klass|if @@version.start_with?(key)driver_klass = klassbreakendendif !driver_klasssupported_versions = driver_map.keys.sort.join(", ")raise Vagrant::Errors::VirtualBoxInvalidVersion,supported_versions: supported_versionsend@logger.info("Using VirtualBox driver: #{driver_klass}")@driver = driver_klass.new(@uuid)@version = @@versionif @uuid# Verify the VM exists, and if it doesn't, then don't worry# about it (mark the UUID as nil)raise VMNotFound if !@driver.vm_exists?(@uuid)endenddef_delegators :@driver, :clear_forwarded_ports,:clear_shared_folders,:clonevm,:create_dhcp_server,:create_host_only_network,:create_snapshot,:delete,:delete_snapshot,:delete_unused_host_only_networks,:discard_saved_state,:enable_adapters,:execute_command,:export,:forward_ports,:halt,:import,:list_snapshots,:read_forwarded_ports,:read_bridged_interfaces,:read_dhcp_servers,:read_guest_additions_version,:read_guest_ip,:read_guest_property,:read_host_only_interfaces,:read_mac_address,:read_mac_addresses,:read_machine_folder,:read_network_interfaces,:read_state,:read_used_ports,:read_vms,:reconfig_host_only,:remove_dhcp_server,:restore_snapshot,:resume,:set_mac_address,:set_name,:share_folders,:ssh_port,:start,:suspend,:verify!,:verify_image,:vm_exists?protected# This returns the version of VirtualBox that is running.## @return [String]def read_version# The version string is usually in one of the following formats:## * 4.1.8r1234# * 4.1.8r1234_OSE# * 4.1.8_MacPortsr1234## Below accounts for all of these.# Note: We split this into multiple lines because apparently "".split("_")# is [], so we have to check for an empty array in between.output = ""retryable(on: Vagrant::Errors::VirtualBoxVersionEmpty, tries: 3, sleep: 1) dooutput = execute("--version")if output =~ /vboxdrv kernel module is not loaded/ ||output =~ /VirtualBox kernel modules are not loaded/iraise Vagrant::Errors::VirtualBoxKernelModuleNotLoadedelsif output =~ /Please install/# Check for installation incomplete warnings, for example:# "WARNING: The character device /dev/vboxdrv does not# exist. Please install the virtualbox-ose-dkms package and# the appropriate headers, most likely linux-headers-generic."raise Vagrant::Errors::VirtualBoxInstallIncompleteelsif output.chomp == ""# This seems to happen on Windows for uncertain reasons.# Raise an error otherwise the error is that they have an# incompatible version of VirtualBox which isn't true.raise Vagrant::Errors::VirtualBoxVersionEmpty,vboxmanage: @vboxmanage_path.to_sendendparts = output.split("_")return nil if parts.empty?parts[0].split("r")[0]endendendendend
3 在C:\software\Vagrant\embedded\gems\2.2.5\gems\vagrant-2.2.5\plugins\providers\virtualbox\driver 下新建version_6_1.rb 内容如下
require File.expand_path("../version_6_0", __FILE__)module VagrantPluginsmodule ProviderVirtualBoxmodule Driver# Driver for VirtualBox 6.1.xclass Version_6_1 < Version_6_0def initialize(uuid)super@logger = Log4r::Logger.new("vagrant::provider::virtualbox_6_1")endendendendend
