virtualbox - vb.customize 'storageattach' mounts my disk first time, but changes are lost after vagrant halt ; vagrant up -
i new vagrant , trying add second disk virtual machine cooking vagrant. figured out how attach disk when vm first booted, when bring machine down , again (with 'vagrant --provision' make sure provisioners run) changes make disk lost.
i ran both times logging , log output second run (the reboot after machine provisioned) shows storageattach command being executed. every file create under "/dev/shm" (which seems mount point second disk) disappears.
the failure mode is:
vagrant ...
touch /dev/shm/some.file ls /dev/shm/some.file # see output here...
vagrant halt
vagrant --provision
ls /dev/shm/some.file # no such file or directory.. did go ?
any tips 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) |config| config.vm.define :master |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" |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" |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 log output of second 'vagrant --provision' [ using --provision ensure provisioning steps done each vagrant ]:
info sanedefaults: automatically figuring out whether 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 process exit. remaining 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 process exit. remaining timeout: 32000 debug subprocess: exit status: 0
thanks bmw engineered , stylish answer, , peter well. referenced article (gist.github.com/leifg/4713995) had magic, reproduce below in vagrant script , corresponding bootstrap file makes file system newly added second disk, , adds /etc/fstab. solves problem [ no more disappearing data ].
vagrantfile:
vagrant.require_version ">= 1.4.3" vagrantfile_api_version = "2" disk = './seconddisk.vdi' box_name="test" vagrant.configure(vagrantfile_api_version) |config| config.vm.define :master |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" |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'] ) # create second disk , attach config.vm.provider "virtualbox" |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 # new - invoke script partitions new disk (/dev/sdb) # , create mount directives in /etc/fstab #config.vm.provision :shell, path: "bootstrap.sh" config.vm.provision "shell" |shell| shell.inline = "sudo /vagrant/bootstrap.sh" end end
bootstap script:
#!/bin/bash -x # configure , mount second disk # yum install -y parted parted /dev/sdb mklabel msdos parted /dev/sdb mkpart primary 512 100% mkfs.xfs /dev/sdb1 mkdir /mnt/disk echo `blkid /dev/sdb1 | awk '{print$2}' | sed -e 's/"//g'` /mnt/disk xfs noatime,nobarrier 0 0 >> /etc/fstab mount /mnt/disk
Comments
Post a Comment