<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DevMemo – linux</title><link>https://devmemo.gitlab.io/tags/linux/</link><description>Recent content in linux on DevMemo</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Thu, 13 Jul 2023 05:40:50 +0000</lastBuildDate><atom:link href="https://devmemo.gitlab.io/tags/linux/index.xml" rel="self" type="application/rss+xml"/><item><title>Blog: How To Resize Disk On Linux</title><link>https://devmemo.gitlab.io/blog/how_to_resize_disk_on_linux/</link><pubDate>Thu, 13 Jul 2023 05:40:50 +0000</pubDate><guid>https://devmemo.gitlab.io/blog/how_to_resize_disk_on_linux/</guid><description>
&lt;p>Assuming you have a Linux VM, and you enlarged the disk. Take the following steps on your Linux to apply the changes.&lt;/p>
&lt;h2 id="step-1-resize-the-volume">Step 1: Resize the volume&lt;/h2>
&lt;p>The easiest way to resize your volume is to use cfdisk.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo cfdisk
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This is what it looks like on my VM.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span> Disk: /dev/sda
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Size: 64 GiB, 68719476736 bytes, 134217728 sectors
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Label: gpt, identifier: 89F6152F-43FB-4262-8B2E-06EF3344C5A3
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Device Start End Sectors Size Type
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;gt;&amp;gt; /dev/sda1 2048 4095 2048 1M BIOS boot
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> /dev/sda2 4096 134217694 134213599 64G Linux filesystem
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ┌────────────────────────────────────────────────────────────────────────────────────┐
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │Partition UUID: 1BDD55B2-1581-4671-878E-5891F4802220 │
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │Partition type: BIOS boot (21686148-6449-6E6F-744E-656564454649) │
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └────────────────────────────────────────────────────────────────────────────────────┘
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> [ Delete ] [ Resize ] [ Quit ] [ Type ] [ Help ] [ Write ] [ Dump ]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Go to your target device, and then resize it as you need. For my case, it is &lt;code>/dev/sda2&lt;/code>, because that&amp;rsquo;s where the root directory is mounted.&lt;/p>
&lt;h2 id="step-2-apply-the-change-to-your-filesystem">Step 2: Apply the change to your filesystem.&lt;/h2>
&lt;p>To apply the change to your file system, run the following command&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo resize2fs /dev/sda2
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now you have added more spaces to your disk.&lt;/p></description></item><item><title>Blog: Automate Proxmox VM Creation With Cloud-Init</title><link>https://devmemo.gitlab.io/blog/automate_proxmox_vm_creation_with_cloud_init/</link><pubDate>Mon, 06 Feb 2023 15:10:26 -0800</pubDate><guid>https://devmemo.gitlab.io/blog/automate_proxmox_vm_creation_with_cloud_init/</guid><description>
&lt;p>This post gives you step-by-step instructions of how to automate proxmox VM creation. I&amp;rsquo;ll use ubuntu as an example.&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>The overall strategy is to use the &lt;a href="https://cloud-images.ubuntu.com/">ubuntu cloud image&lt;/a> to create a Proxmox VM template, and attach a cloud-init disk to it. After that, we can clone the template to create new VM, and new VM will automatically bootstrap itself, e.g., changing the hostname.&lt;/p>
&lt;h2 id="prepare-tools">Prepare tools&lt;/h2>
&lt;p>Install &lt;code>virt-customize&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>apt-get install libguestfs-tools
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="prepare-the-ubuntu-cloud-image">Prepare The Ubuntu Cloud Image&lt;/h2>
&lt;p>Use the following commands to prepare the ubuntu cloud image:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Create a new directory for our image building.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkdir ubuntu-cloud-image
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd ubuntu-cloud-image
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Download the cloud image.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Resize the image to 16GB. Feel free to change it to your desired size.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qemu-img resize noble-server-cloudimg-amd64.img 16G
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Install avahi-deamon for mdns.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>virt-customize -a noble-server-cloudimg-amd64.img --run-command &lt;span style="color:#e6db74">&amp;#39;apt update &amp;amp;&amp;amp; apt install avahi-daemon -y &amp;amp;&amp;amp; cloud-init clean --logs --machine-id --configs all --reboot &amp;amp;&amp;amp; sudo truncate -s 0 /etc/machine-id /var/lib/dbus/machine-id&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="prepare-the-proxmox-vm-template">Prepare The Proxmox VM Template&lt;/h2>
&lt;p>Then, we prepare the Proxmox VM template with the following steps.&lt;/p>
&lt;h3 id="create-a-temporary-vm">Create A Temporary VM&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Create a VM with the following configuration:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># * vmid: 1000 (feel free to change this)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># * memory: 4GB&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># * network: attached to bridge vmbr0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm create &lt;span style="color:#ae81ff">1000&lt;/span> --name ubuntu-noble-template --memory &lt;span style="color:#ae81ff">4096&lt;/span> --net0 virtio,bridge&lt;span style="color:#f92672">=&lt;/span>vmbr0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="attach-the-ubuntu-cloud-image">Attach The Ubuntu Cloud Image&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Attach the ubuntu cloud image onto the VM.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Note that here ssd is my storage name. You&amp;#39;ll need to replace it with yours.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm importdisk &lt;span style="color:#ae81ff">1000&lt;/span> noble-server-cloudimg-amd64.img ssd
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Make the attached disk scsi0.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm set &lt;span style="color:#ae81ff">1000&lt;/span> --scsihw virtio-scsi-pci --scsi0 ssd:vm-1000-disk-0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Set scsi0 as the first boot device.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm set &lt;span style="color:#ae81ff">1000&lt;/span> --boot c --bootdisk scsi0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="create-a-cloud-init-drive">Create A Cloud-init Drive&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Create a cloud-init drive.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm set &lt;span style="color:#ae81ff">1000&lt;/span> --ide2 ssd:cloudinit
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Configure your cloud-init drive. Replace the username, password and sshkeys for your case.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm set &lt;span style="color:#ae81ff">1000&lt;/span> --ciuser swe --cipassword swe-passwd --sshkeys ~/.ssh/id_rsa.pub --ipconfig0 ip&lt;span style="color:#f92672">=&lt;/span>dhcp
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="convert-the-vm-into-a-template">Convert The VM Into A Template&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Convert the VM into a template.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm template &lt;span style="color:#ae81ff">1000&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="create-vm">Create VM&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Create a VM using the template, and set the name to ubuntu-vm1.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm clone &lt;span style="color:#ae81ff">1000&lt;/span> &lt;span style="color:#ae81ff">1101&lt;/span> --full --name ubuntu-vm1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Create another VM using the template, and set the name to ubuntu-vm2.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>qm clone &lt;span style="color:#ae81ff">1000&lt;/span> &lt;span style="color:#ae81ff">1102&lt;/span> --full --name ubuntu-vm2
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To access these VMs, you can do&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Use the following command to access ubuntu-vm1 if you have mdns included in your template, and you are within the same LAN as ubuntu-vm1.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ssh swe@ubuntu-vm1.local
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Use the following command to access ubuntu-vm2 if you have mdns included in your template, and you are within the same LAN as ubuntu-vm2.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ssh swe@ubuntu-vm2.local
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item></channel></rss>