1.9 KiB
1.9 KiB
pve-go
PVE-Go is a go library for the Proxmox VE API.
The design is based on the Hetzner Clound API implementation: https://github.com/hetznercloud/hcloud-go
Cloud-Init Image
How to prepare a cloud-init image.
Download the latest version of the base image to one of your proxmox nodes:
curl -sSL https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img >/tmp/bionic-server-cloudimg-amd64.img
Create a cloud-init config to bootstrap the template:
cat <<'EOF'> /var/lib/vz/snippets/9000_bootstrap
#cloud-config
package_update: true
package_upgrade: true
ntp:
enabled: true
servers: ["pool.ntp.org"]
ssh_deletekeys: true
ssh_genkeytypes: ["ed25519", "rsa"]
runcmd:
- "apt-get -y clean"
- "apt-get -y autoremove --purge"
- "bash -c 'rm /home/ubuntu/.ssh/authorized_keys; exit 0'"
- "bash -c 'find /var/log -type f | while read f; do echo -ne >$f; done; exit 0'"
- "bash -c 'rm -rf /var/lib/cloud/*; exit 0'"
power_state:
mode: poweroff
EOF
Create the template VM:
qm destroy 9000
qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9000 /tmp/bionic-server-cloudimg-amd64.img local
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local:9000/vm-9000-disk-0.raw
qm set 9000 --ide0 local:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0
qm set 9000 --cicustom "user=local:snippets/9000_bootstrap"
qm set 9000 --ipconfig0 ip=dhcp,ip6=dhcp
qm start 9000
sleep 10;while :; do qm status 9000|grep -q stopped && break; done
qm set 9000 --cicustom ""
qm set 9000 --ipconfig0 ""
qm template 9000
More Image Cleanup
apt -y purge apport apport-symptoms bash-completion byobu htop landscape-common lxcfs lxd lxd-client motd-news-config nano ntfs-3g os-prober ufw
apt -y autoremove
Even more cleanup:
apt -y purge lshw lsof ltrace man-db manpages mdadm mtr-tiny screen sosreport strace tcpdump tmux usbutils whiptail
apt -y autoremove