-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathdebian-13-cloudinit.sh
More file actions
73 lines (59 loc) · 2.4 KB
/
Copy pathdebian-13-cloudinit.sh
File metadata and controls
73 lines (59 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /bin/bash
set -xe
VMID="${VMID:-8000}"
STORAGE="${STORAGE:-local-zfs}"
IMG="debian-13-generic-amd64.qcow2"
BASE_URL="https://cloud.debian.org/images/cloud/trixie/latest"
EXPECTED_SHA=$(wget -qO- "$BASE_URL/SHA512SUMS" | awk '/'$IMG'/{print $1}')
download() {
wget -q "$BASE_URL/$IMG"
}
verify() {
sha512sum "$IMG" | awk '{print $1}'
}
[ ! -f "$IMG" ] && download
ACTUAL_SHA=$(verify)
if [ "$EXPECTED_SHA" != "$ACTUAL_SHA" ]; then
rm -f "$IMG"
download
ACTUAL_SHA=$(verify)
[ "$EXPECTED_SHA" != "$ACTUAL_SHA" ] && exit 1
fi
rm -f debian-13-generic-amd64-resized.qcow2
cp debian-13-generic-amd64.qcow2 debian-13-generic-amd64-resized.qcow2
qemu-img resize debian-13-generic-amd64-resized.qcow2 8G
sudo qm destroy $VMID || true
sudo qm create $VMID --name "debian-13-template" --ostype l26 \
--memory 1024 --balloon 0 \
--agent 1 \
--bios ovmf --machine q35 --efidisk0 $STORAGE:0,pre-enrolled-keys=0 \
--cpu x86-64-v2-AES --cores 1 --numa 1 \
--vga serial0 --serial0 socket \
--net0 virtio,bridge=vmbr0,mtu=1
sudo qm importdisk $VMID debian-13-generic-amd64-resized.qcow2 $STORAGE
sudo qm set $VMID --scsihw virtio-scsi-pci --scsi0 $STORAGE:vm-$VMID-disk-1,discard=on,ssd=1
sudo qm set $VMID --boot order=scsi0
sudo qm set $VMID --scsi1 $STORAGE:cloudinit
if [ ! -d "/var/lib/vz/snippets" ]; then
mkdir -p "/var/lib/vz/snippets"
fi
cat << EOF | sudo tee /var/lib/vz/snippets/debian-13.yaml
#cloud-config
runcmd:
- "sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources"
- apt-get update
- apt-get install -y gnupg qemu-guest-agent
- reboot
# Taken from https://forum.proxmox.com/threads/combining-custom-cloud-init-with-auto-generated.59008/page-3#post-428772
EOF
echo "timezone: "$(cat /etc/timezone) | sudo tee -a /var/lib/vz/snippets/debian-13.yaml
# echo "locale: "$LANG | sudo tee -a /var/lib/vz/snippets/debian-13.yaml
# As of 2026-02-27 CloudInit is unable to set the locale on Debian 13
# See https://github.com/canonical/cloud-init/pull/6472
# As of 2026-06-07 Setting the locale via the above no longer works
sudo qm set $VMID --cicustom "vendor=local:snippets/debian-13.yaml"
sudo qm set $VMID --tags debian-template,debian-13,cloudinit
sudo qm set $VMID --ciuser $USER
sudo qm set $VMID --sshkeys ~/.ssh/authorized_keys
sudo qm set $VMID --ipconfig0 ip=dhcp,ip6=dhcp
sudo qm template $VMID