WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Shrink Filesystem with LVM on Fedora

Edited 3 weeks ago by ExtremeHow Editorial Team

FedoraLVMFilesystemShrinkingCommand LineTerminalStorage ManagementConfigurationSystem AdministrationAdvanced Users

How to Shrink Filesystem with LVM on Fedora

This content is available in 7 different language

Logical Volume Management (LVM) is a system for managing disk storage in a more flexible and scalable way than traditional partitioning methods. With LVM, you can perform tasks such as resizing volume groups and logical volumes with minimal disruption to your system. This tutorial focuses on shrinking a file system using LVM on a Fedora system. While expanding a file system is generally straightforward, shrinking it requires careful steps. The steps described should be followed carefully as they involve potentially risky operations that can lead to data loss if not performed properly.

Understanding LVM

Before jumping into the resizing process, it is important to understand some basic concepts related to LVM:

Preparation

Before you begin shrinking your logical volume, here are some preparation steps:

1. Back up your data

The first and foremost step is to backup all the important data. Shrinking can be a delicate task and there is a risk of losing data.

2. Unmount the file system

You must ensure that the file system is not in use during the operation. This means that you should unmount it. Use the following command:

sudo umount /dev/<volume-group>/<logical-volume>

Replace <volume-group> and <logical-volume> with your actual volume group and logical volume names.

3. Run a file system check

It is a good practice to check the integrity of the file system before resizing. Depending on the type of your file system, use the appropriate checking tool. Here, e2fsck is an example for ext-file system:

sudo e2fsck -f /dev/<volume-group>/<logical-volume>

The -f option forces the check even if the file system appears to be clean.

Shrinking the file system

4. Shrink the file system

After making sure the file system is consistent, you can now shrink it. Remember, you must shrink the file system before you can shrink the logical volume. With the resize2fs tool for ext-filesystems, you can resize the file system to a specific size.

sudo resize2fs /dev/<volume-group>/<logical-volume> <desired-size>G

Replace <desired-size> with your target size in gigabytes. Be sure to set a size large enough to hold your data even after resizing.

5. Shrink the Logical Volume

Once the file system has been successfully reduced, you can resize the logical volume. Use the lvreduce command:

sudo lvreduce -L <desired-size>G /dev/<volume-group>/<logical-volume>

To avoid file system damage, make sure the size you specify in lvreduce is the same or larger than the size after using resize2fs.

Post-resizing steps

6. Check the file system

Re-verify the integrity of the file system:

sudo e2fsck /dev/<volume-group>/<logical-volume>

Be sure to resolve any issues before proceeding.

7. Re-mount the file system

If everything looks okay, remount the file system so that it is available for use:

sudo mount /dev/<volume-group>/<logical-volume> /mount/point

Conclusion

Shrinking a filesystem with LVM on Fedora requires careful planning and execution to prevent data loss. It requires you to back up your data, unmount the filesystem, check its integrity, shrink the filesystem, shrink the logical volume accordingly, and make sure everything works properly after remounting the filesystem. While these instructions focus on ext-filesystems, the principles are the same for other types, although the specific commands or tools may differ. Always be sure to understand the steps and verify your backups before attempting filesystem resize operations.

If you find anything wrong with the article content, you can


Comments