【问题标题】:Cannot create a VM with accessible network interface无法创建具有可访问网络接口的 VM
【发布时间】:2018-06-21 15:20:35
【问题描述】:

我开始为开发创建一个新的虚拟机,因为我的 ubuntu 14.4 似乎已经过时了。

我决定将来切换到 ubuntu 17.10,但第一次安装失败。

这是我的流浪文件:

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

Vagrant.configure("2") do |config|

    config.vm.provider "virtualbox" do |vb|
        vb.gui = false
        vb.memory = "1024"
    end

    config.vm.box = "generic/ubuntu1710"
    config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: false
    config.vm.network "private_network", ip: "192.168.37.200"

end

在配置过程中我得到了这个

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/ifdown 'eth1' || true
/sbin/ip addr flush dev 'eth1'
# Remove any previous network modifications from the interfaces file
sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre
sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tac | sed -e '/^#VAGRANT-END/,$ d' | tac > /tmp/vagrant-network-interfaces.post

cat \
  /tmp/vagrant-network-interfaces.pre \
  /tmp/vagrant-network-entry \
  /tmp/vagrant-network-interfaces.post \
  > /etc/network/interfaces

rm -f /tmp/vagrant-network-interfaces.pre
rm -f /tmp/vagrant-network-entry
rm -f /tmp/vagrant-network-interfaces.post

/sbin/ifup 'eth1'

Stdout from the command:



Stderr from the command:

bash: line 4: /sbin/ifdown: No such file or directory
bash: line 20: /sbin/ifup: No such file or directory

机器无法通过托管窗口使用。我必须在配置之前安装一些东西吗?或者你更喜欢 hashicorb 的其他机器模板?

问候 n00n

【问题讨论】:

    标签: windows ubuntu vagrant virtualbox ubuntu-17.10


    【解决方案1】:

    由于删除了传统的网络配置工具和文件:/sbin/ifup/sbin/ifdown,目前 Vagrant 无法与 Ubuntu 17.10 一起使用。

    但是您可以使用以下解决方法创建具有网络接口的 vagrant VM:

    1. 将安装ifupdown 添加到您的 Vagrantfile 中:

    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    $provision_script = <<PROVISION
        apt-get -y update
        apt-get install ifupdown -y
    PROVISION
    
    Vagrant.configure("2") do |config|
        config.vm.provision "shell", inline: $provision_script
        config.vm.provider "virtualbox" do |vb|
            vb.gui = false
            vb.memory = "1024"
        end
    
        config.vm.box = "generic/ubuntu1710"
        config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: false
        config.vm.network "private_network", ip: "192.168.37.200"
    end
    

    2. 创建流浪虚拟机:

    vagrant up
    

    当然它会因相关错误而失败。

    3. 在刚刚创建的 VM 中启动配置脚本。它安装包ifupdown 和必要的文件:

    vagrant provision
    

    4. 现在重新加载你的虚拟机:

    vagrant reload
    

    【讨论】:

    • 在我的 ubuntu 18.04 中使用 VirtualBox 5.1.38r122592 和 Vagrant 2.0.2 可以正常工作。谢谢!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 2016-01-31
    • 2014-09-27
    • 1970-01-01
    • 2021-09-17
    • 2020-01-24
    相关资源
    最近更新 更多