ProxMox Qemu create Ubuntu template

Запись создана 5 апреля, 2024

wget https://cloud-images.ubuntu.com/releases/jammy/release/ubuntu-22.04-server-cloudimg-amd64.img
mv ubuntu-22.04-server-cloudimg-amd64.img ubuntu-22.04-server-cloudimg-amd64.qcow2
qemu-img resize ubuntu-22.04-server-cloudimg-amd64.qcow2 10G
 
qm create  9000 \
--name ubuntu22 \
--bootdisk virtio0 \
--ostype l26 \
--sockets 1  \
--cores 2 \
--memory 1024 \
--scsihw virtio-scsi-single \
--onboot yes \
--serial0 socket \
--vga serial0 \
--net0 virtio,bridge=vmbr0 \
--agent 1 \
--ide2 local-zfs:cloudinit \
--virtio0 local-zfs:0,import-from=/root/ubuntu-22.04-server-cloudimg-amd64.qcow2
 
qm set 9000 --ipconfig0 ip=dhcp

Enable snippets store on ProxMox:

pvesm set local --content images,rootdir,vztmpl,backup,iso,snippets
cat > /var/lib/vz/snippets/9000.yaml << EOF
#cloud-config
preserve_hostname: true

users:
  - default
  - name: shakirov
    gecos: Artur Shakirov
    shell: /bin/bash
    groups: sudo
    sudo: ALL=(ALL) NOPASSWD:ALL
    passwd: $PASSWORD_HASH_TAKE_IT_FROM_YOUR_/etc/shadow_
    lock_passwd: false
    ssh_authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5o74MtkmdOjSIvqvV+z0vtB65KE2EHLk8FGWqIqOxVg2nAvHNKS7Zy255c+mAWOS+sEJUsZMFlxaIsqS7f1nf/3TMftlnlRH3WNdoh2QP7lsEccpRrPymhD7+ZkouC0FosqciGEKGo0sGXnnyLnNajYp01UHmgsALH5vEsK9xXeiTtinvEDanI4QrI9U4bCoIEGboKeQPhvk7355x7hV05RBpq3fud/No+rbiD9PZxUQCI/l1H6GWtLbWE/LaGxS1CmBb1Rw3Ea5agJ5yX24F+Ey19CnKk8WsW649AI4HO4QdTKE7zwIEWW46ONIAEnpV0LkYmJbfBUCaKo/8g6I3
      - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQ187Jo6t/Wxxgs73NnEWc+OGebbruOY/DfmxemFX2C shakirov@shakirov
 
write_files:
  - path: /etc/sudoers.d/cloud-init
    content: |
      Defaults !requiretty
 
package_update: true
package_upgrade: true
packages:
  - qemu-guest-agent
  - pwgen
  - nmap
  - htop
  - iftop
 
runcmd:
  - sed -i -e 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
  - sed -i -e 's/^PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
  - [ systemctl, enable, qemu-guest-agent ]
  - [ systemctl, start, qemu-guest-agent ]
EOF

Apply Cloud-init to VM

qm set 9000  --cicustom "user=local:snippets/9000.yaml"

Now we have imported cloud image and can prepare it. At this stage you can customize somehow your image

qm start 9000 && qm terminal 9000
sudo -i
cat /dev/null > /etc/machine-id
cloud-init clean
history -c
shutdown -h now

Convert our VM to template

qm template 9000

And now we can create a VM from template:

qm clone 9000 107 --full --name mgmt

» Запись из раздела Proxmox VE | Комментировать

Комментарии





Ответить