Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reload + vb.customize = sad #6

Open
thenoid opened this issue Oct 1, 2015 · 6 comments
Open

reload + vb.customize = sad #6

thenoid opened this issue Oct 1, 2015 · 6 comments

Comments

@thenoid
Copy link

thenoid commented Oct 1, 2015

In my vagrant file i have something like this

diskpath="c:\\tmp\\"
srvname="somerandomstring"
file_to_disk="#{diskpath}#{srvname}.vdi"

    srv.vm.provider :virtualbox do |vb|
      unless File.exist?('file_to_disk')
        puts file_to_disk 
        vb.customize ['createhd', '--filename', file_to_disk, '--size', 100 * 1024]

      end
      vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
    end

    srv.vm.provision :shell, path: "scripts/proxy_setup.sh"
    srv.vm.provision :reload

Problem that i'm running into, is that when reload executes - it appears the value of the "File.exists?" isn't being re-evaluated, so the condition still returns false adn the createhd executes again, which errors out.

i've tested that if the file exists before hand, teh File.exists triggers, so i know my logic/paths aren't bad there. Definitely some interaction between reload + customizer

A customization command failed:

["createhd", "--filename", "c:\\tmp\\openshift-infra-ctp-rh7-x86_64.vdi", "--size", 102400]

  The following error was experienced:

  #<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

  Command: ["createhd", "--filename", "c:\\tmp\\openshift-infra-ctp-rh7-x86_64.vdi", "--size", "102400"]

  Stderr: 0%...
  Progress state: VBOX_E_FILE_ERROR
  VBoxManage.exe: error: Failed to create medium
  VBoxManage.exe: error: Could not create the medium storage unit 'c:\tmp\openshift-infra-ctp rh7-x86_64.vdi'.
  VBoxManage.exe: error: VDI: cannot create image 'c:\tmp\openshift-infra-ctp-rh7-x86_64.vdi' (VERR_ALREADY_EXISTS)
  VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
  VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreateMedium(struct HandlerArg *)" at line 449 of file VBoxManageDisk.cpp
  >

  Please fix this customization and try again.
@marcindulak
Copy link

The same problem here with virtualbox-5.0, Ubuntu 14.04, 3.13.0-85-generic, vagrant_1.8.1_x86_64.deb.

Virtualbox to 4.3.38r106717 reloads without errors.
Interestingly the "puts" statement does not give any output when successfully reloading with virtualbox-4.3 so probably it's a wrong track.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.define "centos7" do |machine|
    machine.vm.box = "puppetlabs/centos-7.2-64-puppet"
    machine.vm.box_url = "puppetlabs/centos-7.2-64-puppet"
    machine.vm.provider "virtualbox" do |v|
      v.memory = 256
      v.cpus = 1
      disk = 'sdb.vdi'
      if !File.exist?(disk)
        puts disk
        v.customize ['createhd', '--filename', disk, '--size', 64, '--variant', 'Fixed']
        v.customize ['modifyhd', disk, '--type', 'writethrough']
      end
      v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', disk]
    end
  end
  config.vm.define "centos7" do |machine|
    machine.vm.provision :reload
  end
end

@frusswur
Copy link

I had a similar problem. For me the problem could be solved to shorten the file path ot the image. On Windows for example the maximum length of a file path is 260 chars.

@marcinbarczynski
Copy link

Reloading works fine on VirtualBox 4.3, because vboxmanage createhd returns 0 even if it failed: see output of vagrant up --debug.

@an0t8
Copy link

an0t8 commented Sep 18, 2017

This is still a problem. And reverting to an old version of VirtualBox is not a good solution. Is there any way to have reload clear out the provider object or something?

@marcindulak
Copy link

This project is not maintained. Switch to https://github.com/vagrant-libvirt/vagrant-libvirt if you can, it does not seem to have such problems.

@rubenst2013
Copy link

On the eve to 2019 and the problem still persists.
Just tested with Vagrant 2.2.2 and VBox 6. windows 10 1809 as host and Ubuntu 18.04 as guest.

I also tried many different variants of how to wrap that "pre boot customization" in various conditionals - but it seems like whenever the reload happens the vm is properly shutdown and then vagrant tries to do the "pre boot customizations" again while ignoring every conditional constructs around them.

Could this be an issue with the evaluation order of vagrant files?

I found a workaround...I extracted the vboxmanage createmedium disk command to a shell script and then call vagrant up. that way the provisioning works.
I will try to augment the virtualbox providers customize command with some additional checks, like ignoring a given list of errors or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants