Compare commits

..
7 Commits
10 changed files with 166 additions and 103 deletions

No files matched your search

Executable
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=5000
VM_NAME="AlmaLinux-9"
CPU_CORE=2
CPU_SOCKET=1
RAM=4096
DISK=30
IMAGE_URL="https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2"
PACKAGES=""
DOCKER=0
# Alma keeps root on partition 4 with XFS
GROW_CMD="growpart /dev/sda 4 && xfs_growfs /"
build_template
Regular → Executable
+9 -21
View File
@@ -1,26 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=9998 VM_ID=9998
VM_NAME="Debian-12-Large-Docker" VM_NAME="Debian-13-Large-Docker"
CPU_CORE=4 CPU_CORE=4
CPU_SOCKET=2 CPU_SOCKET=2
RAM=8192 RAM=8192
DISK=100 DISK=100
#getting latest image" IMAGE_URL="https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2"
wget https://cdimage.debian.org/images/cloud/bookworm/20250210-2019/debian-12-generic-amd64-20250210-2019.qcow2 PACKAGES=""
#installing qemu guest agent and remove HW ID DOCKER=1
virt-customize -a debian-12-generic-amd64-20250210-2019.qcow2 --install qemu-guest-agent,neofetch
virt-customize -a debian-12-generic-amd64-20250210-2019.qcow2 --run-command "curl -fsSL https://get.docker.com -o get-docker.sh build_template
sh get-docker.sh"
virt-customize -a debian-12-generic-amd64-20250210-2019.qcow2 --run-command "echo -n > /etc/machine-id"
qm create $VM_ID --name $VM_NAME --net0 virtio,bridge=vmbr0
qm set $VM_ID --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm importdisk "$VM_ID" debian-12-generic-amd64-20250210-2019.qcow2 local-lvm
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-"$VM_ID"-disk-0
qm set "$VM_ID" --ide2 local-lvm:cloudinit
qm set "$VM_ID" --boot c --bootdisk scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize $VM_ID scsi0 "$DISK"G
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
rm debian-12-generic-amd64-20250210-2019.qcow2 #clean iso
echo "Template er ferdig med id "$VM_ID""
+30
View File
@@ -37,6 +37,36 @@ qm set 200 --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub
## Legacy scripts ## Legacy scripts
`all.sh`, `Ubuntu-LTS-*.sh`, `Ubuntu-22-04-LTS.sh` and `Debian.sh` are the old fixed-size scripts (hard-coded storage `rust`/`local-lvm` and IDs). They are kept for reference. Use `install.sh` instead. `all.sh`, `Ubuntu-LTS-*.sh`, `Ubuntu-22-04-LTS.sh` and `Debian.sh` are the old fixed-size scripts (hard-coded storage `rust`/`local-lvm` and IDs). They are kept for reference. Use `install.sh` instead.
## Fixed templates (all.sh)
The older per-distro scripts are still here. `./all.sh` builds them all, or run one, e.g. `./Ubuntu-LTS-Small.sh`.
## Templates
| Script | VM ID | Docker |
|---|---|---|
| Ubuntu-LTS-Small.sh | 2000 | no |
| Ubuntu-LTS-Medium.sh | 3000 | yes |
| Ubuntu-LTS-Large.sh | 4000 | yes |
| Alma.sh (AlmaLinux 9, for FreeIPA) | 5000 | no |
| Debian.sh (Debian 13) | 9998 | yes |
| Ubuntu-22-04-LTS.sh | 9999 | yes |
Each script only sets its sizes and image; the build itself is in `lib.sh`. Set `DOCKER=0`
in a script to skip Docker. The image is cached in `/var/lib/vz/template/cloud` and each
script works on its own copy, so they can run in any order.
## Where the templates land
Defaults fit pvebox: storage `ssd`, network `vmbr1` (VM-Ekstern). Override per run:
```sh
STORAGE=tank BRIDGE=intern ./Ubuntu-LTS-Large.sh
```
A script stops if its VM ID already exists. Remove the old template first:
`qm destroy 2000 --purge`
<details> <details>
<summary>Source Doc </summary> <summary>Source Doc </summary>
Regular → Executable
+8 -20
View File
@@ -1,26 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=9999 VM_ID=9999
VM_NAME="Ubuntu-22-04-LTS-Large-Docker" VM_NAME="Ubuntu-22-04-LTS-Large-Docker"
CPU_CORE=4 CPU_CORE=4
CPU_SOCKET=2 CPU_SOCKET=2
RAM=8192 RAM=8192
DISK=100 DISK=100
#getting latest image" IMAGE_URL="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img PACKAGES="neofetch"
#installing qemu guest agent and remove HW ID DOCKER=1
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent,neofetch
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "curl -fsSL https://get.docker.com -o get-docker.sh build_template
sh get-docker.sh"
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"
qm create $VM_ID --name $VM_NAME --net0 virtio,bridge=vmbr0
qm set $VM_ID --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm importdisk "$VM_ID" jammy-server-cloudimg-amd64.img local-lvm
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-"$VM_ID"-disk-0
qm set "$VM_ID" --ide2 local-lvm:cloudinit
qm set "$VM_ID" --boot c --bootdisk scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize $VM_ID scsi0 "$DISK"G
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
rm jammy-server-cloudimg-amd64.img #clean iso
echo "Template er ferdig med id "$VM_ID""
Regular → Executable
+8 -20
View File
@@ -1,26 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=4000 VM_ID=4000
VM_NAME="Ubuntu-24-04-LTS-Large-Docker" VM_NAME="Ubuntu-24-04-LTS-Large-Docker"
CPU_CORE=4 CPU_CORE=4
CPU_SOCKET=2 CPU_SOCKET=2
RAM=8192 RAM=8192
DISK=100 DISK=100
#getting latest image" IMAGE_URL="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
#wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img PACKAGES=""
#installing qemu guest agent and remove HW ID DOCKER=1
virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a noble-server-cloudimg-amd64.img --run-command "curl -fsSL https://get.docker.com -o get-docker.sh build_template
sh get-docker.sh"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"
qm create $VM_ID --name $VM_NAME --net0 virtio,bridge=vmbr0
qm set $VM_ID --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm importdisk "$VM_ID" noble-server-cloudimg-amd64.img rust
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 rust:vm-"$VM_ID"-disk-0
qm set "$VM_ID" --ide2 rust:cloudinit
qm set "$VM_ID" --boot c --bootdisk scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize $VM_ID scsi0 "$DISK"G
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
rm noble-server-cloudimg-amd64.img clean iso
echo "Template er ferdig med id "$VM_ID""
Regular → Executable
+8 -20
View File
@@ -1,26 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=3000 VM_ID=3000
VM_NAME="Ubuntu-24-04-LTS-Medium-Docker" VM_NAME="Ubuntu-24-04-LTS-Medium-Docker"
CPU_CORE=2 CPU_CORE=2
CPU_SOCKET=2 CPU_SOCKET=2
RAM=4096 RAM=4096
DISK=50 DISK=50
#getting latest image" IMAGE_URL="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
#wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img PACKAGES=""
#installing qemu guest agent and remove HW ID DOCKER=1
virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a noble-server-cloudimg-amd64.img --run-command "curl -fsSL https://get.docker.com -o get-docker.sh build_template
sh get-docker.sh"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"
qm create $VM_ID --name $VM_NAME --net0 virtio,bridge=vmbr0
qm set $VM_ID --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm importdisk "$VM_ID" noble-server-cloudimg-amd64.img rust
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 rust:vm-"$VM_ID"-disk-0
qm set "$VM_ID" --ide2 rust:cloudinit
qm set "$VM_ID" --boot c --bootdisk scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize $VM_ID scsi0 "$DISK"G
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
#rm noble-server-cloudimg-amd64.img clean iso
echo "Template er ferdig med id "$VM_ID""
Regular → Executable
+8 -20
View File
@@ -1,26 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" && source ./lib.sh
VM_ID=2000 VM_ID=2000
VM_NAME="Ubuntu-24-04-LTS-Small" VM_NAME="Ubuntu-24-04-LTS-Small"
CPU_CORE=2 CPU_CORE=2
CPU_SOCKET=2 CPU_SOCKET=2
RAM=2048 RAM=2048
DISK=50 DISK=50
#getting latest image" IMAGE_URL="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img PACKAGES=""
#installing qemu guest agent and remove HW ID DOCKER=0
virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a noble-server-cloudimg-amd64.img --run-command "curl -fsSL https://get.docker.com -o get-docker.sh build_template
sh get-docker.sh"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"
qm create $VM_ID --name $VM_NAME --net0 virtio,bridge=vmbr0
qm set $VM_ID --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm importdisk "$VM_ID" noble-server-cloudimg-amd64.img rust
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 rust:vm-"$VM_ID"-disk-0
qm set "$VM_ID" --ide2 rust:cloudinit
qm set "$VM_ID" --boot c --bootdisk scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize $VM_ID scsi0 "$DISK"G
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
#rm noble-server-cloudimg-amd64.img clean iso
echo "Template er ferdig med id "$VM_ID""
Regular → Executable
+10 -1
View File
@@ -1 +1,10 @@
apt install -y libguestfs-tools && chmod +x Ubuntu-L* && chmod +x Debian.sh && ./Debian.sh && ./Ubuntu-LTS-Small.sh && ./Ubuntu-LTS-Medium.sh && ./Ubuntu-LTS-Large.sh #&& ./Ubuntu-22-04-LTS.sh #!/usr/bin/env bash
# Builds every template. Stops at the first failure.
set -e
cd "$(dirname "$0")"
./Debian.sh
./Alma.sh
./Ubuntu-LTS-Small.sh
./Ubuntu-LTS-Medium.sh
./Ubuntu-LTS-Large.sh
#./Ubuntu-22-04-LTS.sh
+10 -1
View File
@@ -267,10 +267,19 @@ print_summary() {
build_template() { build_template() {
local id=$1 name=$2 cores=$3 ram=$4 disk=$5 docker=$6 local id=$1 name=$2 cores=$3 ram=$4 disk=$5 docker=$6
local image="$WORKDIR/build-$id.img" local image="$WORKDIR/build-$id.img"
local -a customize=(--install qemu-guest-agent) # The cloud image's root filesystem is only ~2 GB, too small for Docker.
# Grow the image by 4 GB and the root partition with it before installing.
# Classic eth0/eth1 NIC names: Proxmox cloud-init configures eth0..ethN, and
# Ubuntu 26.04 brings NICs up in the initramfs, so cloud-init can't rename them
# later and static IPs never apply on first boot.
local -a customize=(--run-command 'growpart /dev/sda 1 && resize2fs /dev/sda1'
--install qemu-guest-agent
--write '/etc/default/grub.d/99-net-ifnames.cfg:GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT net.ifnames=0 biosdevname=0"'
--run-command 'update-grub')
info "[$id] Preparing image for $name" info "[$id] Preparing image for $name"
cp "$BASE_IMAGE" "$image" cp "$BASE_IMAGE" "$image"
qemu-img resize -q "$image" +4G
if [[ $docker == y ]]; then if [[ $docker == y ]]; then
customize+=(--run-command 'curl -fsSL https://get.docker.com | sh') customize+=(--run-command 'curl -fsSL https://get.docker.com | sh')
Executable
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Shared template builder. Each <distro>.sh sets the variables below and calls build_template.
#
# VM_ID VM_NAME CPU_CORE CPU_SOCKET RAM DISK - template hardware (DISK in GB)
# IMAGE_URL - cloud image to start from
# PACKAGES - extra apt packages, comma separated
# DOCKER=1 - install Docker from get.docker.com
# GROW_CMD - grows the root fs (default: ext4 on sda1)
#
# Override where it lands with environment variables:
# STORAGE=ssd BRIDGE=vmbr1 ./Ubuntu-LTS-Small.sh
set -euo pipefail
STORAGE="${STORAGE:-ssd}" # pvebox: ssd (SSD raidz1) or tank (SAS raidz1)
BRIDGE="${BRIDGE:-vmbr1}" # vmbr1 = VM-Ekstern (VLAN 4), intern = Proxmox NAT, vmbr0 = Lab
IMAGE_DIR="${IMAGE_DIR:-/var/lib/vz/template/cloud}"
build_template() {
if qm status "$VM_ID" >/dev/null 2>&1; then
echo "VM $VM_ID finnes allerede - slett den først: qm destroy $VM_ID --purge" >&2
exit 1
fi
command -v virt-customize >/dev/null || apt install -y libguestfs-tools
# Download once into a cache (only again when the image changed upstream);
# customize a copy so every script starts from a clean image.
mkdir -p "$IMAGE_DIR"
wget -q --show-progress -N -P "$IMAGE_DIR" "$IMAGE_URL"
local work; work=$(mktemp -d)
local disk="$work/disk.qcow2"
cp "$IMAGE_DIR/$(basename "$IMAGE_URL")" "$disk"
# The cloud image's root filesystem is only ~2 GB, too small for Docker.
# Grow the image by 4 GB and the root partition with it.
qemu-img resize -q "$disk" +4G
virt-customize -a "$disk" --run-command "${GROW_CMD:-growpart /dev/sda 1 && resize2fs /dev/sda1}"
# Guest agent, extra packages, optional Docker, and an empty machine-id so clones get their own DHCP lease
virt-customize -a "$disk" --install "qemu-guest-agent${PACKAGES:+,$PACKAGES}"
if [ "${DOCKER:-0}" = 1 ]; then
virt-customize -a "$disk" --run-command "curl -fsSL https://get.docker.com | sh"
fi
virt-customize -a "$disk" --truncate /etc/machine-id
# cpu host: AlmaLinux 9 needs x86-64-v2 and won't boot on the old kvm64 default
qm create "$VM_ID" --name "$VM_NAME" --cpu host --net0 "virtio,bridge=$BRIDGE"
qm set "$VM_ID" --cores "$CPU_CORE" --sockets "$CPU_SOCKET" --memory "$RAM"
qm set "$VM_ID" --scsihw virtio-scsi-pci --scsi0 "$STORAGE:0,import-from=$disk,discard=on"
qm set "$VM_ID" --ide2 "$STORAGE:cloudinit"
qm set "$VM_ID" --boot order=scsi0
qm set "$VM_ID" --serial0 socket --vga serial0
qm resize "$VM_ID" scsi0 "${DISK}G"
qm set "$VM_ID" --ipconfig0 ip=dhcp
qm set "$VM_ID" --agent enabled=1
qm template "$VM_ID"
rm -rf "$work"
echo "Template er ferdig med id $VM_ID ($VM_NAME) på $STORAGE, nett $BRIDGE"
}