This is the 40th article in the technical Writing Project (including translation). Set a small goal of 999, at least 2 articles per week.

This article focuses on how to share folders with VirtualBox

  • Rsync is unidirectional (changes in the host machine are periodically synchronized to the VM, but the changes in the VM do not affect the host)
  • NFS official document saysWindows users: NFS folders do not work on Windows hosts. Vagrant will ignore your request for NFS synced folders on Windows.And the need to download plug-ins, novice nine times out of ten will be cheated
  • SMB has good compatibility and supports MAC, Linux, and Windows access (VIRTUAL machines). The host is limited to MAC and Win. However, WIN requires administrator rights, and operations on MAC are complicated and must be configured to prevent automatic timeout
  • All things considered, VirtualBox is good, of course, but it has performance issues if there are too many files, meaning don’t use it to build front-end projects (anode_modulesRsync can be used in conjunction with rsync. Rsync can be used to set the excluded directory, and then periodically synchronize to the VIRTUAL machine. If you need bidirectional, then copy files to the directory mounted as VirtualBox, the host machine can access.

The Python + Vagrant + VirtualBox series

  • Pycharm + Vagrant + VirtualBox (Pycharm + Vagrant + VirtualBox)
  • 037- Vagrant automatically synchronizes files after startup (up) (rsync-auto)
  • 040- Resolve Linux sharing folder problem using VirtualBox
  • Win10 VirtualBox fails to start (VERR_NEM_VM_CREATE_FAILED)
  • 043- Resolving vagrant Permission denied to access virtualBox shared folder
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box_check_update = false
  config.vm.box = "centos/7"
  config.vm.hostname = "ansible"
  config.vm.network "private_network", ip: "172.17.8.102"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    vb.cpus = 2
    vb.name = config.vm.hostname
  end
  Unidirectional synchronization
  config.vm.synced_folder "."."/vagrant".type: "rsync",
    rsync__verbose: true,
    rsync__auto: true,
    rsync__exclude: ['.git*'.'node_modules*'.'*.log'.'*.box'.'Vagrantfile']
    config.trigger.after :up do |t|
      t.info = "rsync auto"
      t.run = {inline: "vagrant rsync-auto"}
    end
  
  config.vm.provision "shell", inline: <<-SHELL
## Configure xshell etc can use password login
sed -e "s/#PasswordAuthentication yes/PasswordAuthentication yes/g" -e "s/PasswordAuthentication no/PasswordAuthentication yes/g" -i  /etc/ssh/sshd_config
service sshd restart

## Set up the qinghua-yuan of yum
sudo sed -e "/mirrorlist/d" -e "s/#baseurl/baseurl/g" -e "s/mirror\.centos\.org/mirrors\.tuna\.tsinghua\.edu\.cn/g" -i /etc/yum.repos.d/CentOS-Base.repo
sudo yum makecache
sudo yum install -y epel-release

Install virtualBox kernel headers
yum install -y gcc make kernel-headers-$(uname -r) kernel-devel-$( uname -r)

You can use rsync to synchronize directories without having to download them online every timeThe curl -o http://download.virtualbox.org/virtualbox/6.0.10/VBoxGuestAdditions_6.0.10.iso sudo mkdir / media/VBoxGuestAdditions sudo mount -o loop, ro VBoxGuestAdditions_6. 0.10 iso/media/VBoxGuestAdditions sudo sh / media/VBoxGuestAdditions VBoxLinuxAdditions. Run the rm VBoxGuestAdditions_6. 0.10 iso sudo umount/media/VBoxGuestAdditions sudo rmdir /media/VBoxGuestAdditions SHELL endCopy the code





Want ads

Friends in Jinan, Shandong, welcome to join us and do things together. Long-term recruitment, Java programmer, big data engineer, operation and maintenance engineer, front-end engineer.

The resources

  • My blog
  • I’m the nuggets
  • larsar/shared_folder_centos_virtualbox.txt
  • Synced Folders
  • How to sync folder with Vagrant in Windows?
  • Automatically download and install VirtualBox guest additions in Vagrant