Add Hyper-V support for Gen-1 boot order with ISO
This commit is contained in:
parent
e490b7651d
commit
55ae803852
|
@ -148,6 +148,13 @@ type CommonConfig struct {
|
|||
// built. When this value is set to true, the machine will start without a
|
||||
// console.
|
||||
Headless bool `mapstructure:"headless" required:"false"`
|
||||
// Over time the Hyper-V builder has been modified to change the original
|
||||
// boot order that is used when an ISO is mounted. Hyper-V's default is to
|
||||
// boot from the CD first, the original Hyper-V builder included code to
|
||||
// codify this setting when the primary ISO is mounted, that code was eventually
|
||||
// modified to place the IDE adapter before the the CD (only in generation 1).
|
||||
// Setting this value to true, forces the original method of operation.
|
||||
LegacyGen1BootOrder bool `mapstructure:"legacy_gen1_boot_order" required:"false"`
|
||||
}
|
||||
|
||||
func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) ([]error, []string) {
|
||||
|
|
|
@ -111,7 +111,7 @@ type Driver interface {
|
|||
|
||||
MountDvdDrive(string, string, uint, uint) error
|
||||
|
||||
SetBootDvdDrive(string, uint, uint, uint) error
|
||||
SetBootDvdDrive(string, uint, uint, uint, bool) error
|
||||
|
||||
UnmountDvdDrive(string, uint, uint) error
|
||||
|
||||
|
|
|
@ -263,8 +263,8 @@ func (d *HypervPS4Driver) MountDvdDrive(vmName string, path string, controllerNu
|
|||
}
|
||||
|
||||
func (d *HypervPS4Driver) SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint,
|
||||
generation uint) error {
|
||||
return hyperv.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, generation)
|
||||
generation uint, legacyGen1BootOrder bool) error {
|
||||
return hyperv.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, generation, legacyGen1BootOrder)
|
||||
}
|
||||
|
||||
func (d *HypervPS4Driver) UnmountDvdDrive(vmName string, controllerNumber uint, controllerLocation uint) error {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
type StepMountDvdDrive struct {
|
||||
Generation uint
|
||||
LegacyGen1BootOrder bool
|
||||
}
|
||||
|
||||
func (s *StepMountDvdDrive) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -58,7 +59,7 @@ func (s *StepMountDvdDrive) Run(ctx context.Context, state multistep.StateBag) m
|
|||
state.Put("os.dvd.properties", dvdControllerProperties)
|
||||
|
||||
ui.Say(fmt.Sprintf("Setting boot drive to os dvd drive %s ...", isoPath))
|
||||
err = driver.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, s.Generation)
|
||||
err = driver.SetBootDvdDrive(vmName, controllerNumber, controllerLocation, s.Generation, s.LegacyGen1BootOrder)
|
||||
if err != nil {
|
||||
err := fmt.Errorf(errorMsg, err)
|
||||
state.Put("error", err)
|
||||
|
|
|
@ -242,7 +242,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
&hypervcommon.StepEnableIntegrationService{},
|
||||
|
||||
&hypervcommon.StepMountDvdDrive{
|
||||
Generation: b.config.Generation,
|
||||
Generation: b.config.Generation,
|
||||
LegacyGen1BootOrder: b.config.LegacyGen1BootOrder,
|
||||
},
|
||||
&hypervcommon.StepMountFloppydrive{
|
||||
Generation: b.config.Generation,
|
||||
|
|
|
@ -282,7 +282,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
&hypervcommon.StepEnableIntegrationService{},
|
||||
|
||||
&hypervcommon.StepMountDvdDrive{
|
||||
Generation: b.config.Generation,
|
||||
Generation: b.config.Generation,
|
||||
LegacyGen1BootOrder: b.config.LegacyGen1BootOrder,
|
||||
},
|
||||
&hypervcommon.StepMountFloppydrive{
|
||||
Generation: b.config.Generation,
|
||||
|
|
|
@ -156,13 +156,21 @@ Hyper-V\Set-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -Cont
|
|||
return err
|
||||
}
|
||||
|
||||
func SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint, generation uint) error {
|
||||
func SetBootDvdDrive(vmName string, controllerNumber uint, controllerLocation uint, generation uint, legacyGen1BootOrder bool) error {
|
||||
|
||||
if generation < 2 {
|
||||
script := `
|
||||
var script string
|
||||
if (legacyGen1BootOrder) {
|
||||
script = `
|
||||
param([string]$vmName)
|
||||
Hyper-V\Set-VMBios -VMName $vmName -StartupOrder @("CD","IDE","LegacyNetworkAdapter","Floppy")
|
||||
`
|
||||
} else {
|
||||
script = `
|
||||
param([string]$vmName)
|
||||
Hyper-V\Set-VMBios -VMName $vmName -StartupOrder @("IDE","CD","LegacyNetworkAdapter","Floppy")
|
||||
`
|
||||
}
|
||||
var ps powershell.PowerShellCmd
|
||||
err := ps.Run(script, vmName)
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue