Files
scripts-proxmox/debian-13-fr-vm.sh

115 lines
2.3 KiB
Bash

#!/usr/bin/env bash
set -e
VMID=$(pvesh get /cluster/nextid)
HN="debian13"
BRG="dhcp"
CORE_COUNT="2"
RAM_SIZE="2048"
DISK_SIZE="40G"
echo "Création VM Debian 13 ID: $VMID"
URL="https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2"
FILE=$(basename "$URL")
TMPDIR=$(mktemp -d)
cd "$TMPDIR"
echo "Téléchargement image Debian 13..."
curl -fLO "$URL"
STORAGE="local-zfs"
qm create $VMID \
-name "$HN" \
-memory $RAM_SIZE \
-cores $CORE_COUNT \
-net0 virtio,bridge=$BRG \
-ostype l26 \
-scsihw virtio-scsi-pci \
-agent 1 \
-onboot 0
qm importdisk $VMID "$FILE" $STORAGE
qm set $VMID \
-scsi0 ${STORAGE}:vm-${VMID}-disk-0 \
-boot order=scsi0 \
-serial0 socket \
-scsi1 ${STORAGE}:cloudinit
# DHCP IPv4 dans l'UI cloud-init
qm set "$VMID" --ipconfig0 ip=dhcp >/dev/null
# Root user + password via Proxmox cloud-init (fiable)
qm set "$VMID" --ciuser root --cipassword "root" >/dev/null
# Meilleure résolution console
qm set "$VMID" --vga virtio >/dev/null
# Resize disque côté Proxmox
qm resize "$VMID" scsi0 "$DISK_SIZE" >/dev/null
# ===== Cloud-init FR + ROOT PASSWORD + PROXMOX AGENT =====
SNIPPET_DIR="/var/lib/vz/snippets"
mkdir -p "$SNIPPET_DIR"
cat > "$SNIPPET_DIR/${VMID}-user-data.yaml" <<EOF
#cloud-config
disable_root: false
ssh_pwauth: true
growpart:
mode: auto
devices: ["/"]
ignore_growroot_disabled: false
resize_rootfs: true
chpasswd:
list: |
root:root
expire: false
locale: fr_FR.UTF-8
packages:
- locales
- kbd
- console-setup
- keyboard-configuration
- qemu-guest-agent
write_files:
- path: /etc/default/keyboard
content: |
XKBLAYOUT="fr"
XKBMODEL="pc105"
- path: /etc/default/console-setup
content: |
KEYMAP="fr"
runcmd:
# Locale FR
- sed -i 's/^# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen
- locale-gen
- update-locale LANG=fr_FR.UTF-8
# Clavier console FR
- loadkeys fr || true
- setupcon -k || true
# Activation agent Proxmox
- systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
EOF
qm set $VMID --cicustom "user=local:snippets/${VMID}-user-data.yaml"
echo "VM Debian 13 créée avec succès : $VMID"
echo "Bridge : dhcp | DHCP IPv4 | Clavier FR | root/root | Agent Proxmox OK"
echo "La VM n'est PAS démarrée automatiquement."