現(xiàn)象:
環(huán)境:
- Windows 10
- VirtualBox 5.1.30
- Vagrant 1.9.8
- centos/7 box
使用 vagrant 啟動 Virtualbox centos/7 box巡社,能夠?qū)⑺拗鳈C當(dāng)前目錄下的文件同步(復(fù)制)到虛擬機 /vagrant 目錄,但在虛擬機中對 /vagrant 所做的修改并不會在宿主機目錄生效梨睁,無法實現(xiàn)雙向共享
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/d/VM/centos/ => /vagrant
分析:
從上面啟動過程 No guest additions were detected on the base box for this VM!
可以看出 centos/7 缺少 Virtualbox Guest Additions
解決:
vagrant 安裝 vagrant-vbguest 插件互拾,在 Vagrantfile 中配置 synced_folder
- 安裝 vagrant-vbguest
vagrant plugin install vagrant-vbguest
- Vagrantfile 配置共享目錄沟娱,掛載位置不能使用 /vagrant
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/share"
end
- 啟動過程會自動安裝 Virtualbox Guest Additions,啟動后配置的共享目錄可以雙向讀寫
==> default: Machine booted and ready!
==> default: Configuring proxy environment variables...
==> default: Configuring proxy for Yum...
[default] No installation found.
Loaded plugins: fastestmirror
...
Installing Virtualbox Guest Additions 5.1.30 - guest version is unknown
...
==> default: Checking for guest additions in VM...
==> default: Rsyncing folder: /cygdrive/d/VM/centos/ => /vagrant
==> default: Mounting shared folders...
default: /share => D:/VM/centos