【问题标题】:Vagrantfile ordering provisioner issueVagrantfile 订购供应商问题
【发布时间】:2017-02-26 18:10:03
【问题描述】:

我有以下流浪文件:

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

Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    vb.cpus = 4
    #storage
  end

  config.vm.provision "shell",
    path: "vagrant_files/setup_script.sh"

  config.vm.provision :reload

  config.vm.provision "shell",
    path: "vagrant_files/setup_script_2.sh"

  config.vm.provision :reload

  config.vm.provision "shell",
     path: "vagrant_files/setup_script_3.sh"

  config.vm.synced_folder ".", "/vagrant"

end

在我的设置 setup_script 中,我有 vagrant install Virtual Box Guest Additions,这是让同步文件夹功能为 vagrant 工作的要求。

不幸的是,即使我将同步文件夹的行放在 Vagrantfile 的最后,它仍然会首先尝试执行该任务,从而导致错误:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

mount: unknown filesystem type 'vboxsf'

我知道我需要先安装 Virtual Box Guest Additions。还有其他人遇到这个问题吗?大家是怎么解决这个问题的?

【问题讨论】:

    标签: vagrant vagrantfile vagrant-provision


    【解决方案1】:

    这是一个有趣的问题。我用相同的基本盒子启动了一个 CentOS 7 VM...

    vagrant init centos/7
    vagrant up
    

    ...Guest Additions 安装失败。这是 Vagrant 的相关输出...

    Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
    mount: /dev/loop0 is write-protected, mounting read-only
    Installing Virtualbox Guest Additions 5.0.10 - guest version is
    Verifying archive integrity... All good.
    Uncompressing VirtualBox 5.0.10 Guest Additions for Linux............
    VirtualBox Guest Additions installer
    Copying additional installer modules ...
    ./install.sh: line 345: bzip2: command not found
    tar: This does not look like a tar archive
    tar: Exiting with failure status due to previous errors
    ./install.sh: line 358: bzip2: command not found
    tar: This does not look like a tar archive
    tar: Exiting with failure status due to previous errors
    

    所以这个基础盒子没有安装bzip2 包,这会导致失败。出于好奇,我从ubuntu/trusty64 基本框创建了一个新的Ubuntu VM,并且安装了Guest Additions,没有任何问题。正如您可能猜到的那样,bzip2 软件包已经安装在 Ubuntu 中。

    我会将此归类为基本盒子本身的问题。 CentOS 项目应该将bzip2 烘焙到他们所有与 VirtualBox 一起使用的 Vagrant 基础盒子中。

    当然,现在这对你没有帮助,但幸运的是你有many more options for CentOS base boxes,我希望他们中的大多数人都不会受到这个问题的影响。

    【讨论】:

    • 一种可能性(不太聪明)是使用vagrant trigger plugin 并执行config.vbguest.auto_update = false config.vm.provision "shell", inline <install package> config.trigger.after :up do run "vagrant vbguest --auto-reboot --no-provision" end 之类的操作
    • 我认为这是一个应该可行的好主意。我实际上没有听说过'vagrant-triggers'插件。感谢您提及!
    【解决方案2】:

    为了解决我的问题,我刚刚加载了 Centos 盒子。 然后我开始安装 Virtual Box Guest Additions 然后我开始重新包装盒子

    这解决了我的问题。

    【讨论】:

      【解决方案3】:

      我在 https://github.com/mitchellh/vagrant/issues/6769 上使用了 luvejo 提示,它也对我有用:

      您还可以安装 vagrant-vbguest 插件,以便添加 为您添加 VirtualBox 访客。

       vagrant plugin install vagrant-vbguest 
      
       vagrant destroy && vagrant up
      

      这对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 2014-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多