55 lines
2.1 KiB
Bash
Executable File
55 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# https://wiki.k-space.ee/en/hosting/proxmox
|
|
# image does not come from debian, but whole thing probably replaced with self-service thing anyway
|
|
|
|
if [[ "$#" -ne 2 ]]; then
|
|
echo "ERROR: expected exactly 2 arguments"
|
|
echo "USAGE: $0 <storage> <vmid>"
|
|
exit 1
|
|
fi
|
|
storage="$1"
|
|
vmid="$2"
|
|
img=debian-13
|
|
ident=d13.v2
|
|
size=100G
|
|
|
|
# will error if vmid exists
|
|
qm create "$vmid" \
|
|
--cpu x86-64-v3 --numa 1 \
|
|
--cores 16 --vcpus 8 \
|
|
--memory 4096 \
|
|
--scsihw virtio-scsi-pci \
|
|
--ide0 none,media=cdrom --ide2 "$storage":cloudinit,format=raw \
|
|
--boot order='ide0;scsi0' \
|
|
--serial0 socket --vga serial0 \
|
|
--net0 virtio,bridge=vmbr0 \
|
|
--ipconfig0 ip='193.40.103.99/24',gw='193.40.103.1',ip6='2001:bb8:4008:20::99/64',gw6='2001:bb8:4008:20::1' \
|
|
--searchdomain zoo.k-space.ee --nameserver '1.1.1.1 8.8.8.8' \
|
|
--ostype l26 --hotplug disk,network,usb,memory,cpu --onboot 1 \
|
|
--agent 1,fstrim_cloned_disks=1 \
|
|
--name "$ident.$HOSTNAME" --description "https://wiki.k-space.ee/en/hosting/proxmox"$'\n\n'"Base template: $ident"$'\n\n'"User: UNDOCUMENTED"
|
|
|
|
# Whole script supposed to be replaced by self-service suite anyway.
|
|
#TODO: virt-builder version is crap, replacing it with drop-in:
|
|
wget 'https://cdimage.debian.org/images/cloud/bookworm/latest/debian-13-genericcloud-amd64.raw' -O "$img".img
|
|
|
|
function cleanup {
|
|
rm "$img".img
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
virt-customize -a "$img".img \
|
|
--root-password disabled \
|
|
--install qemu-guest-agent,sshguard \
|
|
--run-command 'unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections' \
|
|
--run-command 'dpkg-reconfigure -f noninteractive unattended-upgrades' \
|
|
--append-line '/lib/udev/rules.d/80-hotplug-cpu-mem.rules:SUBSYSTEM=="cpu", ACTION=="add", TEST=="online", ATTR{online}=="0", ATTR{online}="1"' \
|
|
--append-line '/lib/udev/rules.d/80-hotplug-cpu-mem.rules:SUBSYSTEM=="memory", ACTION=="add", TEST=="state", ATTR{state}=="offline", ATTR{state}="online"'
|
|
|
|
qm set "$vmid" --scsi0 "$storage":0,import-from="$PWD/$img.img",discard=on,ssd=1
|
|
qm disk resize "$vmid" scsi0 "$size"
|
|
|
|
qm template "$vmid"
|