From 74255c553b982b1fceca2bfa9d9dfb9bbf05dcf2 Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Mon, 14 Nov 2016 23:11:26 +0000 Subject: [PATCH] Be smarter about loading guest additions iso. Windows 10 and Windows Server 2016 no longer come with iso. So default to not loading guest additions when the iso is missing --- builder/hyperv/iso/builder.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index ac55399b3..e68c38e2d 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -182,11 +182,30 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { // Errors if b.config.GuestAdditionsMode == "" { - b.config.GuestAdditionsMode = "attach" + if b.config.GuestAdditionsPath != "" { + b.config.GuestAdditionsMode = "attach" + } else { + b.config.GuestAdditionsPath = os.Getenv("WINDIR") + "\\system32\\vmguest.iso" + + if _, err := os.Stat(b.config.GuestAdditionsPath); os.IsNotExist(err) { + if err != nil { + b.config.GuestAdditionsPath = "" + b.config.GuestAdditionsMode = "none" + } else { + b.config.GuestAdditionsMode = "attach" + } + } + } } - if b.config.GuestAdditionsPath == "" { + if b.config.GuestAdditionsPath == "" && b.config.GuestAdditionsMode == "attach" { b.config.GuestAdditionsPath = os.Getenv("WINDIR") + "\\system32\\vmguest.iso" + + if _, err := os.Stat(b.config.GuestAdditionsPath); os.IsNotExist(err) { + if err != nil { + b.config.GuestAdditionsPath = "" + } + } } for _, isoPath := range b.config.SecondaryDvdImages {