Skip to content

Instantly share code, notes, and snippets.

@Aabayoumy
Last active May 4, 2023 12:08
Show Gist options
  • Save Aabayoumy/7914a7964563f0b844b87006178071fb to your computer and use it in GitHub Desktop.
Save Aabayoumy/7914a7964563f0b844b87006178071fb to your computer and use it in GitHub Desktop.
jammy-server-cloudimg-amd64 template on ProxMox
# based on https://gist.github.com/reluce/797515dc8b906eb07f54393a119df9a7
# https://techbythenerd.com/posts/creating-an-ubuntu-cloud-image-in-proxmox/
# All commands will be executed on a Proxmox host
apt update -y && apt install libguestfs-tools -y
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
# Install qemu-guest-agent on the image. Additional packages can be specified by separating with a comma.
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent,neovim,tmux,exa,git
# Read and set root user password from file.
virt-customize -a jammy-server-cloudimg-amd64.img --root-password file:password_root.txt
# Create an additional user.
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "useradd -m -s /bin/bash abayoumy"
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "usermod -aG sudo abayoumy"
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "echo 'abayoumy ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
# Set password for that user.
virt-customize -a jammy-server-cloudimg-amd64.img --password abayoumy:file:password_abayoumy.txt
# Delete temporary password files safely.
shred -uv password_root.txt password_abayoumy.txt
# Optional: Install fish shell.
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "apt-add-repository ppa:fish-shell/release-3 --yes"
virt-customize -a jammy-server-cloudimg-amd64.img --install fish
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "chsh -s /usr/bin/fish abayoumy"
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "dpkg --configure -a"
virt-customize -a jammy-server-cloudimg-amd64.img --timezone "Africa/Cairo"
virt-customize -a jammy-server-cloudimg-amd64.img --ssh-inject abayoumy:file:id_rsa.pub
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "echo nameserver 8.8.8.8 >> /etc/resolv.conf"
#----
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "snap install starship --edge"
#---
# Finally, update all packages in the image.
virt-customize -a jammy-server-cloudimg-amd64.img --update
# Next, we create a Proxmox VM template.
# Change values for your bridge and storage and change defaults to your liking.
qm create 980 --name "ubuntu-22.04-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
qm importdisk 980 jammy-server-cloudimg-amd64.img local-lvm
qm set 980 --scsihw virtio-scsi-pci --scsi0 local-lvm:980/vm-980-disk-0.raw
qm resize 980 scsi0 20G
qm set 980 --boot c --bootdisk scsi0
qm set 980 --ide2 local-lvm:cloudinit
qm set 980 --serial0 socket --vga serial0
qm set 980 --agent enabled=1
qm template 980
# Now we can create new VMs by cloning this template or reference it with Terraform Proxmox etc.
# Login with SSH only possible with user "ubuntu" and SSH keys specified in cloudinit image.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment