-
-
Save reluce/797515dc8b906eb07f54393a119df9a7 to your computer and use it in GitHub Desktop.
# All commands will be executed on a Proxmox host | |
sudo apt update -y && sudo 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. | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent | |
# Read and set root user password from file. | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --root-password file:password_root.txt | |
# Create an additional user. | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --run-command "useradd -m -s /bin/bash myuser" | |
# Set password for that user. | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --password myuser:file:password_myuser.txt | |
# Delete temporary password files safely. | |
shred -uv password_root.txt password_myuser.txt | |
# Optional: Install fish shell. | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --run-command "apt-add-repository ppa:fish-shell/release-3 --yes" | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --install fish | |
sudo virt-customize -a jammy-server-cloudimg-amd64.img --run-command "chsh -s /usr/bin/fish myuser" | |
# Finally, update all packages in the image. | |
sudo 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. | |
sudo qm create 777 --name "ubuntu-20.04-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0 | |
sudo qm importdisk 777 jammy-server-cloudimg-amd64.img zfs | |
sudo qm set 777 --scsihw virtio-scsi-pci --scsi0 zfs:vm-777-disk-0 | |
sudo qm set 777 --boot c --bootdisk scsi0 | |
sudo qm set 777 --ide2 zfs:cloudinit | |
sudo qm set 777 --serial0 socket --vga serial0 | |
sudo qm set 777 --agent enabled=1 | |
sudo qm template 777 | |
# 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. |
Thanks, I'll copy it ! (I'll give credit to you, ofc)
Maybe append sudo virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
with --run-command 'systemctl enable qemu-guest-agent.service'
Maybe append
sudo virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
with--run-command 'systemctl enable qemu-guest-agent.service'
isnt the agent enabled by line 29?
sudo qm set 777 --agent enabled=1
isnt the agent enabled by line 29?
sudo qm set 777 --agent enabled=1
I believe this just turns the option on in Proxmox and has no impact inside inside the image.
Usually (at least in Ubuntu) the service gets enabled automatically, so you don't have to enable it manually.
isnt the agent enabled by line 29?
sudo qm set 777 --agent enabled=1
I believe this just turns the option on in Proxmox and has no impact inside inside the image. Usually (at least in Ubuntu) the service gets enabled automatically, so you don't have to enable it manually.
Looks like you are right, it is just the Proxmox side of things. I couldn't find any docs on Ubuntu starting it up automatically but that is my lived experience with it. Cheers I learnt something new.
from: https://pve.proxmox.com/pve-docs/qm.1.html
--agent [enabled=]<1|0> [,freeze-fs-on-backup=<1|0>] [,fstrim_cloned_disks=<1|0>] [,type=<virtio|isa>]
Enable/disable communication with the QEMU Guest Agent and its properties.
This is awesome. Thanks!