implement resize disk

This commit is contained in:
Jonas Leder 2024-08-04 00:13:19 +02:00
commit e5390800bf
4 changed files with 27 additions and 6 deletions

View file

@ -3,5 +3,6 @@
"rebootIfRequired": true,
"updateHostname": true,
"updatePassword": true,
"updateNetworkConfig": true
"updateNetworkConfig": true,
"resizeDisk": true
}

View file

@ -9,11 +9,12 @@ import (
)
type Config struct {
PasswordApiEndpoint string `json:"passwordApiEndpoint"`
RebootIfRequired bool `json:"rebootIfRequired"`
UpdateHostname bool `json:"updateHostname"`
UpdatePassword bool `json:"updatePassword"`
UpdateNetworkConfig bool `json:"updateNetworkConfig"`
PasswordApiEndpoint string `json:"passwordApiEndpoint"`
RebootIfRequired bool `json:"rebootIfRequired"`
UpdateHostname bool `json:"updateHostname"`
UpdatePassword bool `json:"updatePassword"`
UpdateNetworkConfig bool `json:"updateNetworkConfig"`
ResizeDisk bool `json:"resizeDisk"`
}
var Configuration Config

View file

@ -93,6 +93,13 @@ func application() {
}
}
if config.Configuration.ResizeDisk {
err := windows.ResizeDisk("C")
if err != nil {
log.Log.Error("Failed resizing disk", err.Error())
}
}
if rebootRequired {
log.Log.Warn("Reboot is required to apply the changes")
if len(os.Args) > 1 && os.Args[1] == "firstboot" {

12
windows/resizedisk.go Normal file
View file

@ -0,0 +1,12 @@
package windows
import (
"fmt"
"jonasled.dev/jonasled/cloud-init-windows/log"
)
func ResizeDisk(driveLetter string) error {
log.Log.Info(fmt.Sprintf("Resizing Partition %s to fill disk", driveLetter))
return execPsCommand(fmt.Sprintf("Resize-Partition -DriveLetter %s -Size (Get-PartitionSupportedSize -DriveLetter %s).SizeMax", driveLetter, driveLetter))
}