Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions plugins/providers/virtualbox/cap/configure_disks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def self.resize_disk(machine, disk_config, defined_disk, controller)
# original disk information in case anything goes wrong during clone/resize
original_disk = defined_disk
backup_disk_location = "#{original_disk[:location]}.backup"

# clone disk to vdi formatted disk
vdi_disk_file = machine.provider.driver.vmdk_to_vdi(defined_disk[:location])
# resize vdi
Expand All @@ -357,8 +356,12 @@ def self.resize_disk(machine, disk_config, defined_disk, controller)
machine.provider.driver.remove_disk(controller.name, defined_disk[:port], defined_disk[:device])
# Create a backup of the original disk if something goes wrong
LOGGER.warn("Making a backup of the original disk at #{defined_disk[:location]}")
FileUtils.mv(defined_disk[:location], backup_disk_location)

# tha - has to be fixed
if Vagrant::Util::Platform.wsl?
machine.provider.driver.clone_disk(defined_disk[:location], backup_disk_location, "VMDK")
else
FileUtils.mv(defined_disk[:location], backup_disk_location)
end
# we have to close here, otherwise we can't re-clone after
# resizing the vdi disk
machine.provider.driver.close_medium(defined_disk[:uuid])
Expand All @@ -379,7 +382,11 @@ def self.resize_disk(machine, disk_config, defined_disk, controller)
raise
ensure
# Remove backup disk file if all goes well
FileUtils.remove(backup_disk_location, force: true)
if Vagrant::Util::Platform.wsl?
machine.provider.driver.close_medium(backup_disk_location)
else
FileUtils.remove(backup_disk_location, force: true)
end
end

# Remove cloned resized volume format
Expand Down Expand Up @@ -415,7 +422,12 @@ def self.resize_disk(machine, disk_config, defined_disk, controller)
def self.recover_from_resize(machine, disk_info, backup_disk_location, original_disk, vdi_disk_file, controller)
begin
# move backup to original name
FileUtils.mv(backup_disk_location, original_disk[:location], force: true)
if Vagrant::Util::Platform.wsl?
machine.provider.driver.execute("modifymedium","disk", dbackup_disk_location, "--move", original_disk[:location])
machine.provider.driver.execute("internalcommands", "sethduuid", original_disk[:location], original_info[:uuid])
else
FileUtils.mv(backup_disk_location, original_disk[:location], force: true)
end
# Attach disk
machine.provider.driver.attach_disk(controller.name,
disk_info[:port],
Expand Down
9 changes: 7 additions & 2 deletions plugins/providers/virtualbox/driver/version_5_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,12 @@ def vm_exists?(uuid)
# @param [String] defined_disk_path
# @return [String] destination - The cloned disk
def vmdk_to_vdi(defined_disk_path)

source = defined_disk_path
destination = File.join(File.dirname(source), File.basename(source, ".*")) + ".vdi"

if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.wsl?
destination = destination.sub(/^\.\/+/, '')
end
clone_disk(source, destination, 'VDI')

destination
Expand All @@ -952,7 +955,9 @@ def vmdk_to_vdi(defined_disk_path)
def vdi_to_vmdk(defined_disk_path)
source = defined_disk_path
destination = File.join(File.dirname(source), File.basename(source, ".*")) + ".vmdk"

if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.wsl?
destination = destination.sub(/^\.\/+/, '')
end
clone_disk(source, destination, 'VMDK')

destination
Expand Down