Vb.customize 'storageattach' mounts my drive for the first time, but changes are lost after stopping vagrants; wandering up

I am new to vagrant and am trying to add a second drive to a virtual machine that I am cooking with vagrant. I figured out how to reattach the disk when the VM boots first, but when I bring the machine down and then back up again (with a "roaming-up-provision" to make sure the conductors are running) the changes I make to the disk are lost.

I ran both times with logging, and the log output for the second run (reboot after the machine was initially provisioned) shows the storageattach command being executed. But every file created under "/ dev / shm" (which appears to be the mount point for the second drive) disappears.

Failure Mode:

tramp up ...

 touch /dev/shm/some.file
 ls /dev/shm/some.file   # see output here... 

      

wandering stop

vagrant up --provision

ls /dev/shm/some.file     #  no such file or directory.. where did it go ? 

      

any hints would be most appreciated.

My Vagrantfile:

...

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 use -provision so that all initialization 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

      

+3


source to share


1 answer


Thanks to BMW for a well-engineered and stylish answer, and Peter. The linked article (gist.github.com/leifg/4713995) had the magic that I will reproduce below in a Vagrant script and the corresponding bootstrap file that makes the filesystem from the newly added second drive and adds it to / etc. / Fstab. This completely solves my problem [no more data disappears].

Vagrantfile:

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']
    )

    # create the second disk and attach it
    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

    # NEW - invoke script which  partitions the new disk (/dev/sdb) 
    # and create mount directives in /etc/fstab
    #config.vm.provision :shell, path: "bootstrap.sh"  
    config.vm.provision "shell" do |shell|
        shell.inline = "sudo /vagrant/bootstrap.sh"  
    end
end

      



bootstap script:

#!/bin/bash  -x

#   configure and 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

      

+4


source







All Articles