<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Filesystem on DevOps OPf</title><link>https://buck.zone/en/tags/filesystem/</link><description>Recent content in Filesystem on DevOps OPf</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Daniel 'Tealk' Buck</copyright><lastBuildDate>Thu, 24 Aug 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://buck.zone/en/tags/filesystem/index.xml" rel="self" type="application/rss+xml"/><item><title>Logical Volume Management (LVM) Guide</title><link>https://buck.zone/en/p/logical-volume-management-lvm-guide/</link><pubDate>Thu, 24 Aug 2023 00:00:00 +0000</pubDate><guid>https://buck.zone/en/p/logical-volume-management-lvm-guide/</guid><description>&lt;p&gt;Logical Volume Management (LVM) is a flexible method for managing storage on Linux systems. It allows you to dynamically adjust storage space without recreating partitions or deleting data. This guide explains how to create, extend, and permanently mount an LVM.&lt;/p&gt;
&lt;h2 id="create-lvm"&gt;Create LVM
&lt;/h2&gt;&lt;h3 id="create-a-physical-volume-pv"&gt;Create a Physical Volume (PV)
&lt;/h3&gt;&lt;p&gt;A &lt;strong&gt;Physical Volume (PV)&lt;/strong&gt; is the foundation of LVM. It represents a physical disk or partition to be used by LVM. To create a PV, run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;pvcreate /dev/sdb
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/dev/sdb&lt;/code&gt; is the disk you want to use for LVM. Replace it with the actual device name of your disk.&lt;/li&gt;
&lt;li&gt;This step marks the disk as LVM-compatible and prepares it for use in a Volume Group.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="create-a-volume-group-vg"&gt;Create a Volume Group (VG)
&lt;/h3&gt;&lt;p&gt;A &lt;strong&gt;Volume Group (VG)&lt;/strong&gt; is a collection of Physical Volumes. It provides the storage space from which Logical Volumes are created. To create a VG and add the previously created PV, use:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;vgcreate vg_data /dev/sdb
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;vg_data&lt;/code&gt; is the name of the Volume Group. You can choose any name that makes sense for your setup.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/dev/sdb&lt;/code&gt; is the Physical Volume to be added to the Volume Group.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="create-a-logical-volume-lv"&gt;Create a Logical Volume (LV)
&lt;/h3&gt;&lt;p&gt;A &lt;strong&gt;Logical Volume (LV)&lt;/strong&gt; is the actual usable storage space allocated from a Volume Group. To create an LV that uses all available space in the Volume Group, run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;lvcreate -l 100%FREE -n lv_data vg_data
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-l 100%FREE&lt;/code&gt; allocates all available space in the Volume Group to the Logical Volume.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-n lv_data&lt;/code&gt; assigns the name &lt;code&gt;lv_data&lt;/code&gt; to the Logical Volume.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;vg_data&lt;/code&gt; is the Volume Group from which the space is allocated.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="create-a-filesystem"&gt;Create a Filesystem
&lt;/h3&gt;&lt;p&gt;To use the Logical Volume, you need to create a filesystem on it. In this example, we use the ext4 filesystem:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;mkfs.ext4 /dev/vg_data/lv_data
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/dev/vg_data/lv_data&lt;/code&gt; is the path to the Logical Volume.&lt;/li&gt;
&lt;li&gt;The ext4 filesystem is a common choice for Linux systems, but you can use other filesystems like XFS or btrfs depending on your requirements.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="extend-lvm"&gt;Extend LVM
&lt;/h2&gt;&lt;p&gt;If you need more storage space, you can extend an existing LVM. Follow these steps:&lt;/p&gt;
&lt;h3 id="resize-the-physical-volume-pv"&gt;Resize the Physical Volume (PV)
&lt;/h3&gt;&lt;p&gt;If the underlying disk has been expanded (e.g., by adding more storage in a virtual machine), you need to update the Physical Volume:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;pvresize /dev/sdb
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This command adjusts the size of the Physical Volume to match the new size of the disk.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/dev/sdb&lt;/code&gt; is the disk you are resizing.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="extend-the-logical-volume-lv"&gt;Extend the Logical Volume (LV)
&lt;/h3&gt;&lt;p&gt;To use the additional storage space, extend the Logical Volume:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;lvextend -l +100%FREE /dev/vg_data/lv_data
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-l +100%FREE&lt;/code&gt; extends the Logical Volume by using all available free space in the Volume Group.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/dev/vg_data/lv_data&lt;/code&gt; is the Logical Volume you are extending.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="resize-the-filesystem"&gt;Resize the Filesystem
&lt;/h3&gt;&lt;p&gt;After extending the Logical Volume, you need to resize the filesystem to utilize the new space:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;resize2fs /dev/mapper/vg_data-lv_data
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;resize2fs&lt;/code&gt; adjusts the size of the ext4 filesystem to match the new size of the Logical Volume.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/dev/mapper/vg_data-lv_data&lt;/code&gt; is the path to the Logical Volume.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="add-entry-to-etcfstab"&gt;Add Entry to &lt;code&gt;/etc/fstab&lt;/code&gt;
&lt;/h2&gt;&lt;p&gt;To ensure the Logical Volume is automatically mounted at system startup, you need to add it to the &lt;code&gt;/etc/fstab&lt;/code&gt; file.&lt;/p&gt;
&lt;h3 id="display-the-uuid"&gt;Display the UUID
&lt;/h3&gt;&lt;p&gt;Find the UUID of the Logical Volume:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;lsblk -f
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The UUID is a unique identifier for the Logical Volume. It is required to add the volume to &lt;code&gt;/etc/fstab&lt;/code&gt;.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="add-entry-to-etcfstab-1"&gt;Add Entry to &lt;code&gt;/etc/fstab&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Add the UUID to the &lt;code&gt;/etc/fstab&lt;/code&gt; file so the volume is mounted automatically at boot:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;UUID=foo /mnt/data ext4 defaults 0 0&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; /etc/fstab
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;foo&lt;/code&gt; with the actual UUID of the Logical Volume.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/mnt/data&lt;/code&gt; is the mount point where the Logical Volume will be accessible. Adjust this to your desired directory.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ext4&lt;/code&gt; is the filesystem type. Use the appropriate type if you used a different filesystem.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="reload-systemd"&gt;Reload Systemd
&lt;/h3&gt;&lt;p&gt;Reload the Systemd configuration to apply the changes:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;systemctl daemon-reload
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This ensures that Systemd recognizes the updated &lt;code&gt;/etc/fstab&lt;/code&gt; configuration.##&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="mount-the-volume"&gt;Mount the Volume
&lt;/h3&gt;&lt;p&gt;Finally, mount the volume to verify that everything is working correctly:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&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;mount -a
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This command mounts all filesystems listed in &lt;code&gt;/etc/fstab&lt;/code&gt;. If there are no errors, the Logical Volume should now be mounted and accessible.&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>