Skip to content

Instantly share code, notes, and snippets.

@taking
Last active September 7, 2023 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taking/8851e39281e3484a899e12edbe945188 to your computer and use it in GitHub Desktop.
Save taking/8851e39281e3484a899e12edbe945188 to your computer and use it in GitHub Desktop.

How to Create Proxmox Ubuntu Cloud Image

Reference

Prerequisites

  • ubuntu focal(20.04) image

Prepare Cloud-init Templates

# ubuntu 20.04 cloudimg 
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img

# 새로운 VM 이미지 생성 (vmid, memory, network 등)
qm create 9000 --core=8 --memory 16384 --net0 virtio,bridge=vmbr0 --agent 1 --balloon 0

# 다운로드한 이미지를 local-lvm 저장소로 가져오기
qm importdisk 9000 focal-server-cloudimg-amd64.img local-lvm

# VM에 새 디스크를 SCSI 드라이브로 연결 (ubuntu 의 경우, virtio-scsi-pci 를 필요로 함)
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0

# cloudinit 데이터를 VM을 전송을 위해 ide2 CDROM 드라이브를 구성
qm set 9000 --ide2 local-lvm:cloudinit

# bootdisk 를 scsi0 로 설정하여, BIOS가 디스크에서만 부팅되도록 제한
qm set 9000 --boot c --bootdisk scsi0

# We also want to configure a serial console and use that as display. Many Cloud-Init images rely on that, because it is an requirement for OpenStack images.
qm set 9000 --serial0 socket --vga serial0

# 작업 이미지를 템플릿으로 변환
qm template 9000

Deploy Templates

# 템플릿을 클론하기
qm clone 9000 101 --name ubuntu-20.04

# SSH KEY 키 등록
qm set 101 --sshkey ~/.ssh/id_rsa.pub

# IP 주소 등록
qm set 101 --ipconfig0 ip=192.168.0.101/24,gw=192.168.0.1 --nameserver 8.8.8.8
# or qm set 101 --ipconfig0 ip=dhcp

# ID & PW 등록
qm set 101 --cipassword="somepassword" --ciuser=taking

# 디스크 사이즈 
qm resize 101 scsi0 +60G

(Option) Disk Pass-through

lsblk |awk 'NR==1{print $0" DEVICE-ID(S)"}NR>1{dev=$1;printf $0" ";system("find /dev/disk/by-id -lname \"*"dev"\" -printf \" %p\"");print "";}'|grep -v -E 'part|lvm'
qm set 100 --sata0 /dev/disk/by-id/{YOUR DISK ID}
@taking
Copy link
Author

taking commented Jun 19, 2022

(Option) Proxmox Performance
apt update
apt install irqbalance -y

@taking
Copy link
Author

taking commented Jun 20, 2022

(Option) More Sata 6, 7

  • edit /etc/pve/qemu-server/{VM_ID}.conf
args: -device ahci,id=ahci1,multifunction=on,bus=pci.0,addr=0xb -drive 'file=/dev/disk/by-id/usb-External_USB3.0_0000007788FC-0:2,if=none,id=drive-sata6,format=raw,aio=threads,detect-zeroes=unmap' -device ide-hd,bus=ahci1.0,drive=drive-sata6,id=sata6 -device ahci,id=ahci2,multifunction=on,bus=pci.0,addr=0xc -drive 'file=/dev/disk/by-id/nvme-SHGP31-1000GM-2_AJ08N85211060931H,if=none,id=drive-sata7,format=raw,aio=threads,detect-zeroes=unmap' -device ide-hd,bus=ahci1.1,drive=drive-sata7,id=sata7

101.conf

bios: ovmf
boot: order=sata0;sata1;net0
cores: 4
ide2: none,media=cdrom
memory: 16384
meta: creation-qemu=6.2.0,ctime=1655648772
name: xpenology
net0: vmxnet3=00:11:32:39:38:31,bridge=vmbr0,firewall=1
numa: 0
ostype: l26
sata0: local-lvm:vm-101-disk-1,size=1G
sata1: local-lvm:vm-101-disk-0,cache=writeback,size=102359808081
sata2: /dev/disk/by-id/wwn-0x50025385a02a099e,size=500107608K
sata3: /dev/disk/by-id/nvme-SHGP31-1000GM-2_AJ08N85211060931H
sata4: /dev/disk/by-id/usb-External_USB3.0_0000007788FC-0:0,size=3907018584K
sata5: /dev/disk/by-id/usb-External_USB3.0_0000007788FC-0:1,size=4883770584K
scsihw: virtio-scsi-pci
serial0: socket
smbios1: uuid=4f2dd9f0-336c-4775-805c-a58344f5049f
sockets: 2
vmgenid: 8855a6ee-03bc-4577-8e71-8f8a19afad0e
args: -device ahci,id=ahci1,multifunction=on,bus=pci.0,addr=0xb -drive 'file=/dev/disk/by-id/usb-External_USB3.0_0000007788FC-0:2,if=none,id=drive-sata6,format=raw,aio=threads,detect-zeroes=unmap' -device ide-hd,bus=ahci1.0,drive=drive-sata6,id=sata6 -device ahci,id=ahci2,multifunction=on,bus=pci.0,addr=0xc -drive 'file=/dev/disk/by-id/usb-External_USB3.0_0000007788FC-0:3,if=none,id=drive-sata7,format=raw,aio=threads,detect-zeroes=unmap' -device ide-hd,bus=ahci1.1,drive=drive-sata7,id=sata7

@taking
Copy link
Author

taking commented Jun 20, 2022

Status Unknown

systemctl restart pvedaemon
systemctl restart pvestatd
systemctl restart pveproxy
systemctl restart corosync
pvestatd restart

@taking
Copy link
Author

taking commented Dec 23, 2022

lsblk |awk 'NR==1{print $0" DEVICE-ID(S)"}NR>1{dev=$1;printf $0" ";system("find /dev/disk/by-id -lname \"*"dev"\" -printf \" %p\"");print "";}'|grep -v -E 'part|lvm'

CleanShot 2022-12-23 at 13 56 58@2x

@taking
Copy link
Author

taking commented Sep 7, 2023

newNum=300
ipAddr=105
disk=30

qm clone 9000 ${newNum} --name ubuntu-20.04
qm set ${newNum} --sshkey ~/.ssh/taking.pub
qm set ${newNum} --ipconfig0 ip=192.168.0.${ipAddr}/24,gw=192.168.0.1 --nameserver 8.8.8.8
qm set ${newNum} --cipassword="somepassword" --ciuser=taking
qm resize ${newNum}  scsi0 +${disk}G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment