Invalid configured shell error when 运行 the official FreeBSD vagrant box

Invalid configured shell error when running the official FreeBSD vagrant box

我尝试 运行 官方 FreeBSD vagrant box 使用:

vagrant init freebsd/FreeBSD-10.2-STABLE

然后,根据 https://forums.freebsd.org/threads/52717/ 中的说明相应修改我的 Vagrantfile,添加以下行:

Vagrant.configure("2") do |config|
  config.vm.guest = :freebsd
  config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
  config.vm.box = "freebsd/FreeBSD-10.2-STABLE"
  config.ssh.shell = "sh"
  config.vm.base_mac = "080027D14C66"

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    vb.customize ["modifyvm", :id, "--cpus", "1"]
    vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  end
end

当我发出 vagrant up 命令时:

vagrant up --provider virtualbox

显示以下错误:

The configured shell (config.ssh.shell) is invalid and unable to properly execute commands. The most common cause for this is using a shell that is unavailable on the system. Please verify you're using the full path to the shell and that the shell is executable by the SSH user.

尽管有错误,我仍然能够vagrant ssh 进入盒子。但是,我无法使用 vagrant halt 正常关闭机器。它会显示与上面相同的错误并且根本不会关闭。

修复很简单,因为这完全是我的菜鸟错误。在 Vagrantfile 中,除了最顶部的两行之外,您应该删除 运行 vagrant init 命令时生成的所有部分。然后将建议的粘贴到这两行下方。完整的 Vagrantfile 应该如下所示:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
    config.vm.guest = :freebsd
    config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
    config.vm.box = "freebsd/FreeBSD-10.2-STABLE"
    config.ssh.shell = "sh"
    config.vm.base_mac = "080027D14C66"

    config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "1024"]
      vb.customize ["modifyvm", :id, "--cpus", "1"]
      vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
      vb.customize ["modifyvm", :id, "--audio", "none"]
      vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
      vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
    end

    config.vm.network "private_network", ip: "192.168.33.10"
end

我做错的是将这个 Vagrant.configure("2") do |config| 块嵌套在自动生成的块中。