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 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