Wiki source code of proxmox

Version 11.5 by Kevin Wiki on 2026/05/18 15:40

Show last authors
1 (% class="row" %)
2 (((
3 (% class="col-xs-12 col-sm-8" %)
4 (((
5 {{children/}}
6
7
8 = Getting Started with Proxmox VE LXC and VM Templates =
9
10 Proxmox VE (PVE) allows users to create and manage both LXC containers and KVM virtual machines (VMs). This guide walks you through the process of downloading, importing, and creating templates for both.
11
12 == LXC Templates ==
13
14 LXC containers are lightweight and ideal for running Linux services with minimal overhead.
15
16 === List Available Templates ===
17
18 To view the available LXC templates:
19
20 {{code language="bash"}}
21 pveam list
22 {{/code}}
23
24 === Download Templates ===
25
26 Use the pveam download command to import templates to the local storage:
27
28 {{code language="bash"}}
29 pveam download local ubuntu-22.04-standard_22.04-1_amd64.tar.gz
30 pveam download local ubuntu-24.04-standard_24.04-1_amd64.tar.zst
31 pveam download local debian-12-standard_11.7-1_amd64.tar.zst
32 {{/code}}
33
34 Once downloaded, these templates can be used to create new LXC containers from the Proxmox web interface or via CLI.
35
36 == VM Template from Ubuntu Cloud Image ==
37
38 KVM VMs are ideal when you need full virtualization, for instance, to run Windows or more complex Linux systems.
39
40 === Download Ubuntu Cloud Image ===
41
42 Download the official Ubuntu 24.04 cloud [[image:]]
43
44 {{code language="bash"}}
45 wget http://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img
46 {{/code}}
47
48 === Create the Virtual Machine ===
49
50 Create a new VM with ID 910 (you can pick any unused ID):
51
52 {{code language="bash"}}
53 qm create 910 -name template-ubuntu-jammy -memory 2048 -net0 virtio,bridge=vmbr0 -cores 2 -sockets 1
54 {{/code}}
55
56 === Import and Attach the Disk ===
57
58 Choose the correct storage (replace nvme if you use a different storage name):
59
60 {{code language="bash"}}
61 qm importdisk 910 ubuntu-24.04-server-cloudimg-amd64.img nvme
62 qm set 910 -scsihw virtio-scsi-pci -virtio0 nvme:vm-910-disk-0
63 {{/code}}
64
65 === Configure the VM ===
66
67 {{code language="bash"}}
68 qm set 910 -serial0 socket
69 qm set 910 -boot c -bootdisk virtio0
70 qm set 910 -agent 1
71 qm set 910 -hotplug disk,network,usb
72 qm set 910 -vcpus 1
73 qm set 910 -vga qxl
74 qm set 910 -ide2 nvme:cloudinit
75 qm resize 910 virtio0 +8G
76 {{/code}}
77
78
79 If your disk is using SCSI instead of virtio, resize like this:
80
81 {{code language="bash"}}
82 qm resize 910 scsi0 +8G
83 {{/code}}
84
85 === Convert the VM into a Template ===
86
87 {{code language="bash"}}
88 qm template 910
89 {{/code}}
90
91 Now you can use this template to clone new VMs instantly.
92
93 == Bash Script to Automate Setup ==
94
95 Install the above using bash script below
96
97 === setup_proxmox_templates.sh ===
98
99 {{code language="bash"}}
100 #!/bin/bash
101
102 # Exit on errors
103 set -e
104
105 echo "Downloading LXC templates..."
106 pveam download nvme ubuntu-22.04-standard_22.04-1_amd64.tar.zst
107 pveam download nvme ubuntu-24.04-standard_24.04-2_amd64.tar.zst
108 pveam download nvme alpine-3.21-default_20241217_amd64.tar.xz
109 pveam download nvme debian-12-standard_12.7-1_amd64.tar.zst
110
111 echo "Downloading Ubuntu cloud image..."
112 wget -N http://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img
113
114 echo "Creating VM Template..."
115 qm create 910 -name template-ubuntu-jammy -memory 2048 -net0 virtio,bridge=vmbr0 -cores 2 -sockets 1 && 1
116
117 # qm importdisk 910 ubuntu-24.04-server-cloudimg-amd64.img nvme
118 # qm set 910 -scsihw virtio-scsi-pci -scsi0-virtio0 nvme:910/vm-910-disk-0
119 qm set 910 -scsihw virtio-scsi-pci -scsi0 nvme:0,import-from=/mnt/nvmestorage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img
120
121 qm set 910 -serial0 socket
122 qm set 910 -boot c -bootdisk virtio0
123 qm set 910 -agent 1
124 qm set 910 -hotplug disk,network,usb
125 qm set 910 -vcpus 1
126 qm set 910 -vga qxl
127 qm set 910 -ide2 nvme:cloudinit
128 # qm resize 910 scsi0 +8G
129
130 read -p "Confirm converting to template by pressing Enter"
131 qm template 910
132
133 echo "Templates setup complete."
134 {{/code}}
135
136
137 = VM runtime setup =
138
139 After creating the VM and before making it into a template there are some programs and settings we want to ensure exists always.
140
141 (% id="cke_bm_721114S" style="display:none" %)** **(%%)**clear bash history** to not leave any configuration in history, clear and disable history file before proceeding:
142
143 {{code language="bash"}}
144 unset HISTFILE
145 export HISTSIZE=0
146 export HISTFILESIZE=0
147
148 sudo rm /.bash_history
149 rm ~/.bash_history
150 {{/code}}
151
152 **qemu-guest-agent** is for allowing proxmox to query information from the VM such as IP address, shutdown commands, etc
153
154 {{code language="bash"}}
155 sudo apt update
156 sudo apt upgrade -y
157 sudo apt install qemu-guest-agent -y
158
159 sudo systemctl enable qemu-guest-agent.service
160 sudo systemctl start qemu-guest-agent.service
161 {{/code}}
162
163 **reset machine-id** to not have overlapping ids from same template
164
165 {{code language="bash"}}
166 cat /dev/null > /etc/machine-id
167 cat /dev/null > /var/lib/dbus/machine-id
168 {{/code}}
169
170 **cloud-init** is a great hook for installing or configuring programs or receiving variables from cloudinit CDROM drive. Making it easier to change IP, hostname, DNS, username/password, etc between VMs.
171
172 If you used a cloud-init base image it will have run the default cloudinit which installs and configures a bunch of s
173
174 {{code language="bash"}}
175 cloud-init clean
176 {{/code}}
177
178 This is a debian example of what we are looking for:
179
180 {{code language="yaml"}}
181 # The top level settings are used as module
182 # and system configuration.
183 # A set of users which may be applied and/or used by various modules
184 # when a 'default' entry is found it will reference the 'default_user'
185 # from the distro configuration specified below
186
187 # If this is set, 'root' will not be able to ssh in and they
188 # will get a message to login instead as the default $user
189 disable_root: true
190
191 # This will cause the set+update hostname module to not operate (if true)
192 preserve_hostname: false
193
194 apt:
195 # This prevents cloud-init from rewriting apt's sources.list file,
196 # which has been a source of surprise.
197 preserve_sources_list: true
198
199 # manually managed resolv
200 manage_resolv_conf: false
201
202 package_update: true
203 packages:
204 - qemu-guest-agent
205
206 # The modules that run in the 'init' stage
207 cloud_init_modules:
208 - seed_random
209 - bootcmd
210 - write-files
211 - growpart
212 - resizefs
213 - disk_setup
214 - mounts
215 - set_hostname
216 - update_hostname
217 - update_etc_hosts
218 - ca-certs
219 - rsyslog
220 - users-groups
221 - ssh
222
223 # The modules that run in the 'config' stage
224 cloud_config_modules:
225 - keyboard
226 - locale
227 - set-passwords
228 - grub-dpkg
229 - apt-pipelining
230 - apt-configure
231 - ntp
232 - timezone
233 - disable-ec2-metadata
234 - runcmd
235
236 # The modules that run in the 'final' stage
237 cloud_final_modules:
238 - package-update-upgrade-install
239 - write-files-deferred
240 - scripts-vendor
241 - scripts-per-once
242 - scripts-per-boot
243 - scripts-per-instance
244 - scripts-user
245 - ssh-authkey-fingerprints
246 # - keys-to-console
247 - install-hotplug
248 # - phone-home
249 - final-message
250 - power-state-change
251
252 runcmd:
253 - systemctl enable qemu-guest-agent.service
254
255 # System and/or distro specific settings
256 # (not accessible to handlers/transforms)
257 system_info:
258 # This will affect which distro class gets used
259 distro: debian
260 # Other config here will be given to the distro class and/or path classes
261 paths:
262 cloud_dir: /var/lib/cloud/
263 templates_dir: /etc/cloud/templates/
264 package_mirrors:
265 - arches: [default]
266 failsafe:
267 primary: https://deb.debian.org/debian
268 security: https://deb.debian.org/debian-security
269 ssh_svcname: ssh
270 {{/code}}
271
272
273
274
275
276
277 )))
278
279 (% class="col-xs-12 col-sm-4" %)
280 (((
281 (% class="box" %)
282 (((
283 |=Site|[[Proxmox>>https://proxmox.com]]
284 |=Dashboard|
285 |=Servers|1200 €
286 |=Image|[[Credits>>https://commons.wikimedia.org/wiki/File:FalabellaFestivo.jpg]]
287 )))
288
289 (% class="box" %)
290 (((
291 **Contents**
292
293 {{toc/}}
294 )))
295 )))
296 )))