Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cdseoo/05ba75a95903a0518637868daf9c8c35 to your computer and use it in GitHub Desktop.
Save cdseoo/05ba75a95903a0518637868daf9c8c35 to your computer and use it in GitHub Desktop.

Revisions

  1. @Jimmy-Z Jimmy-Z revised this gist Mar 1, 2023. 1 changed file with 11 additions and 21 deletions.
    32 changes: 11 additions & 21 deletions pve-cloud-init-template-debian.sh
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,21 @@
    #!/bin/sh

    # apt install parted
    # apt install curl

    # obviously change this per your needs
    VMID=9000
    DEB_OS_IMG=debian-10.3.2-20200406-openstack-amd64.qcow2
    DISK=/dev/mapper/pve-vm--$VMID--disk--0
    VMID=9001
    STOR=local-lvm
    VER=20230124-1270
    URL_PATH=https://cloud.debian.org/images/cloud/bullseye/$VER/
    IMG=debian-11-genericcloud-amd64-$VER.qcow2

    wget -c https://cloud.debian.org/images/cloud/OpenStack/current/$DEB_OS_IMG
    curl -L -o $IMG -C - $URL_PATH$IMG
    # https://pve.proxmox.com/wiki/Cloud-Init_Support
    # https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines
    qm create $VMID --cores 4 --cpu cputype=host --memory 4096 --net0 virtio,bridge=vmbr0 --ostype l26 --serial0 socket --vga serial0
    qm importdisk $VMID $DEB_OS_IMG local-lvm
    qm set $VMID --scsihw virtio-scsi-single --scsi0 local-lvm:vm-$VMID-disk-0,discard=on,iothread=true
    qm set $VMID --ide2 local-lvm:cloudinit
    qm importdisk $VMID $IMG $STOR
    qm set $VMID --scsihw virtio-scsi-single --scsi0 $STOR:vm-$VMID-disk-0,discard=on,iothread=true
    qm set $VMID --ide2 $STOR:cloudinit
    qm set $VMID --boot c --bootdisk scsi0

    # https://pve.proxmox.com/wiki/Resize_disks
    qm resize $VMID scsi0 20G
    fdisk -l $DISK
    parted --script $DISK 'resizepart 1 100%'
    fdisk -l $DISK
    e2fsck -yf ${DISK}p1
    resize2fs ${DISK}p1

    # http://blog.roberthallam.org/2017/12/solved-logical-volume-is-used-by-another-device/
    sync
    dmsetup remove ${DISK}p1

    qm template $VMID
    qm template $VMID
  2. @Jimmy-Z Jimmy-Z created this gist Apr 23, 2020.
    31 changes: 31 additions & 0 deletions pve-cloud-init-template-debian.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/sh

    # apt install parted

    # obviously change this per your needs
    VMID=9000
    DEB_OS_IMG=debian-10.3.2-20200406-openstack-amd64.qcow2
    DISK=/dev/mapper/pve-vm--$VMID--disk--0

    wget -c https://cloud.debian.org/images/cloud/OpenStack/current/$DEB_OS_IMG
    # https://pve.proxmox.com/wiki/Cloud-Init_Support
    # https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines
    qm create $VMID --cores 4 --cpu cputype=host --memory 4096 --net0 virtio,bridge=vmbr0 --ostype l26 --serial0 socket --vga serial0
    qm importdisk $VMID $DEB_OS_IMG local-lvm
    qm set $VMID --scsihw virtio-scsi-single --scsi0 local-lvm:vm-$VMID-disk-0,discard=on,iothread=true
    qm set $VMID --ide2 local-lvm:cloudinit
    qm set $VMID --boot c --bootdisk scsi0

    # https://pve.proxmox.com/wiki/Resize_disks
    qm resize $VMID scsi0 20G
    fdisk -l $DISK
    parted --script $DISK 'resizepart 1 100%'
    fdisk -l $DISK
    e2fsck -yf ${DISK}p1
    resize2fs ${DISK}p1

    # http://blog.roberthallam.org/2017/12/solved-logical-volume-is-used-by-another-device/
    sync
    dmsetup remove ${DISK}p1

    qm template $VMID