Auto-install qemu-guest-agent package during image customization

This commit is contained in:
2025-11-18 15:34:13 +07:00
parent 4042ad7263
commit 5690f50cfc
3 changed files with 34 additions and 2 deletions

View File

@@ -28,6 +28,12 @@ func customizeImage(config *Config) error {
}
}
if config.GuestAgent {
if err := installGuestAgent(imagePath); err != nil {
return err
}
}
fmt.Println("Verifying customized image...")
if err := verifyImage(imagePath); err != nil {
return fmt.Errorf("customized image verification failed: %w", err)
@@ -93,3 +99,22 @@ func injectSSHKey(imagePath, sshKeyPath string) error {
return nil
}
func installGuestAgent(imagePath string) error {
fmt.Println("Installing QEMU Guest Agent...")
cmd := exec.Command("virt-customize",
"-a", imagePath,
"--install", "qemu-guest-agent",
"--run-command", "systemctl enable qemu-guest-agent",
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to install qemu-guest-agent: %w", err)
}
fmt.Println("QEMU Guest Agent installed and enabled!")
return nil
}