Created
July 27, 2024 18:19
-
-
Save RSully/431cad726289d04bb3fa136dd8d360f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This documents how you would take a Debian 12 cloud image and make a Proxmox template out of it. | |
# This script isn't really meant to be executed, but more as a reference and copy/paste for each step. | |
# Enjoy! | |
# Download the image | |
mkdir -p ~/debian-bookworm-build/original && cd ~/debian-bookworm-build/original | |
wget 'https://cloud.debian.org/images/cloud/bookworm/20240717-1811/debian-12-genericcloud-amd64-20240717-1811.qcow2' | |
cd .. | |
# This is what the file systems in that image look like, for reference: | |
# | |
# $ virt-filesystems --long --parts --blkdevs -h -a debian-12-genericcloud-amd64-20240717-1811.qcow2 | |
# Name Type MBR Size Parent | |
# /dev/sda1 partition - 1.9G /dev/sda | |
# /dev/sda14 partition - 3.0M /dev/sda | |
# /dev/sda15 partition - 124M /dev/sda | |
# /dev/sda device - 2.0G - | |
# Resize the image, to give us more space to work with. | |
# The image is 2GB by default (seen above), but I'd like at least 8GB | |
qemu-img create -f qcow2 -o preallocation=metadata bookworm-cloudimg-amd64-8G.qcow2 8G | |
virt-resize --expand /dev/sda1 original/debian-12-genericcloud-amd64-20240717-1811.qcow2 bookworm-cloudimg-amd64-8G.qcow2 | |
# Setup the image | |
# This will do a few things... | |
# * Reinstall grub, required because virt-resize messes up the partitions and the image won't boot, see: | |
# https://bugzilla.redhat.com/show_bug.cgi?id=1472039 | |
# https://news.ycombinator.com/item?id=16304781 | |
# * Install cloud guest packages | |
# * Install the qemu guest agent (so Proxmox can communicate to the guest), and enable it. | |
# * And install a base layer of packages that I like... | |
# * cifs-utils are for connecting to my SMB file share | |
# * htop and tmux are nice to have | |
virt-customize -a bookworm-cloudimg-amd64-8G.qcow2 \ | |
--run-command 'grub-install /dev/sda' \ | |
--install cloud-guest-utils,cloud-initramfs-growroot \ | |
--install qemu-guest-agent \ | |
--run-command 'systemctl enable qemu-guest-agent' \ | |
--install cifs-utils,htop,tmux | |
# Re-shrink the image after we made our changes: | |
virt-sparsify --compress bookworm-cloudimg-amd64-8G.qcow2 bookworm-cloudimg-amd64-8G-small.qcow2 | |
rm bookworm-cloudimg-amd64-8G.qcow2 | |
# | |
# Now the image is ready to go, and we can add it to Proxmox as a template! | |
# | |
# *** From root user on the Proxmox host: *** | |
# | |
# Create the VM | |
qm create 9020 \ | |
--name 'Debian-12-20240717-ready' \ | |
--ostype l26 \ | |
--memory 2048 \ | |
--cores 2 \ | |
--net0 virtio,bridge=vmbr0 \ | |
--scsihw virtio-scsi-single \ | |
--agent enabled=1,fstrim_cloned_disks=1 | |
# Copy over image | |
qm set 9020 --scsi0 local-vmdata:0,import-from=/home/ryan/debian-bookworm-build/bookworm-cloudimg-amd64-8G-small.qcow2 | |
# Start configuring cloud-init data | |
qm set 9020 --ide2 local-vmdata:cloudinit --boot order=scsi0 --serial0 socket --vga serial0 | |
# Convert VM to template to begin using | |
qm template 9020 | |
# Now you can clone it from the Proxmox web UI and make VMs :) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment