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

Unable to use already existing disk using file. #12643

Open
ForceConstant opened this issue Jan 6, 2022 · 3 comments · May be fixed by #12690
Open

Unable to use already existing disk using file. #12643

ForceConstant opened this issue Jan 6, 2022 · 3 comments · May be fixed by #12690

Comments

@ForceConstant
Copy link

Please note that the Vagrant issue tracker is in priority reserved for bug reports and enhancements. For general usage questions, please use
HashiCorp Discuss: https://discuss.hashicorp.com/c/vagrant/24 Thank you!

When submitting a bug report, please provide the minimal configuration and required information necessary to reliably reproduce the issue. It
should include a basic Vagrantfile that only contains settings to reproduce the described behavior.

Tip: Before submitting your issue, don't hesitate to remove the above introductory text, possible empty sections (e.g. References), and this tip.

Vagrant version

2.2.18

Host operating system

Windows

Guest operating system

Linux

Vagrantfile

...
  config.vm.disk :disk, name: "home", size: "100GB", file: "./home.vdi"

Debug output

...
Disk 'home' not found in guest. Creating and attaching disk to guest...
...

Expected behavior

Utlize already existing vdi disk instead of creating a new one.

Actual behavior

Created a new disk

@haydenseitz
Copy link

haydenseitz commented Feb 11, 2022

I'm also having this issue.

Vagrant version

Vagrant 2.2.19

Host operating system

Windows, using vagrant installed in WSL and Virtualbox installed in Windows (using setup reference from this thread)

Guest operating system

Linux

Vagrantfile

...
  config.vm.disk :disk, size: "10GB", name: "gluster_storage", disk_ext: "vdi"
...

Debug output

...
 INFO subprocess: Starting process: ["/mnt/c/Program Files/Oracle/VirtualBox/VBoxManage.exe", "list", "hdds"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: UUID:           add59cc1-f018-4c71-b2ea-cc0589a60ef6
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\hseitz\VirtualBox VMs\vagrant-test_default_1644609493054_27899\generic-ubuntu2004-virtualbox-disk001.vmdk
Storage format: VMDK
Capacity:       131072 MBytes
Encryption:     disabled

UUID:           dec281f6-be15-4e7e-aa16-2c95297100cb
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\hseitz\vagrant-test\gluster_storage.vdi
Storage format: VDI
Capacity:       10240 MBytes
Encryption:     disabled

DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO interface: detail: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...
 INFO interface: detail:     default: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...
    default: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...
...

EDIT: my steps to get to this error is do vagrant up, then vagrant halt, then the issue happens when trying vagrant up again

@haydenseitz
Copy link

The same issue happens when trying from my WSL home directory, instead of my windows home directory. Notice the path change from C:\Users\... to \\wsl$\Ubuntu\home\...

 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: UUID:           a3b9f57b-4906-4763-9482-4a8587d86e7e
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\hseitz\VirtualBox VMs\vagrant-test_default_1644610594629_31032\generic-ubuntu2004-virtualbox-disk001.vmdk
Storage format: VMDK
Capacity:       131072 MBytes
Encryption:     disabled

UUID:           224a7685-ce31-4804-a138-595e693f6172
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       \\wsl$\Ubuntu\home\hseitz\vagrant-test\gluster_storage.vdi
Storage format: VDI
Capacity:       10240 MBytes
Encryption:     disabled

DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO interface: detail: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...
 INFO interface: detail:     default: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...
    default: Disk 'gluster_storage' not found in guest. Creating and attaching disk to guest...

@haydenseitz
Copy link

I believe here is the problem:

primary = storage_controllers.get_primary_attachment
existing_disk = machine.provider.driver.list_hdds.detect do |d|
File.dirname(d["Location"]) == File.dirname(primary[:location]) &&
d["Disk Name"] == disk.name
end

When checking if a disk already exists, vagrant checks if the directory of the default disk location and the current disk location match. In WSL this fails, because the default disk location begins with C:\ but the additional disk location begins with \\wsl$\, shown here in debugging:

UUID:           9550eff5-ddf8-4fb9-bd72-575282c3d126
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\hseitz\VirtualBox VMs\vagrant-test_default_1644963819550_77749\generic-ubuntu2004-virtualbox-disk001.vmdk
Storage format: VMDK
Capacity:       131072 MBytes
Encryption:     disabled

UUID:           55e76b6b-b6a1-48f4-9216-b17262a337ea
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       \\wsl$\Ubuntu\home\hseitz\vagrant-test\gluster_storage.vdi
Storage format: VDI
Capacity:       10240 MBytes
Encryption:     disabled

I was able to get the VM to accept the existing disk by (manually) updating the disk location in VirtualBox to use the C:\ path instead of \\wsl$\, but I haven't figured out a full workaround yet.

I am thinking the root of the issue happens when the additional disk is first created here:

guest_folder = File.dirname(guest_info["CfgFile"])
disk_ext = disk_config.disk_ext
disk_file = File.join(guest_folder, disk_config.name) + ".#{disk_ext}"
LOGGER.info("Attempting to create a new disk file '#{disk_file}' of size '#{disk_config.size}' bytes")
disk_var = machine.provider.driver.create_disk(disk_file, disk_config.size, disk_ext.upcase)

Looks like when an additional disk is first created, the directory is selected based on the location of the CfgFile, which Windows VirtualBox will create beginning with C:\. I'm assuming this fails (have not properly tested) in WSL, which is why the additional disk is saved to the working dir instead of the virtualbox VM directory. Either way, it seems there is a need for logic to handle C:\ vs \\wsl$\ directories.

I've not contributed to this project before, but I will try my hand at setting up a dev environment and maybe submit a PR.

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

Successfully merging a pull request may close this issue.

2 participants