<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Miner Ninja</title>
    <description>The latest articles on DEV Community by Miner Ninja (@minerninja).</description>
    <link>https://dev.to/minerninja</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1757881%2Fac4b1074-9001-49aa-b311-1f760127ad07.png</url>
      <title>DEV Community: Miner Ninja</title>
      <link>https://dev.to/minerninja</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/minerninja"/>
    <language>en</language>
    <item>
      <title>Create an Ubuntu Cloud-Init Template on Proxmox: The Command Line Guide</title>
      <dc:creator>Miner Ninja</dc:creator>
      <pubDate>Wed, 28 Aug 2024 14:44:35 +0000</pubDate>
      <link>https://dev.to/minerninja/create-an-ubuntu-cloud-init-template-on-proxmox-the-command-line-guide-5b61</link>
      <guid>https://dev.to/minerninja/create-an-ubuntu-cloud-init-template-on-proxmox-the-command-line-guide-5b61</guid>
      <description>&lt;p&gt;This guide will demonstrate how to create an Ubuntu cloud-init template on Proxmox and set up a virtual machine with Ubuntu Server 24.04 LTS via the command line.&lt;br&gt;
For the latest Ubuntu Cloud images, you can check &lt;a href="https://cloud-images.ubuntu.com/" rel="noopener noreferrer"&gt;Ubuntu Cloud Images&lt;/a&gt;.&lt;br&gt;
All steps in this guide are to be executed on a Proxmox server.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Prepare the Ubuntu Cloud-init Image
&lt;/h2&gt;
&lt;h4&gt;
  
  
  1.1 Download the Ubuntu Cloud Image:
&lt;/h4&gt;

&lt;p&gt;To download the Ubuntu 24.04 image, use &lt;code&gt;wget&lt;/code&gt; with the appropriate URL and save it to the &lt;code&gt;/var/lib/vz/template/iso/&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-P&lt;/span&gt; /var/lib/vz/template/iso/ https://cloud-images.ubuntu.com/daily/server/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-P&lt;/code&gt; — option tells wget to save the file in the specified directory&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1.2 Verify that the file was downloaded successfully:
&lt;/h4&gt;

&lt;p&gt;Make sure the file is in the correct directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /var/lib/vz/template/iso/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see &lt;code&gt;ubuntu-24.04-server-cloudimg-amd64.img&lt;/code&gt; listed in the directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a Virtual Machine Template in Proxmox
&lt;/h2&gt;

&lt;h4&gt;
  
  
  2.1. Create a new Virtual Machine (VM):
&lt;/h4&gt;

&lt;p&gt;Create a VM with a unique identifier &lt;code&gt;9000&lt;/code&gt; (or any other available ID):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm create 9000 &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-cloud-init-template"&lt;/span&gt; &lt;span class="nt"&gt;--memory&lt;/span&gt; 2048 &lt;span class="nt"&gt;--cores&lt;/span&gt; 2 &lt;span class="nt"&gt;--net0&lt;/span&gt; virtio,bridge&lt;span class="o"&gt;=&lt;/span&gt;vmbr0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;9000&lt;/code&gt; — Unique identifier for the VM.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--name&lt;/code&gt; — Name of the virtual machine.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--memory&lt;/code&gt; — Amount of RAM in megabytes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--cores&lt;/code&gt; — Number of CPU cores.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--net0&lt;/code&gt; — Network card configuration (uses &lt;code&gt;virtio&lt;/code&gt; with bridge &lt;code&gt;vmbr0&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2.3 Import the downloaded image into the Proxmox storage
&lt;/h4&gt;

&lt;p&gt;Use &lt;code&gt;qm importdisk&lt;/code&gt; to import the downloaded image into local storage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm importdisk 9000 /var/lib/vz/template/iso/ubuntu-24.04-server-cloudimg-amd64.img local-lvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;9000&lt;/code&gt; — ID of the virtual machine.&lt;/li&gt;
&lt;li&gt;Path to the Ubuntu Cloud-init image file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;local-lvm&lt;/code&gt; — Name of the storage in Proxmox.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2.4 Configure the primary disk and VM settings:
&lt;/h4&gt;

&lt;p&gt;Set up the disk using the &lt;code&gt;scsi&lt;/code&gt; type and configure the boot options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--scsihw&lt;/span&gt; virtio-scsi-pci &lt;span class="nt"&gt;--scsi0&lt;/span&gt; local-lvm:vm-9000-disk-0
qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--boot&lt;/span&gt; c &lt;span class="nt"&gt;--bootdisk&lt;/span&gt; scsi0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--scsihw&lt;/code&gt; — Specifies the SCSI controller type (using &lt;code&gt;virtio-scsi-pci&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--scsi0&lt;/code&gt; — Configures the primary disk of the VM.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--boot c --bootdisk scsi0&lt;/code&gt; — Sets the VM to boot from the primary disk.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2.5. Add a Cloud-init disk:
&lt;/h4&gt;

&lt;p&gt;Add a Cloud-init disk to the VM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--ide2&lt;/span&gt; local-lvm:cloudinit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--ide2&lt;/code&gt; — Specifies that the disk will be attached as an IDE device.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;local-lvm:cloudinit&lt;/code&gt; — Specifies the storage and type of the disk.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Configure Cloud-init
&lt;/h2&gt;

&lt;p&gt;Configure Cloud-init settings such as user, password, and SSH key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--ipconfig0&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dhcp
   qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--ciuser&lt;/span&gt; ubuntu &lt;span class="nt"&gt;--cipassword&lt;/span&gt; &lt;span class="s1"&gt;'yourpassword'&lt;/span&gt;
   qm &lt;span class="nb"&gt;set &lt;/span&gt;9000 &lt;span class="nt"&gt;--sshkey&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ssh/id_rsa.pub&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--ipconfig0 ip=dhcp&lt;/code&gt; — Configures the IP to be assigned via DHCP.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--ciuser&lt;/code&gt; — Specifies the Cloud-init username.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--cipassword&lt;/code&gt; — Sets the password for the user (replace &lt;code&gt;'yourpassword'&lt;/code&gt; with your desired password).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--sshkey&lt;/code&gt; — Adds an SSH key for the user (the contents of the public key from &lt;code&gt;~/.ssh/id_rsa.pub&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: Save the Template
&lt;/h2&gt;

&lt;p&gt;Convert the VM to a template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm template 9000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Use the Template to Create New Virtual Machines
&lt;/h2&gt;

&lt;h4&gt;
  
  
  5.1 Clone the template to create a new VM:
&lt;/h4&gt;

&lt;p&gt;Create a new VM from the template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm clone 9000 201 &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"new-ubuntu-vm"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;100&lt;/code&gt; — Unique ID for the new VM.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--name&lt;/code&gt; — Name of the new virtual machine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5.2 Configure the new VM (if needed):
&lt;/h4&gt;

&lt;p&gt;You can modify settings for the new VM, such as memory size and the number of cores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm &lt;span class="nb"&gt;set &lt;/span&gt;201 &lt;span class="nt"&gt;--memory&lt;/span&gt; 4096 &lt;span class="nt"&gt;--cores&lt;/span&gt; 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5.3 Start the new VM:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   qm start 201
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now you have an guide for creating a virtual machine using the Ubuntu 24.04 Cloud-init image. This process allows you to quickly and conveniently deploy new virtual machines with minimal effort using the Proxmox command line.&lt;/p&gt;

</description>
      <category>proxmox</category>
      <category>ubuntu</category>
      <category>cloudinit</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
