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

Support .vhd file #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

remi-espie
Copy link

This PR adds support for .vhd files.

Before this PR, when using a .vhd as the iso_url (as stated possible in the documentation), VirtualBox returns the error Error attaching ISO: VBoxManage error: VBoxManage.exe: error: The medium '<path/to/vhd>' can't be used as the requested device type (DVD, detected HDD).

This solves the issue by checking the extension of the file and, if it is .vhd, by changing the disk type from dvddrive to hdd in the VirtualBox' VM creation command.
If using a hdd type disk, it will not be unmounted before export.
It also removes the creation of a .vdi disk if using a .vhd.

However, by using directly the .vhd file, it is modified and won't remain the same after running packer.
An improvement would be to clone the .vhd file to the temp directory, as (for example) the Hyper-V plugin do.

This closes #123

@remi-espie remi-espie requested a review from a team as a code owner March 6, 2024 14:12
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @remi-espie,

Thanks for the contribution, and apologies for taking so long to review!

The idea makes sense, however before we can consider merging it I would suggest not making the changes in-place, and instead as you point out, clone the disk to another disk, and boot on it at that time. This becomes especially relevant as reusing input as the target makes options like output_directory or output_filename incompatible with that capability, so if we decide to NOT proceed with copying, we should add checks during the Prepare step to make sure that no option gets ignored.

I believe this copy could be done even as a separate builder potentially? I feel like calling the builder ISO and clone a disk may prove slightly confusing, but I can imagine that being a possibility though, especially considering the iso_url docs do mention VHDs.

Thanks again, please let me know your thoughts and feel free to ping me when you're ready for another round of review, I'll take another look then!

@@ -91,11 +92,17 @@ func (s *StepAttachISOs) Run(ctx context.Context, state multistep.StateBag) mult
port = 13
device = 0
}
if path.Ext(isoPath) == ".vhd" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we already had it so I would suggest using filepath for that operation as it is more suited for local file paths (path is more aimed at URIs).
Both work all the same for this though I'd think, my comment is more of a nitpick than anything else

"--medium", diskFullPaths[i],
"--nonrotational", nonrotational,
"--discard", discard,
if path.Ext(state.Get("iso_path").(string)) != ".vhd" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the condition could be reversed to limit the amount of changes here?

Suggested change
if path.Ext(state.Get("iso_path").(string)) != ".vhd" {
if path.Ext(state.Get("iso_path").(string)) == ".vhd" {
return multistep.ActionContinue
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are we certain iso_path is always set? I worry accessing this and casting it to a string may crash the plugin if that's not the case.

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

Successfully merging this pull request may close these issues.

Error when using .VHD as boot device
2 participants