Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant VirtualBox second disk path

I have Vagrant + VirtualBox.

In my Vagrantfile I have

config.vm.provider "virtualbox" do |v|
    v.customize [ "createhd", "--filename", "disk", "--size", 100000 ]
    v.customize [ 'storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', "disk"]
end

When I fire up with vagrant up it looks for "disk" in C:\HashiCorp\Vagrant\bin\disk

VBoxManage.exe: error: Could not find file for the medium 'C:\HashiCorp\Vagrant\bin\disk' (VERR_FILE_NOT_FOUND)

I would like the disk to live alongside the virtual machine's first disk in C:\Users\jma47\VirtualBox VMs\bin_build_1389371691

How can I do this in Vagrantfile?

like image 508
Jepper Avatar asked Jan 10 '14 17:01

Jepper


People also ask

Where are vagrant files stored?

Windows: C:/Users/USERNAME/. vagrant. d/boxes.

How does vagrant work with VirtualBox?

Vagrant is an open-source tool that allows you to create, configure, and manage boxes of virtual machines through an easy to use command interface. Essentially, it is a layer of software installed between a virtualization tool (such as VirtualBox, Docker, Hyper-V) and a VM.

What is the difference between VirtualBox and vagrant?

Vagrant can be classified as a tool in the "Virtual Machine Management" category, while VirtualBox is grouped under "Virtualization Platform". Some of the features offered by Vagrant are: Boxes. Up And SSH.


1 Answers

This can be done if you define a name for virtual machine:

# Try to make it work on both Windows and Linux
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
  vboxmanage_path = "C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe"
else
  vboxmanage_path = "VBoxManage" # Assume it's in the path on Linux
end

Vagrant.configure(2) do |config|
  config.vm.box = "debian/wheezy64"

  config.vm.provider "virtualbox" do |vb|
    vb.name = "VM Name"

    # Get disk path
    line = `"#{vboxmanage_path}" list systemproperties`.split(/\n/).grep(/Default machine folder/).first
    vb_machine_folder = line.split(':', 2)[1].strip()
    second_disk = File.join(vb_machine_folder, vb.name, 'disk2.vdi')

    # Create and attach disk
    unless File.exist?(second_disk)
      vb.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 60 * 1024]
    end
    vb.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
  end
end
like image 104
xuhcc Avatar answered Sep 23 '22 19:09

xuhcc