本文介绍了如何在 ubuntu/xenial64 上获取/vagrant 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚用命令安装了 vagrant box:

I have just installed vagrant box with command:

vagrant init ubuntu/xenial64

并启动它:

vagrant up --provider virtualbox

ssh-ing 后我找不到文件夹/vagrant

after ssh-ing I can not find folder /vagrant

我做错了什么?

根据文档应该有/vagrant文件夹:

默认情况下,Vagrant 会共享你的项目目录(目录与 Vagrantfile) 到/vagrant.

这是一个截图,很明显没有/vagrant 文件夹

Here is a screenshot where is obvious that there is no /vagrant folder

我的宿主环境是:

  • Windows 7
  • Vagrant 1.8.1 版
  • Vbox 版本 5.0.20r106931

这是我的 Vagrant 文件:

Here is my Vagrant file:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/xenial64"

  config.vm.provision "shell", path: "provision.sh"

  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = "4096"
    vb.cpus = "2"

    # Hack for nom global install
    # https://github.com/npm/npm/issues/7308
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]

  end
end

这是我的配置文件:

echo "------------------------------"
echo "--- Updating packages list ---"
echo "------------------------------"
apt-get -y update

echo "-----------------------"
echo "--- Installing curl ---"
echo "-----------------------"
apt-get -y install curl

echo "----------------------"
echo "--- Installing git ---"
echo "----------------------"
apt-get -y install git

echo "-----------------------------"
echo "--- Installing python-pip ---"
echo "-----------------------------"
apt-get -y install python-pip
yes | pip install --upgrade pip

echo "--------------------------"
echo "--- Installing node.js ---"
echo "--------------------------"
apt-get -y install  nodejs

echo "----------------------"
echo "--- Installing npm ---"
echo "----------------------"
apt-get -y install npm

推荐答案

更新:

这个问题终于在官方16.04 vagrant box的v20160921.0.0及更高版本中得到解决.正如 在评论中.

This problem was finally fixed in version v20160921.0.0 and higher of the official 16.04 vagrant box. The release before that v20160909.0.0 is also fixed but has another unrelated issue, as pointed out by Poma in the comments.

您可以使用以下命令下载新版本,并用新的虚拟机实例替换旧的虚拟机实例.但是,升级该框会擦除您的原始 VM 实例.

You can use the following command to download the new version and also replace your old VM instance with a fresh one. However, upgrading the box wipes your original VM instance.

vagrant box update

如果您出于某种原因不想擦除您的 VM,您仍然可以在下面应用我的原始修复.

If you don't want to wipe your VM for some reason, you can still apply my original fixes below.

原帖:

显然官方 ubuntu/xenial64 映像已损坏,如此错误报告中所示在启动板上.

Apparently the official ubuntu/xenial64 image is broken, as indicated in this bug report on launchpad.

以下是 Louis Zuckerman 评论中的引述,其中包含我所知道的在 20160627.0.0 版本中仍未解决的所有问题:

Here's a quote from the comments by Louis Zuckerman with all the issues which are still unfixed as of version 20160627.0.0 from what I could tell:

xenial 的官方 vagrant box 存在许多问题:

  1. 缺少必要的包(同步文件夹不起作用,没有配置管理)
  2. 默认/vagrant 同步文件夹被禁用
  3. vm 名称是静态的,因此您只能在主机上拥有一个 box 实例

[...]

这些步骤为我解决了问题 1 和 2:

These steps fixed issues 1 and 2 for me:

  1. ssh 进入框并手动安装缺少的来宾添加

  1. ssh into the box and install the missing guest additions manually

vagrant ssh
sudo apt-get install virtualbox-guest-utils
exit 

  • 手动将缺少的挂载点添加到您的 Vagrantfile

    config.vm.synced_folder ".", "/vagrant/" # fix broken ubuntu/xenial64 image
    

  • 要解决第三个问题,您必须通过将 VirtualBox 的特定于提供程序的选项添加到您的 Vagrantfile 中,手动为该框指定一个唯一名称.

    To fix the third issue you have to give a unique name to the box manually by adding a provider-specific option for VirtualBox to your Vagrantfile.

    config.vm.provider "virtualbox" do |vb|
      vb.name = "This_Name_Is_Unique_For_This_Machine"
    end
    

    正如对此答案的评论中所指出的,此处对此问题进行了更详细的讨论.

    There is a more detailed discussion of this issue here as pointed out in the comments to this answer.

    这篇关于如何在 ubuntu/xenial64 上获取/vagrant 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-29 06:00