Monday, November 5, 2018

To share files with VM and to suspend,halt and destroy VMs

To share files using Vagrant , i.e., shared files.

By default , vagrant shared the vagrant file host directory with VM.

It will be visible in the folder in VM as /vagrant.

To change the folder location we can do that in vagrantfile.
We can disable the default share folder.
config.vm.synced_folder "./", "/vagrant" , disabled: true

to change the folder or add folders to share:
config.vm.synced_folder  "www", "/vagrant/www"
config.vm.synced_folder "sites-enabled","/vagrant/sites-enabled"


display the contents using ls.



#like hibernate, suspend the vm created usign vagratn file.
vagrant suspend

#to resume again
vagrant resume

#to shutdown the VM or turnoff
vagrant halt

#to resume halted VM
vagrant up

# to delete the VM,not the vagrant file so we can create again with up.
vagrant destroy

The share option above will keep files on the host filesystem exposed.

Instead rsync, will maintain a seperate copies and sync them when asked for.
But it is one-way, sync done from host to guest.
there are some plugins of vagrant to do two-way.

Other options to share,
NFS,SMB,plugins for more types.




No comments:

Post a Comment