Last active
April 18, 2025 22:55
-
-
Save si458/98aa940837784e9ef9bff9e24a7a8bfd to your computer and use it in GitHub Desktop.
virt-customize ubuntu22
This file contains hidden or 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
#!/bin/sh | |
# install tools | |
apt update -y && apt install nano wget curl libguestfs-tools -y | |
# remove old image | |
rm -rfv current/noble-server-cloudimg-amd64.img | |
# remove old template container - WILL DESTROY COMPLETELY | |
qm destroy 9000 --destroy-unreferenced-disks 1 --purge 1 | |
# download new image | |
wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img | |
# add agent to image | |
virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent,cloud-init | |
# set timezone | |
virt-customize -a noble-server-cloudimg-amd64.img --timezone Europe/London | |
# set password auth to yes | |
virt-customize -a noble-server-cloudimg-amd64.img --run-command 'sed -i s/^PasswordAuthentication.*/PasswordAuthentication\ yes/ /etc/ssh/sshd_config' | |
# allow root login with ssh-key only | |
virt-customize -a noble-server-cloudimg-amd64.img --run-command 'sed -i s/^#PermitRootLogin.*/PermitRootLogin\ prohibit-password/ /etc/ssh/sshd_config' | |
# increase image to 16GB | |
qemu-img resize noble-server-cloudimg-amd64.img 16G | |
# create VM | |
qm create 9000 --name "ubuntu-2404-template" --memory 4096 --cores 2 --net0 virtio,bridge=vmbr0,firewall=1 --bios ovmf --agent enabled=1 --efidisk0 local:9000,efitype=4m --ostype l26 --serial0 socket --vga serial0 --machine q35 --scsi1 local:cloudinit --scsihw virtio-scsi-pci | |
# import image to VM | |
qm importdisk 9000 noble-server-cloudimg-amd64.img local | |
# add disk to VM | |
qm set 9000 --scsi0 local:vm-9000-disk-1.raw | |
# set bootdisk to image | |
qm set 9000 --boot c --bootdisk scsi0 | |
# convert to template | |
qm template 9000 | |
# remove new template | |
rm -rfv noble-server-cloudimg-amd64.img |
now that is a thing of beauty. Thanks
fyi
https://github.com/maxfield-allison/scripts/blob/main/ubuntu-template-create.sh
Thanks bro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now that is a thing of beauty.
Thanks