来宾计算机中缺少 Vagrant 同步文件夹
Vagrant synced folder is missing in the guest machine
我正在尝试为我的 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
但是,当我通过 ssh 进入 vm 时,/vagrant
目录不包含主机上同步目录的内容。我已经尝试了 中列出的所有内容,但没有成功。我还尝试将 config.vm.synced_folder
命令移动到 virtualbox 修改下方,但也没有任何运气。
此外,如果我 运行 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 "" && cd ""; }" >> ~vagrant/.bashrc
echo "mgrep () { grep -rnIi \"\" . --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!"
我上面的代码没有错误。
提前致谢!
您的 bootstrap.sh
脚本在这一行有问题
echo "cd() { builtin cd "$@"; ls -FGlAhp; }" >> ~vagrant/.bashrc
特殊字符需要转义,您可以在配置后验证您的 .bashrc
文件,但它与您的 shell 脚本中的不同;所以你应该替换为
echo "cd() { builtin cd \"$@\"; ls -FGlAhp; }" >> ~vagrant/.bashrc
转义时要小心,您为 mgrep
函数做了正确的转义,但对于 mcd
却不正确,因此您需要修复此问题。如果您想通过脚本进行修改,通常会验证您的 .bashrc
文件是否已相应完成更新。
我正在尝试为我的 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
但是,当我通过 ssh 进入 vm 时,/vagrant
目录不包含主机上同步目录的内容。我已经尝试了 config.vm.synced_folder
命令移动到 virtualbox 修改下方,但也没有任何运气。
此外,如果我 运行 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 "" && cd ""; }" >> ~vagrant/.bashrc
echo "mgrep () { grep -rnIi \"\" . --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!"
我上面的代码没有错误。
提前致谢!
您的 bootstrap.sh
脚本在这一行有问题
echo "cd() { builtin cd "$@"; ls -FGlAhp; }" >> ~vagrant/.bashrc
特殊字符需要转义,您可以在配置后验证您的 .bashrc
文件,但它与您的 shell 脚本中的不同;所以你应该替换为
echo "cd() { builtin cd \"$@\"; ls -FGlAhp; }" >> ~vagrant/.bashrc
转义时要小心,您为 mgrep
函数做了正确的转义,但对于 mcd
却不正确,因此您需要修复此问题。如果您想通过脚本进行修改,通常会验证您的 .bashrc
文件是否已相应完成更新。