我试图将带有同步文件夹的虚拟机配置到我的Vagrantfile
所在的目录(应该是默认行为,但它不起作用)。这是我当前状态的Vagrantfile(参见下面的bootstrap.sh
):
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = true
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.hostname = "vagrant"
config.vm.network "private_network", ip: 'XXX.XXX.XX.XXX'
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--cpus", 2]
vb.customize ["modifyvm", :id, "--cpuexecutioncap", 50]
end
config.vm.provision :shell, path: "bootstrap.sh"
end
这是vagrant up
输出的挂载部分,其中--debug
标志被切换:
INFO synced_folders: Invoking synced folder enable: virtualbox
INFO interface: output: Mounting shared folders...
INFO interface: output: ==> default: Mounting shared folders...
==> default: Mounting shared folders...
INFO interface: detail: /vagrant => /path/to/my/project
INFO interface: detail: default: /vagrant => /Users/michaelmartorella/code/ethereum
default: /vagrant => /path/to/my/project
但是,当我进入vm时,/vagrant
目录不包含主机上同步目录的内容。我已经尝试了this solution中列出的所有内容,并且没有运气。我还尝试将config.vm.synced_folder
命令移到虚拟框修改下方,并且没有任何运气。
此外,如果我运行cd /
我没有移动到根目录 - 它会让我进入主目录(看起来非常奇怪,我认为它与导致此问题的任何内容有关问题)。
我正在使用:
Vagrant 1.9.5
VirtualBox Version 5.1.22
Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-119-generic x86_64)
我是从MacOS Sierra Version 10.12.5
如果有帮助,这里也是我的bootstrap.sh
代码:
#!/bin/bash
# Install git for version control, pip for install python packages
echo "Installing base python requirements..."
sudo apt-get -qq -y install git python-dev build-essential automake pkg-config libtool libffi-dev libgmp-dev python-pip libssl-dev > /dev/null 2>&1
# Customize the shell
echo "cd() { builtin cd "$@"; ls -FGlAhp; }" >> ~vagrant/.bashrc
echo "alias cd..='cd ../'" >> ~vagrant/.bashrc
echo "mcd () { mkdir -p "$1" && cd "$1"; }" >> ~vagrant/.bashrc
echo "mgrep () { grep -rnIi \"$1\" . --color; }" >> ~vagrant/.bashrc
echo "alias geth-init='bash /vagrant/init_geth.sh'" >> ~vagrant/.bashrc
echo "alias geth-console='bash /vagrant/geth_console.sh'" >> ~vagrant/.bashrc
# Install ethereum
echo "Installing ethereum..."
sudo apt-get install software-properties-common > /dev/null 2>&1
sudo add-apt-repository -y ppa:ethereum/ethereum > /dev/null 2>&1
sudo apt-get update > /dev/null 2>&1
sudo apt-get -y install ethereum > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Successfully installed ethereum!"
else
echo "Could not install ethereum" >&2
exit 1
fi
# Install pyethapp
echo "Installing pyethapp..."
pip install pyethapp > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Successfully installed pyethapp"
else
echo "Could not install pyethapp" >&2
exit 1
fi
# Complete
echo ""
echo "Vagrant install complete!"
上面的代码没有错误。
提前致谢!
答案 0 :(得分:0)
您的bootstrap.sh
脚本中存在此问题
echo "cd() { builtin cd "$@"; ls -FGlAhp; }" >> ~vagrant/.bashrc
需要转义特殊字符,您可以在配置后验证.bashrc
文件,但它不像您在shell脚本中那样;所以你应该用
echo "cd() { builtin cd \"\$@\"; ls -FGlAhp; }" >> ~vagrant/.bashrc
小心转义,你为mgrep
函数正确设置但mcd
不正确,所以你需要解决这个问题。通常验证您的.bashrc
文件,如果您想通过脚本进行修改,则相应地完成更新。