i am new to vagrant and am trying to add a second disk to the virtual machine i am cooking up with vagrant.
i figured out how to attach the disk when the VM is first booted, but when i bring the machine down
and then back up again (with 'vagrant up –provision' to make sure the provisioners run) the changes i make to the disk
are lost.
I ran both times with logging and the log output for the second run (the reboot after the machine is initially provisioned) shows that the storageattach command being executed. But every file i create under "/dev/shm" (which seems to be the mount point for the second disk) disappears.
The failure mode is:
vagrant up …
touch /dev/shm/some.file
ls /dev/shm/some.file # see output here...
vagrant halt
vagrant up –provision
ls /dev/shm/some.file # no such file or directory.. where did it go ?
any tips would be most appreciated.
My Vagrantfile is:
…
Vagrant.require_version ">= 1.4.3"
VAGRANTFILE_API_VERSION = "2"
disk = './secondDisk.vdi'
BOX_NAME="test"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master do |master|
master.vm.box = "centos65"
master.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
master.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "4196"]
v.name = BOX_NAME
end
master.vm.network :private_network, ip: "192.168.33.10"
master.vm.hostname = BOX_NAME
end
config.vm.synced_folder(".", "/vagrant",
:owner => "vagrant",
:group => "vagrant",
:mount_options => ['dmode=777','fmode=777']
)
config.vm.provider "virtualbox" do |vb|
unless File.exist?(disk)
vb.customize ['createhd', '--filename', disk, '--variant', 'Fixed', '--size', 1 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
end
end
and here is the log output of the second 'vagrant up –provision' [ i am using –provision to ensure all provisioning steps are done with each vagrant up ]:
INFO sanedefaults: Automatically figuring out whether to enable/disable NAT DNS proxy...
INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "modifyvm", "ea5c09 e7-11e7-4630-a7ca-ec66461b9eb6", "--natdnsproxy1", "on"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
INFO warden: Calling IN action: #<VagrantPlugins::ProviderVirtualBox::Action::Customize:0x3dc9818>
INFO interface: info: Running 'pre-boot' VM customizations...
INFO interface: info: ==> master: Running 'pre-boot' VM customizations...
==> master: Running 'pre-boot' VM customizations...
INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "storageattach", "e a5c09e7-11e7-4630-a7ca-ec66461b9eb6", "--storagectl", "SATA", "--port", "1", "--device", "0", "--type", "hdd", "- -medium", "./secondDisk.vdi"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
Best Answer
Thanks to BMW for the well engineered and stylish answer, and Peter as well. The referenced article (gist.github.com/leifg/4713995) had the magic, which i will reproduce below in a Vagrant script and a corresponding bootstrap file that makes a file system from the newly added second disk, and adds it to /etc/fstab. This completely solves my problem [ no more disappearing data ].
Vagrantfile:
bootstap script: