<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Virtualization | Derek Armstrong — Staff Engineer &amp; Solutions Architect</title><link>https://derekarmstrong.dev/tags/virtualization/</link><atom:link href="https://derekarmstrong.dev/tags/virtualization/index.xml" rel="self" type="application/rss+xml"/><description>Virtualization</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Sat, 15 Oct 2022 00:00:00 +0000</lastBuildDate><image><url>https://derekarmstrong.dev/media/sharing.png</url><title>Virtualization</title><link>https://derekarmstrong.dev/tags/virtualization/</link></image><item><title>Setting up Cloud Init Ubuntu Image on Proxmox</title><link>https://derekarmstrong.dev/blog/setting-up-cloud-init-ubuntu-image-on-proxmox/</link><pubDate>Sat, 15 Oct 2022 00:00:00 +0000</pubDate><guid>https://derekarmstrong.dev/blog/setting-up-cloud-init-ubuntu-image-on-proxmox/</guid><description>&lt;p&gt;This post shows a compact, repeatable flow for creating a Cloud-Init based Ubuntu template in Proxmox so you can spin up configured VMs quickly.&lt;/p&gt;
&lt;div class="callout flex px-4 py-3 mb-6 rounded-md border-l-4 bg-cyan-100 dark:bg-cyan-900 border-cyan-500"
data-callout="abstract"
data-callout-metadata=""&gt;
&lt;span class="callout-icon pr-3 pt-1 text-cyan-600 dark:text-cyan-300"&gt;
&lt;svg height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"&gt;&lt;path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75a2.25 2.25 0 0 0-.1-.664m-5.8 0A2.251 2.251 0 0 1 13.5 2.25H15a2.25 2.25 0 0 1 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125zM6.75 12h.008v.008H6.75zm0 3h.008v.008H6.75zm0 3h.008v.008H6.75z"/&gt;&lt;/svg&gt;
&lt;/span&gt;
&lt;div class="callout-content dark:text-neutral-300"&gt;
&lt;div class="callout-title font-semibold mb-1"&gt;TL;DR:&lt;/div&gt;
&lt;div class="callout-body"&gt;&lt;p&gt;Download an Ubuntu cloud image, import it into Proxmox, add a Cloud-Init drive, set boot order, convert to a template, then clone.&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A Proxmox VE host with LVM (or other writable storage like &lt;code&gt;local-lvm&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SSH or shell access to your Proxmox host&lt;/li&gt;
&lt;li&gt;A public SSH key (for injecting into cloud-init)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-checklist"&gt;Quick checklist&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Download cloud image&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Create a small VM (temporary)&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Import disk, attach to VM&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Add cloud-init drive and configure user/ssh&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Convert VM to template&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Clone when needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="step-by-step"&gt;Step-by-step&lt;/h2&gt;
&lt;h3 id="1-download-the-ubuntu-cloud-image"&gt;1) Download the Ubuntu cloud image&lt;/h3&gt;
&lt;p&gt;Choose the release you prefer and download the cloud image. Example (Focal):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="2-create-a-temporary-vm-to-attach-the-image-to"&gt;2) Create a temporary VM to attach the image to&lt;/h3&gt;
&lt;p&gt;Adjust memory and CPU to taste — this VM will become the template.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm create &lt;span class="m"&gt;8000&lt;/span&gt; --memory &lt;span class="m"&gt;2048&lt;/span&gt; --core &lt;span class="m"&gt;2&lt;/span&gt; --name ubuntu-cloud --net0 virtio,bridge&lt;span class="o"&gt;=&lt;/span&gt;vmbr0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="3-import-the-cloud-image-into-storage"&gt;3) Import the cloud image into storage&lt;/h3&gt;
&lt;p&gt;Import the downloaded image into a Proxmox storage pool (example uses &lt;code&gt;local-lvm&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm importdisk &lt;span class="m"&gt;8000&lt;/span&gt; focal-server-cloudimg-amd64.img local-lvm
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="4-attach-the-imported-disk-to-the-vm-scsi-recommended"&gt;4) Attach the imported disk to the VM (SCSI recommended)&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-8000-disk-0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="5-add-the-cloud-init-drive"&gt;5) Add the Cloud-Init drive&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --ide2 local-lvm:cloudinit
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="6-make-the-vm-boot-from-the-disk"&gt;6) Make the VM boot from the disk&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --boot c --bootdisk scsi0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="7-add-a-serial-console-optional-helpful-for-headless-debugging"&gt;7) Add a serial console (optional, helpful for headless debugging)&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --serial0 socket --vga serial0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="callout flex px-4 py-3 mb-6 rounded-md border-l-4 bg-orange-100 dark:bg-orange-900 border-orange-500"
data-callout="warning"
data-callout-metadata=""&gt;
&lt;span class="callout-icon pr-3 pt-1 text-orange-600 dark:text-orange-300"&gt;
&lt;svg height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"&gt;&lt;path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0zM12 15.75h.007v.008H12z"/&gt;&lt;/svg&gt;
&lt;/span&gt;
&lt;div class="callout-content dark:text-neutral-300"&gt;
&lt;div class="callout-title font-semibold mb-1"&gt;Don&amp;rsquo;t Start Yet&lt;br&gt;&lt;/div&gt;
&lt;div class="callout-body"&gt;&lt;p&gt;&lt;strong&gt;Warning — do not start the VM yet.&lt;/strong&gt; Configure cloud-init and hardware first. Starting too early can record IDs/state you may not want in your template.&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id="8-configure-cloud-init-fields-hostname-user-ssh-key"&gt;8) Configure Cloud-Init fields (hostname, user, SSH key)&lt;/h3&gt;
&lt;p&gt;You can set these with the GUI or via &lt;code&gt;qm set&lt;/code&gt;. Example CLI:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --ciuser ubuntu --sshkey &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;cat ~/.ssh/id_rsa.pub&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="m"&gt;8000&lt;/span&gt; --citype nocloud
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to provide a full &lt;code&gt;user-data&lt;/code&gt;/&lt;code&gt;meta-data&lt;/code&gt; payload for NoCloud, you can supply files or use Proxmox GUI fields.&lt;/p&gt;
&lt;h3 id="9-convert-the-vm-to-a-template"&gt;9) Convert the VM to a template&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm template &lt;span class="m"&gt;8000&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="10-clone-the-template-whenever-you-need-a-new-vm"&gt;10) Clone the template whenever you need a new VM&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;qm clone &lt;span class="m"&gt;8000&lt;/span&gt; &lt;span class="m"&gt;135&lt;/span&gt; --name yoshi
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="tips"&gt;Tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Resize disks after cloning if you need per-VM different sizes; keep the template small.&lt;/li&gt;
&lt;li&gt;Put idempotent provisioning (Ansible, cloud-init modules) in the guest rather than baking many steps into the template.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="troubleshooting"&gt;Troubleshooting&lt;/h2&gt;
&lt;p&gt;If you accidentally booted a template (or need a fresh machine-id inside a guest):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo rm -f /etc/machine-id
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo rm -f /var/lib/dbus/machine-id
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Shutdown the VM and do not boot it; a new id will be generated on next boot. If it&amp;rsquo;s not generated automatically, run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemd-machine-id-setup
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If cloud-init doesn&amp;rsquo;t apply after cloning, verify the cloud-init datasource type and that Proxmox&amp;rsquo;s cloud-init fields are populated correctly for the new host.&lt;/p&gt;
&lt;hr&gt;</description></item></channel></rss>