环境: 主机windows10下virtualbox和Vagrant软件,客户机centos7

BUG1:vagrant up 时每次都要手动输入网卡序号才能继续

#  ==> default: Available bridged network interfaces:
# 1) Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
# 2) Hyper-V Virtual Ethernet Adapter
which interface should the network bridge to ?

解决方法:
方法一: 禁用其中之一的网卡,或者
方法二: 在配置文件里加入bridge: “对应网卡名”例如以下

config.vm.network "public_network", bridge: "Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)"

BUG2:共享目录文件无法即时同步:

先启动,然后在客户端项目文件夹里输入

vagrant rsync-auto

即可从主机单向同步到客户机

BUG3:无法双向同步:

是没有安装guest additions (需要cmd或bash命令行翻墙才能安装)

信息如下:

==> 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: Setting hostname...
==> default: Configuring and enabling network interfaces...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /cygdrive/d/vbox_os_project/centos7_box/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
  • 安装插件
    参考链接:https://www.jianshu.com/p/e28b79afc2f5
    vagrant plugin install vagrant-vbguest
    
  • Vagrantfile 配置共享目录,挂载位置不能使用 /vagrant
    Vagrant.configure("2") do |config|
    config.vm.synced_folder ".", "/share"
    end
    
  • 启动过程会自动联网安装 Virtualbox Guest Additions,并在客户机上安装必要的依赖包,启动后配置的共享目录可以双向读写

  • 每次启动虚机都会检查vbguest插件的更新,如果不想更新,修改Vgrantfilew文件,加上这样一条:

    config.vbguest.auto_update = false
    
  • 禁用默认的/vagrant共享目录
    config.vm.synced_folder ".","/vagrant",disabled:true
    

:我这边测试没新建非默认同步目录的话,不能双向同步(建完同步目录,最好禁用默认/vagrant共享目录)

方法二:使用GoodSync实现文件双向实时同步(收费软件)
https://blog.qxzzf.com/archives/235/