From 591b1c2637f7337dc85761734b8eaa92d86c357b Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sun, 14 Feb 2021 23:43:48 +0100 Subject: [PATCH] VirtualBox: added support for "virtio" ISO interface. --- builder/virtualbox/common/step_attach_isos.go | 14 +++++++++++++- builder/virtualbox/iso/builder.go | 4 ++-- builder/virtualbox/iso/step_create_disk.go | 13 +++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/builder/virtualbox/common/step_attach_isos.go b/builder/virtualbox/common/step_attach_isos.go index fe1156d67..24c81dd1e 100644 --- a/builder/virtualbox/common/step_attach_isos.go +++ b/builder/virtualbox/common/step_attach_isos.go @@ -80,6 +80,10 @@ func (s *StepAttachISOs) Run(ctx context.Context, state multistep.StateBag) mult controllerName = "SATA Controller" port = "1" device = "0" + } else if s.ISOInterface == "virtio" { + controllerName = "VirtIO Controller" + port = "1" + device = "0" } ui.Message("Mounting boot ISO...") case "guest_additions": @@ -90,6 +94,10 @@ func (s *StepAttachISOs) Run(ctx context.Context, state multistep.StateBag) mult controllerName = "SATA Controller" port = "2" device = "0" + } else if s.GuestAdditionsInterface == "virtio" { + controllerName = "VirtIO Controller" + port = "2" + device = "0" } ui.Message("Mounting guest additions ISO...") case "cd_files": @@ -100,7 +108,11 @@ func (s *StepAttachISOs) Run(ctx context.Context, state multistep.StateBag) mult controllerName = "SATA Controller" port = "3" device = "0" - } + } else if s.ISOInterface == "virtio" { + controllerName = "VirtIO Controller" + port = "3" + device = "0" + } ui.Message("Mounting cd_files ISO...") } diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 562410f50..39a7f8c81 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -211,9 +211,9 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { errs, errors.New("nvme_port_count cannot be greater than 255")) } - if b.config.ISOInterface != "ide" && b.config.ISOInterface != "sata" { + if b.config.ISOInterface != "ide" && b.config.ISOInterface != "sata" && b.config.ISOInterface != "virtio" { errs = packersdk.MultiErrorAppend( - errs, errors.New("iso_interface can only be ide or sata")) + errs, errors.New("iso_interface can only be ide, sata or virtio")) } // Warnings diff --git a/builder/virtualbox/iso/step_create_disk.go b/builder/virtualbox/iso/step_create_disk.go index 3826fa3d1..b23418d5f 100644 --- a/builder/virtualbox/iso/step_create_disk.go +++ b/builder/virtualbox/iso/step_create_disk.go @@ -66,15 +66,20 @@ func (s *stepCreateDisk) Run(ctx context.Context, state multistep.StateBag) mult } } - if config.HardDriveInterface == "scsi" { - if err := driver.CreateSCSIController(vmName, "SCSI Controller"); err != nil { + // Add a VirtIO controller if we were asked to use VirtIO. We still attach + // the VirtIO controller above because some other things (disks) require + // that. + if config.HardDriveInterface == "virtio" || config.ISOInterface == "virtio" { + if err := driver.CreateVirtIOController(vmName, "VirtIO Controller"); err != nil { err := fmt.Errorf("Error creating disk controller: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } - } else if config.HardDriveInterface == "virtio" { - if err := driver.CreateVirtIOController(vmName, "VirtIO Controller"); err != nil { + } + + if config.HardDriveInterface == "scsi" { + if err := driver.CreateSCSIController(vmName, "SCSI Controller"); err != nil { err := fmt.Errorf("Error creating disk controller: %s", err) state.Put("error", err) ui.Error(err.Error())