1. Install VirtualBox and Vagrant

Install VirtualBox first and then Vagrant. I’m using VirtualBox6.0.8, vagrant_2.4_x86_64.

2. Download the box

I’m using Centos7

Cloud.centos.org/centos/7/va…

Choose your preferred system here cloud.centos.org/centos/

3. Add the box

Create a directory and add box to the directory

vagrant box add Centos7 CentOS-7-x86_64-Vagrant-1902_01.VirtualBox.box
Copy the code

4. Initialize Centos7

The initialization generates a file, Vagrantfile, in the current folder

vagrant init Centos7
Copy the code

Modify the configuration file as follows

Vagrant.configure("2") do |config|  config.vm.box = "centos7"    config.vm.hostname = "CentOS7"    config.vm.synced_folder "D:/Vagrant-work", "/work" 
Copy the code

5. Start the VM

vagrant up
Copy the code

6. Connect the VM

vagrant ssh
Copy the code

The default login user is Vagrant. The default password for root is also vagrant.

7. Install the VBGuest plug-in

Shut down the VIRTUAL machine and run the install command. After the installation is complete, reload the virtual machine and you can see that the VirtualBox Guest Additions installer is being installed.

vagrant plugin install vagrant-vbguest
vagrant reload
Copy the code

Since we have Guest Additions installed above, we need to modify the VagrantFile configuration file so as not to repeat the Guest Additions installation on the next startup by adding two lines of commands before the last end of the configuration file

Vagrant.configure("2") do |config|  config.vm.box = "centos7"    config.vm.hostname = "CentOS7"    config.vm.synced_folder "D:/Vagrant-work", "/work"   config.vbguest.auto_update = false   config.vbguest.no_remote = true   
Copy the code

8. Set automatic mounting upon startup

Then SSH connects to the server. When the system called fstab, the Virtualbox shared directory module had not been loaded, so I had failed to install it before. The final solution is as follows: Add the following command to the /etc/rc.local file as user root

mount -t vboxsf sharing /mnt/share
Copy the code

9. Restart the VM and check whether the shared directory is available

Reboot to see Machine Booted and Ready! default: /work => D:/Vagrant-work

You can create files under the shared directory work to see if bidirectional sharing is possible

10. The common command of Vagrant

Vagrant box add <boxname> <boxfile> vagrant box remove <boxname> vagrant box add <boxname> [Initialize the vagrantfile] Vagrant init < boxName > [Start the virtual machine] Vagrant up [login the virtual machine] Vagrant SSH [Shut down the virtual machine] Vagrant HALT [Check the virtual machine state] Vagrant Status Delete VM Vagrant DestoryCopy the code

Restart the virtual box

sudo "/Library/Application Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh" restart
Copy the code