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

@@ -262,7 +262,10 @@ proxmox-cloud-image -batch batch.txt
## How It Works ## How It Works
1. Download cloud image dari URL yang diberikan 1. Download cloud image dari URL yang diberikan
2. Customize image (resize, inject SSH key jika ada) 2. Customize image:
- Resize disk (jika di-specify)
- Inject SSH key (jika ada)
- **Install qemu-guest-agent package** (jika guest-agent enabled)
3. Upload image ke Proxmox host via SCP 3. Upload image ke Proxmox host via SCP
4. Create VM menggunakan `qm` commands 4. Create VM menggunakan `qm` commands
5. Import disk dan configure VM 5. Import disk dan configure VM
@@ -280,11 +283,15 @@ QEMU Guest Agent adalah service yang berjalan di guest OS untuk:
- File system freeze/thaw - File system freeze/thaw
- Time synchronization - Time synchronization
**Tool ini akan otomatis install qemu-guest-agent package** ke dalam image menggunakan `virt-customize` sebelum upload ke Proxmox.
Enable dengan flag `-guest-agent` atau di config file: Enable dengan flag `-guest-agent` atau di config file:
```yaml ```yaml
guest_agent: true guest_agent: true
``` ```
**Note**: Guest agent di-enable by default. Package akan di-install otomatis saat customize image.
## Proxmox Firewall ## Proxmox Firewall
Proxmox firewall bisa di-enable untuk template dengan flag `-firewall` atau di config file: Proxmox firewall bisa di-enable untuk template dengan flag `-firewall` atau di config file:

View File

@@ -16,4 +16,4 @@ firewall_rules:
- type: out - type: out
action: drop action: drop
dest: "10.0.0.0/8" dest: "10.0.0.0/8"
comment: "Bottom most rules - Block service network to internal network" comment: "Bottom most rules - Block service network to internal network"

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...") fmt.Println("Verifying customized image...")
if err := verifyImage(imagePath); err != nil { if err := verifyImage(imagePath); err != nil {
return fmt.Errorf("customized image verification failed: %w", err) return fmt.Errorf("customized image verification failed: %w", err)
@@ -93,3 +99,22 @@ func injectSSHKey(imagePath, sshKeyPath string) error {
return nil 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
}