@@ -428,8 +428,19 @@ func (d *Driver) generateDiskImage() (string, error) {
428428 diskImage := d .ResolveStorePath ("disk.vhd" )
429429 fixed := d .ResolveStorePath ("fixed.vhd" )
430430
431+ // Resizing vhds requires administrator priviledges
432+ // incase the user is only a hyper-v admin then create the disk at the target size to avoid resizing.
433+ isWindowsAdmin , err := isWindowsAdministrator ()
434+ if err != nil {
435+ return "" , err
436+ }
437+ fixedDiskSize := "10MB"
438+ if ! isWindowsAdmin {
439+ fixedDiskSize = toMb (d .DiskSize )
440+ }
441+
431442 log .Infof ("Creating VHD" )
432- if err := cmd ("New-VHD" , "-Path" , quote (fixed ), "-SizeBytes" , "10MB" , "-Fixed" ); err != nil {
443+ if err := cmd ("New-VHD" , "-Path" , quote (fixed ), "-SizeBytes" , fixedDiskSize , "-Fixed" ); err != nil {
433444 return "" , err
434445 }
435446
@@ -451,12 +462,14 @@ func (d *Driver) generateDiskImage() (string, error) {
451462 }
452463 file .Close ()
453464
454- if err := cmd ("Convert-VHD" , "-Path" , quote (fixed ), "-DestinationPath" , quote (diskImage ), "-VHDType" , "Dynamic" ); err != nil {
465+ if err := cmd ("Convert-VHD" , "-Path" , quote (fixed ), "-DestinationPath" , quote (diskImage ), "-VHDType" , "Dynamic" , "-DeleteSource" ); err != nil {
455466 return "" , err
456467 }
457468
458- if err := cmd ("Resize-VHD" , "-Path" , quote (diskImage ), "-SizeBytes" , toMb (d .DiskSize )); err != nil {
459- return "" , err
469+ if isWindowsAdmin {
470+ if err := cmd ("Resize-VHD" , "-Path" , quote (diskImage ), "-SizeBytes" , toMb (d .DiskSize )); err != nil {
471+ return "" , err
472+ }
460473 }
461474
462475 return diskImage , nil
0 commit comments