forked from balthild/pve-import-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.yaml
More file actions
369 lines (331 loc) · 12.1 KB
/
templates.yaml
File metadata and controls
369 lines (331 loc) · 12.1 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
aliases:
- &command_permit_root_login >-
if grep -E '^PermitRootLogin\s' /etc/ssh/sshd_config >/dev/null 2>&1;
then sed -i -E 's/^(PermitRootLogin\s.*)+$/PermitRootLogin yes # \1/' /etc/ssh/sshd_config;
else printf "\nPermitRootLogin yes\n" >> /etc/ssh/sshd_config;
fi
- &command_install_qga |
#!/bin/sh
# 安装并启用 qemu-guest-agent(适配 Debian/Ubuntu EOL、RHEL/CentOS、openSUSE、Arch)
# 目标:即使装不到也不会让 virt-customize 失败;最后必须 exit 0
set -u
ok=0
fix_debian_eol_sources() {
# 切到 archive.debian.org,并关闭 Valid-Until 校验
mkdir -p /etc/apt/apt.conf.d || true
printf 'Acquire::Check-Valid-Until "false";\n' > /etc/apt/apt.conf.d/99ignore-valid-until || true
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
[ -f "$f" ] || continue
sed -i -E 's@https?://deb\.debian\.org/debian@http://archive.debian.org/debian@g' "$f" || true
sed -i -E 's@https?://security\.debian\.org/debian-security@http://archive.debian.org/debian-security@g' "$f" || true
sed -i -E '/stretch-updates/d' "$f" || true
done
}
fix_ubuntu_eol_sources() {
# Ubuntu EOL → old-releases.ubuntu.com
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
[ -f "$f" ] || continue
sed -i -E 's@https?://([a-z0-9.-]+\.)?ubuntu\.com/?ubuntu@http://old-releases.ubuntu.com/ubuntu@g' "$f" || true
sed -i -E 's@https?://security\.ubuntu\.com/ubuntu@http://old-releases.ubuntu.com/ubuntu@g' "$f" || true
done
}
enable_systemd_wants_link() {
# 不跑 systemctl;仅放 wants 链接,首启自然拉起
mkdir -p /etc/systemd/system/multi-user.target.wants || true
if [ -e /lib/systemd/system/qemu-guest-agent.service ]; then
ln -sf /lib/systemd/system/qemu-guest-agent.service \
/etc/systemd/system/multi-user.target.wants/qemu-guest-agent.service || true
elif [ -e /usr/lib/systemd/system/qemu-guest-agent.service ]; then
ln -sf /usr/lib/systemd/system/qemu-guest-agent.service \
/etc/systemd/system/multi-user.target.wants/qemu-guest-agent.service || true
fi
}
# --- APT 系(Debian/Ubuntu) ---
if command -v apt-get >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
. /etc/os-release 2>/dev/null || true
low_id="$(printf '%s' "${ID:-}" | tr '[:upper:]' '[:lower:]')"
case ",$low_id," in
*,debian,*) fix_debian_eol_sources ;;
*,ubuntu,*) fix_ubuntu_eol_sources ;;
*) : ;;
esac
apt-get -o Acquire::Check-Valid-Until=false update || true
if apt-get install -y --no-install-recommends qemu-guest-agent; then
ok=1
fi
enable_systemd_wants_link
fi
# --- DNF / YUM 系(RHEL/CentOS/Alma/Rocky 等) ---
if [ "$ok" -eq 0 ] && command -v dnf >/dev/null 2>&1; then
dnf -y install qemu-guest-agent && ok=1 || true
enable_systemd_wants_link
fi
if [ "$ok" -eq 0 ] && command -v yum >/dev/null 2>&1; then
yum -y install qemu-guest-agent && ok=1 || true
enable_systemd_wants_link
fi
if [ "$ok" -eq 0 ] && command -v microdnf >/dev/null 2>&1; then
microdnf -y install qemu-guest-agent && ok=1 || true
enable_systemd_wants_link
fi
# --- openSUSE ---
if [ "$ok" -eq 0 ] && command -v zypper >/dev/null 2>&1; then
zypper --non-interactive install -y qemu-guest-agent && ok=1 || true
enable_systemd_wants_link
fi
# --- Arch ---
if [ "$ok" -eq 0 ] && command -v pacman >/dev/null 2>&1; then
pacman -Sy --noconfirm qemu-guest-agent && ok=1 || true
enable_systemd_wants_link
fi
if [ "$ok" -eq 0 ]; then
echo "[WARN] qemu-guest-agent not installed (pkg manager absent or repos unavailable). Skipping." >&2
fi
exit 0
- &command_enable_bbr_optimized >-
set -eux
echo tcp_bbr >/etc/modules-load.d/bbr.conf
cat > /etc/sysctl.d/99-network-tuning.conf << "EOF"
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
EOF
# 镜像源配置 - 用于内网环境
# 使用方法:python3 import.py local-lvm 900 --mirror aliyun
mirrors:
# 阿里云镜像源
aliyun:
ubuntu:
url: http://mirrors.aliyun.com/ubuntu
debian:
url: http://mirrors.aliyun.com/debian
rhel:
url: http://mirrors.aliyun.com/centos
alpine:
url: http://mirrors.aliyun.com/alpine
arch:
url: http://mirrors.aliyun.com/archlinux
# 清华大学镜像源
tsinghua:
ubuntu:
url: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
debian:
url: https://mirrors.tuna.tsinghua.edu.cn/debian
rhel:
url: https://mirrors.tuna.tsinghua.edu.cn/centos
alpine:
url: https://mirrors.tuna.tsinghua.edu.cn/alpine
arch:
url: https://mirrors.tuna.tsinghua.edu.cn/archlinux
# 华为云镜像源
huawei:
ubuntu:
url: https://repo.huaweicloud.com/ubuntu
debian:
url: https://repo.huaweicloud.com/debian
rhel:
url: https://repo.huaweicloud.com/centos
alpine:
url: https://repo.huaweicloud.com/alpine
arch:
url: https://repo.huaweicloud.com/archlinux
# 腾讯云镜像源
tencent:
ubuntu:
url: http://mirrors.cloud.tencent.com/ubuntu
debian:
url: http://mirrors.cloud.tencent.com/debian
rhel:
url: http://mirrors.cloud.tencent.com/centos
alpine:
url: http://mirrors.cloud.tencent.com/alpine
arch:
url: http://mirrors.cloud.tencent.com/archlinux
# 中科大镜像源
ustc:
ubuntu:
url: https://mirrors.ustc.edu.cn/ubuntu
debian:
url: https://mirrors.ustc.edu.cn/debian
rhel:
url: https://mirrors.ustc.edu.cn/centos
alpine:
url: https://mirrors.ustc.edu.cn/alpine
arch:
url: https://mirrors.ustc.edu.cn/archlinux
# 内网示例 - 可自定义为您的内网镜像服务器
# internal:
# ubuntu:
# url: http://your-internal-mirror.local/ubuntu
# debian:
# url: http://your-internal-mirror.local/debian
# rhel:
# url: http://your-internal-mirror.local/centos
templates:
- name: ubuntu-18.04
url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: ubuntu-20.04
url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: ubuntu-22.04
url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: ubuntu-24.04
url: https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: debian-10
url: https://cloud.debian.org/images/openstack/current-10/debian-10-openstack-amd64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: debian-11
url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: debian-12
url: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: debian-13
url: https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- *command_enable_bbr_optimized
- name: centos-stream-8
url: https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: centos-stream-9
url: https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: centos-stream-10
url: https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: archLinux
url: https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: alpineLinux-3.22
url: https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/generic_alpine-3.22.1-x86_64-bios-cloudinit-r0.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
- ./uploads/resolv.conf:/etc/resolv.conf
commands:
- *command_permit_root_login # apk 未覆盖,暂不尝试安装 qga
- name: alpineLinux-3.23
url: https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/cloud/generic_alpine-3.23.2-x86_64-bios-cloudinit-r0.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
- ./uploads/resolv.conf:/etc/resolv.conf
commands:
- *command_permit_root_login # apk 未覆盖,暂不尝试安装 qga
- name: almaLinux-8
url: https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: almaLinux-9
url: https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga
- name: almaLinux-10
url: https://repo.almalinux.org/almalinux/10/cloud/x86_64/images/AlmaLinux-10-GenericCloud-latest.x86_64.qcow2
cloud_init: true
customize:
uploads:
- ./uploads/ssh.cfg:/etc/cloud/cloud.cfg.d/50_ssh.cfg
commands:
- *command_permit_root_login
- *command_install_qga