Outils pour utilisateurs

Outils du site


proxmox:template

Ceci est une ancienne révision du document !


Template Proxmox

# Variables
VMID=9000
DEBVER=13
STORAGE=zfs-ssd-pool
IMG=debian-${DEBVER}-genericcloud-amd64.qcow2
 
# Téléchargement
cd /tmp
wget https://cloud.debian.org/images/cloud/trixie/latest/${IMG}
 
# Optionnel mais utile : installer qemu-guest-agent dans l'image avant de l'importer
apt install -y libguestfs-tools
virt-customize -a ${IMG} --install qemu-guest-agent
virt-customize -a ${IMG} --run-command 'systemctl enable qemu-guest-agent'
 
# Création VM template
qm create ${VMID} \
  --name debian${DEBVER}-cloud-template \
  --memory 2048 --cores 2 \
  --net0 virtio,bridge=vmbr0 \
  --scsihw virtio-scsi-pci \
  --ostype l26 \
  --agent enabled=1,fstrim_cloned_disks=1
 
# Import du disque
qm importdisk ${VMID} ${IMG} ${STORAGE}
qm set ${VMID} --scsi0 ${STORAGE}:vm-${VMID}-disk-0,discard=on,ssd=1
 
# Disque cloud-init
qm set ${VMID} --ide2 ${STORAGE}:cloudinit
 
# Boot order + console série (utile pour `qm terminal`)
qm set ${VMID} --boot order=scsi0
qm set ${VMID} --serial0 socket --vga serial0
 
# Conversion en template
qm template ${VMID}
virt-customize -a debian-12-genericcloud-amd64.qcow2 \
  --install qemu-guest-agent,fail2ban,vim,htop,chrony,unattended-upgrades,curl \
  --run-command 'systemctl enable qemu-guest-agent fail2ban chrony unattended-upgrades' \
  --run-command 'useradd -m -s /bin/bash -G sudo mis-admin' \
  --run-command 'echo "mis-admin ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/mis-admin' \
  --ssh-inject mis-admin:file:/root/provisioning/keys/mis-admin.pub \
  --run-command 'sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication no/" /etc/ssh/sshd_config' \
  --run-command 'sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin no/" /etc/ssh/sshd_config' \
  --timezone Europe/Brussels \
  --run-command 'apt-get clean' \
  --truncate /etc/machine-id
 
# Puis import dans Proxmox comme template
proxmox/template.1780418788.txt.gz · Dernière modification : de root