Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Reclaim hard-drive space with LVM

#1
Reclaim hard-drive space with LVM

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/11/reclaim-hard-drive-space-with-lvm.png" width="903" height="493" title="" alt="" /></div><div><p>LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes. It is commonly used on Fedora installations (prior to BTRFS as default it was LVM+Ext4). But have you ever started up your system to find a message like the image above, after you logged in? Uh oh, Gnome just said the home volume is almost out of space! Luckily, there is likely some space sitting around in another volume, unused and ready to re-alocate. Here’s how to reclaim hard-drive space with LVM.</p>
<p> <span id="more-32142"></span> </p>
<p>The key to easily re-alocate space between volumes is the <a href="http://sourceware.org/lvm2/">Logical Volume Manager (LVM)</a>. Fedora 32 and before use LVM to divide disk space by default. This technology is similar to standard hard-drive partitions, but LVM is a lot more flexible. LVM enables not only flexible volume size management, but also advanced capabilities such as read-write snapshots, striping or mirroring data across multiple drives, using a high-speed drive as a cache for a slower drive, and much more. All of these advanced options can get a bit overwhelming, but resizing a volume is straight-forward.</p>
<h2>LVM basics</h2>
<p>The <em>volume group</em> serves as the main container in the LVM system. By default Fedora only defines a single volume group, but there can be as many as needed. Actual hard-drive and hard-drive partitions are added to the <em>volume group</em> as <em>physical volumes</em>. <em>Physical volumes</em> add available free space to the <em>volume group</em>. A typical Fedora install has one formatted boot partition, and the rest of the drive is a partition configured as an LVM <em>physical volume</em>. </p>
<p>Out of this pool of available space, the <em>volume group</em> allocates one or more <em>logical volumes</em>. These volumes are similar to hard-drive partitions, but without the limitation of contiguous space on the disk. LVM <em>logical volumes</em> can even span multiple devices! Just like hard-drive partitions, <em>logical volumes </em>have a defined size and can contain any filesystem which can then be mounted to specific directories.</p>
<h2>What’s needed</h2>
<p>Confirm the system uses LVM with the <em>gnome-disks</em> application, and make sure there is free space available in some other volume. Without space to reclaim from another volume, this guide isn’t useful. A <a href="https://getfedora.org/en/workstation/download/">Fedora live CD/USB</a> is also needed. Any file system that needs to shrink must be unmounted. Running from a live image allows all the volumes on the hard-disk to remain unmounted, even important directories like <em>/</em> and <em>/home</em>.</p>
<figure class="wp-block-image size-large"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/11/reclaim-hard-drive-space-with-lvm.png" alt="Use gnome-disks to verify free space." class="wp-image-32144" /><figcaption>Use gnome-disks to verify free space</figcaption></figure>
<h2>A word of warning</h2>
<p>No data should be lost by following this guide, but it does muck around with some very low-level and powerful commands. One mistake could destroy all data on the hard-drive. So backup all the data on the disk first!</p>
<h2>Resizing LVM volumes</h2>
<p>To begin, boot the Fedora live image and select <em>Try Fedora</em> at the dialog. Next, use the <em>Run Command</em> to launch the <em>blivet-gui</em> application (accessible by pressing <em>Alt-F2</em>, typing <em>blivet-gui</em>, then pressing <em>enter</em>). Select the volume group on the left under <em>LVM</em>. The logical volumes are on the right.</p>
<figure class="wp-block-image size-large is-resized"><img loading="lazy" src="https://www.sickgaming.net/blog/wp-content/uploads/2020/11/reclaim-hard-drive-space-with-lvm-1.png" alt="Explore logical volumes in blivet gui." class="wp-image-32145" width="581" height="333" /><figcaption>Explore logical volumes in blivet-gui</figcaption></figure>
<p>The logical volume labels consist of both the volume group name and the logical volume name. In the example, the volume group is “fedora_localhost-live” and there are “home”, “root”, and “swap” logical volumes allocated. To find the full volume, select each one, click on the <em>gear</em> icon, and choose <em>resize</em>. The slider in the resize dialog indicates the allowable sizes for the volume. The minimum value on the left is the space already in use within the file system, so this is the minimum possible volume size (without deleting data). The maximum value on the right is the greatest size the volume can have based on available free space in the <em>volume group</em>.</p>
<figure class="wp-block-image size-large"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/11/reclaim-hard-drive-space-with-lvm-2.png" alt="Use the resize dialog in blivet-gui to set the new volume sizes." class="wp-image-32146" /><figcaption>Resize dialog in blivet-gui</figcaption></figure>
<p>A grayed out <em>resize</em> option means the volume is full and there is no free space in the volume group. It’s time to change that! Look through all of the volumes to find one with plenty of extra space, like in the screenshot above. Move the slider to the left to set the new size. Free up enough space to be useful for the full volume, but still leave plenty of space for future data growth. Otherwise, this volume will be the next to fill up.</p>
<p>Click <em>resize</em> and note that a new item appears in the volume listing: <em>free space</em>. Now select the full volume that started this whole endeavor, and move the slider all the way to the right. Press <em>resize</em> and marvel at the new improved volume layout. However, nothing has changed on the hard drive yet. Click on the <em>check-mark</em> to commit the changes to disk.</p>
<figure class="wp-block-image size-large"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/11/reclaim-hard-drive-space-with-lvm-3.png" alt="Review the changes in blivet-gui and then accept to reclaim hard-drive space." class="wp-image-32147" /><figcaption>Review changes in blivet-gui</figcaption></figure>
<p>Review the summary of the changes, and if everything looks right, click <em>Ok</em> to proceed. Wait for <em>blivet-gui</em> to finish.<mark class="annotation-text annotation-text-yoast" id="annotation-text-210149b5-b02e-4dc1-8567-278a926a1e8a"></mark> Now reboot back into the main Fedora install and enjoy all the new space in the previously full volume.</p>
<h2>Planning for the future</h2>
<p>It is challenging to know how much space any particular volume will need in the future. Instead of immediately allocating all available free space, consider leaving it free in the volume group. In fact, Fedora Server reserves space in the volume group by default. Extending a volume is possible while it is online and in use. No live image or reboot needed. When a volume is almost full, easily extend the volume using part of the available free space and keep working. Unfortunately the default disk manager, <em>gnome-disks</em>, does not support LVM volume resizing, so install <em><a href="https://fedoraproject.org/wiki/Blivet-gui">blivet-gui</a></em> for a graphical management tool. Alternately, there is a simple terminal command to extend a volume:</p>
<pre class="wp-block-preformatted">lvresize -r -L +1G /dev/fedora_localhost-live/root </pre>
<h2>Wrap-up</h2>
<p>Reclaiming hard-drive space with LVM just scratches the surface of LVM capabilities. Most people, especially on the desktop, probably don’t need the more advanced features. However, LVM is there when the need arises, though it can get a bit complex to implement. <a href="https://fedoramagazine.org/btrfs-coming-to-fedora-33/">BTRFS</a> is the default filesystem, without LVM, starting with <a href="https://fedoramagazine.org/whats-new-fedora-33-workstation/">Fedora 33</a>. BTRFS can be easier to manage while still flexible enough for most common usages. Check out the recent <a href="https://fedoramagazine.org/btrfs-snapshots-backup-incremental/">Fedora Magazine articles on BTRFS</a> to learn more.</p></p>
</div>


https://www.sickgaming.net/blog/2020/11/...-with-lvm/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016