<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>lxc on Andrew Beaton</title>
    <link>https://andrewbeaton.net/tags/lxc/</link>
    <description>Recent content in lxc on Andrew Beaton</description>
    <image>
      <title>Andrew Beaton</title>
      <url>https://andrewbeaton.net/me.jpeg</url>
      <link>https://andrewbeaton.net/me.jpeg</link>
    </image>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Tue, 20 Jun 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://andrewbeaton.net/tags/lxc/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Automating Linux Containers and Virtual Machines on Proxmox.</title>
      <link>https://andrewbeaton.net/posts/2023/06/proxmox-automate-lxcs-vms/</link>
      <pubDate>Tue, 20 Jun 2023 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2023/06/proxmox-automate-lxcs-vms/</guid>
      <description>A guide to automating the creation of linux containers and virtual machines on Proxmox using scripts.</description>
      <content:encoded><![CDATA[<h2 id="introduction">Introduction</h2>
<p>Automation plays a key role in standardising and simplifying the process of building environments.</p>
<p>Continuing on my journey of automating my home lab setup, I found a very good resource that&rsquo;s available for <a href="https://www.proxmox.com/en/">Proxmox</a> users to automate the installation of various Linux containers and Virtual Machines. You can find them from user <a href="https://github.com/tteck/">tteckster</a> here <a href="https://tteck.github.io/Proxmox/">https://tteck.github.io/Proxmox/</a></p>
<p>By using these scripts, we can save time, ensure consistency, and reduce the chances of human error during the environment build process.</p>
<h2 id="why-automate-lxc-and-vm-builds">Why Automate LXC and VM Builds?</h2>
<p>Automation offers several notable benefits when it comes to building Linux containers and VMs:</p>
<h3 id="time-and-effort-savings"><strong>Time and Effort Savings</strong></h3>
<p>Manually configuring and setting up containers or VMs can be a time-consuming and labor-intensive task.</p>
<p>By automating the build process using command line scripts, we can save significant time and effort.</p>
<p>Scripts eliminate the need to manually perform repetitive steps, allowing for faster deployment.</p>
<h3 id="consistency-and-reproducibility"><strong>Consistency and Reproducibility</strong></h3>
<p>Maintaining consistency across multiple containers or VMs is vital in ensuring reliable application deployment.</p>
<p>Command line scripts enable us to define the exact configuration and settings required for each container or VM.</p>
<p>By automating the build process, every instance is built using the same steps, ensuring consistency and reproducibility across different environments.</p>
<h3 id="error-reduction"><strong>Error Reduction</strong></h3>
<p>Manual configuration is prone to human error. Even a small mistake in the build process can lead to significant issues, affecting the stability and performance.</p>
<p>Automation minimises the chances of human error by executing a predefined set of instructions consistently.</p>
<p>Scripts can perform complex and error-prone tasks accurately, reducing the risk of misconfiguration or missteps.</p>
<h3 id="flexibility-and-customisation"><strong>Flexibility and Customisation</strong></h3>
<p>These command line scripts provide a flexible and customisable approach to building Linux containers and VMs.</p>
<p>These scripts often offer various options and parameters that allow us to tailor the build process according to their specific requirements.</p>
<p>We can choose different configurations, select specific software packages, and define resource allocation based on our application&rsquo;s needs.</p>
<h2 id="introducing-the-command-line-scripts">Introducing the Command Line Scripts</h2>
<p>This brilliant <a href="https://tteck.github.io/Proxmox/">website</a> by <a href="https://github.com/tteck/">tteckster</a> provides a collection of command line scripts that enable the automation of Linux Container (LXC) and Virtual Machine (VM) builds on <a href="https://www.proxmox.com/en/">Proxmox</a>.</p>
<p>These scripts enable us to create in an interactive manner, offering options for both basic and advanced configurations.</p>
<h3 id="basic-setup">Basic Setup</h3>
<p>The basic setup uses default settings, making it a convenient option for users who prefer a quick and straight forward setup.</p>
<p>To run the basic script for your specific machine, go through the list of options available and use the command in the Proxmox shell.</p>
<p>For example, to create a Linux Container for Cloudflared, we can use the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>bash -c <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/cloudflared.sh<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><p>Or to create a MariaDB container, we can use the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>bash -c <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/mariadb.sh<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><h3 id="advanced-setup">Advanced Setup</h3>
<p>For more flexibility and customisation, the advanced setup feature of the scripts allows us to alter the default settings according to our needs.</p>
<p>This function utilises the <code>whiptail</code> command to present options in a dialogue box format, allowing us to modify the options available, such as increased memory, disk size and set options such as static IP addresses and DNS.</p>
<p>To run the advanced setup script, when prompted, choose the <!-- raw HTML omitted --> settings options when presented after running your chosen script.</p>
<p>After selecting your options, the script collects and verifies the input in order to generate the final configuration for the container or virtual machine.</p>
<h2 id="summary">Summary</h2>
<p>Automating our Proxmox builds with command line scripts streamlines the deployment process, reduces manual effort, and ensures consistency and reproducibility.</p>
<p>By using the provided basic or advanced setup scripts from the website, we can easily build Linux Containers or Virtual Machines on <a href="https://www.proxmox.com/en/">Proxmox</a> tailored to our specific needs in a repeatable manner.</p>
<p>Remember to visit <a href="https://tteck.github.io/Proxmox/">https://tteck.github.io/Proxmox/</a> for more details and documentation on the available scripts.</p>
<p>There are also a number of other scripts available and can be found by searching on GitHub. For example, user <a href="https://github.com/roib20">roib20</a> has created Proxmox helper scripts for TrueNAS and CloudInit which can be found here <a href="https://github.com/roib20/proxmox-scripts.">https://github.com/roib20/proxmox-scripts</a></p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Using Terraform to create an LXC on Proxmox</title>
      <link>https://andrewbeaton.net/posts/2020/02/using-terraform-to-create-lxc-on-proxmox/</link>
      <pubDate>Tue, 18 Feb 2020 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2020/02/using-terraform-to-create-lxc-on-proxmox/</guid>
      <description>Using Terraform to create an LXC on Proxmox</description>
      <content:encoded><![CDATA[<p>I’ve been looking at automating as much of my home lab that’s running on <a href="https://www.proxmox.com/en/">Proxmox</a>  as possible, not only to get things up and running quickly should a failure happen but also to keep my skills current with the various automation tools out there at the moment.</p>
<p>From my previous posts, you can see that I use <a href="https://www.ansible.com/">Ansible</a> a fair bit for my personal projects, but at work, being a C# developer and working for an organisation that is predominantly Microsoft based, we use <a href="https://www.terraform.io/">Terraform</a> by HashiCorp for infrastructure automation.</p>
<p>I’ve been keeping a close eye on a project by Telmate on Github. They have been working on the <a href="https://github.com/Telmate/terraform-provider-proxmox">Terraform Proxmox Provider</a> and a few days ago a commit was made to allow the creation of <a href="https://en.wikipedia.org/wiki/LXC">Linux Containers (LXC)</a> in Proxmox as opposed to just the creation of Virtual Machines (VMs), so I was keen to give it a go.</p>
<h2 id="requirements">Requirements</h2>
<p>I’m using macOS Catalina as my development machine, so the instructions will be based on this platform, but the tools will be the same and installation may differ.</p>
<h4 id="go">Go</h4>
<p>Download and install Go from <a href="https://golang.org/dl/">Go’s website</a>. Or by a direct link to <a href="https://golang.org/doc/install?download=go1.13.3.darwin-amd64.pkg">MacOS Go 1.13.3</a></p>
<h4 id="terraform-provider-and-provisioner">Terraform Provider and Provisioner</h4>
<p>Using Go, get the latest Terraform provider and provisioner for Proxmox.</p>
<p>These instructions differ slightly from those on the <a href="https://github.com/Telmate/terraform-provider-proxmox">Terraform Proxmox Provider</a> Github page, but they are what worked for me.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Go" data-lang="Go"><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">get</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">install</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">get</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provisioner</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">go</span> <span style="color:#a6e22e">install</span> <span style="color:#a6e22e">github</span>.<span style="color:#a6e22e">com</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Telmate</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provider</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span><span style="color:#f92672">/</span><span style="color:#a6e22e">cmd</span><span style="color:#f92672">/</span><span style="color:#a6e22e">terraform</span><span style="color:#f92672">-</span><span style="color:#a6e22e">provisioner</span><span style="color:#f92672">-</span><span style="color:#a6e22e">proxmox</span>
</span></span></code></pre></div><p>Copy them to the correct locations:</p>
<pre tabindex="0"><code>which terraform-provider-proxmox
~/go-workspace/bin/terraform-provider-proxmox
which terraform-provisioner-proxmox
~/go-workspace/bin/terraform-provisioner-proxmox 

cd ~/.terraform.d
mkdir plugins
cd plugins
cp ~/go-workspace/bin/terraform-provider-proxmox .
cp ~/go-workspace/bin/terraform-provisioner-proxmox .
</code></pre><h4 id="example-of-container-creation">Example of container creation</h4>
<p>Using the example below, after updating your own values, a new container will be created, ready to be started.</p>
<p>I found it simple enough to create a new container using the Proxmox GUI and comparing the values with the resources in the example below and a little trial and error.</p>
<p>For a list of all the resources available that you can set, it’s worth having a read through of the <a href="https://github.com/Telmate/terraform-provider-proxmox/blob/master/proxmox/resource_lxc.go">resource_lxc.go</a> code on Github.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>provider <span style="color:#e6db74">&#34;proxmox&#34;</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    pm_tls_insecure <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span>    pm_api_url <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;https://proxmox.home.lan:8006/api2/json&#34;</span>
</span></span><span style="display:flex;"><span>    pm_user <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;terraform@pam&#34;</span>
</span></span><span style="display:flex;"><span>    pm_password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&lt;secure password&gt;&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>resource <span style="color:#e6db74">&#34;proxmox_lxc&#34;</span> <span style="color:#e6db74">&#34;lxc-test&#34;</span> <span style="color:#f92672">{</span> 
</span></span><span style="display:flex;"><span>    hostname <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;lxc-test-host&#34;</span>
</span></span><span style="display:flex;"><span>    cores <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>    memory <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;1024&#34;</span>
</span></span><span style="display:flex;"><span>    swap <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;2048&#34;</span>
</span></span><span style="display:flex;"><span>    network <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>        name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;eth0&#34;</span>
</span></span><span style="display:flex;"><span>        bridge <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;vmbr0&#34;</span>
</span></span><span style="display:flex;"><span>        ip <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;192.168.1.69/24&#34;</span>  
</span></span><span style="display:flex;"><span>        firewall <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>    ostemplate <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local:vztmpl/ubuntu-18.04-custom.tar.gz&#34;</span> 
</span></span><span style="display:flex;"><span>    password <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&lt;secure password&gt;&#34;</span>
</span></span><span style="display:flex;"><span>    pool <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;terraform&#34;</span>
</span></span><span style="display:flex;"><span>    rootfs <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local-lvm2:8&#34;</span> 
</span></span><span style="display:flex;"><span>    storage <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;local-lvm2&#34;</span>
</span></span><span style="display:flex;"><span>    target_node <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;proxmox&#34;</span>
</span></span><span style="display:flex;"><span>    unprivileged <span style="color:#f92672">=</span> true
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><h4 id="run">Run</h4>
<pre tabindex="0"><code>terraform init
terraform plan
terraform apply
</code></pre>]]></content:encoded>
    </item>
    
    <item>
      <title>Remove Proxmox 5.4 &#34;No Valid Subscription&#34; message</title>
      <link>https://andrewbeaton.net/posts/2019/09/proxmox-no-valid-subscription/</link>
      <pubDate>Sun, 29 Sep 2019 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2019/09/proxmox-no-valid-subscription/</guid>
      <description>Remove Proxmox 5.4 &amp;#34;No Valid Subscription&amp;#34; message</description>
      <content:encoded><![CDATA[<p>If, like me, you are using Proxmox in your Homelab, it can get a bit annoying to see the “No valid Subscription” message, every time you log in.</p>
<p>Purchasing a subscription from Proxmox is certainly recommended if you’re planning to use it in anger or in a production environment as it will give you access to support, the enterprise repository and keep the developers supported.</p>
<p>But for a test environment, you can remove the message by simply editing one of the JavaScript files on the server.</p>
<p>This file does get overwritten when you update, so you will need to reapply when that happens.</p>
<h2 id="detailed-approach">Detailed Approach</h2>
<pre tabindex="0"><code>cd /usr/share/javascript/proxmox-widget-tookit
cp proxmoxlib.js proxmoxlib.js.old
vi proxmoxlib.js
</code></pre><p>Search for Active until you find it in the following line:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">data</span>.<span style="color:#a6e22e">status</span> <span style="color:#f92672">!==</span> <span style="color:#e6db74">&#39;Active&#39;</span>) {
</span></span></code></pre></div><p>And change it to:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">false</span>) {
</span></span></code></pre></div><p>Save the file and exit. Now restart the service to load the updated file:</p>
<pre tabindex="0"><code>systemctl restart pveproxy.service
</code></pre><h2 id="one-liner-approach">One Liner Approach</h2>
<pre tabindex="0"><code>sed -i.bak &#34;s/data.status !== &#39;Active&#39;/false/g&#34; /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js &amp;&amp; systemctl restart pveproxy.service
</code></pre><p>Even if you are feeling brave, I would recommend that you take a backup of proxmoxlib.js file before running the above command, just to be safe.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
