How to shrink LVM size?

To shrink the size of a Logical Volume (LVM) in Linux, follow these steps:

1. Check Filesystem Usage

Before shrinking, ensure that the filesystem is not using more space than you plan to allocate. You can check this with:

df -h /dev/vg_name/lv_name

2. Resize the Filesystem

You need to reduce the filesystem size before reducing the logical volume. For example, if you're using ext4, you can do this with:

sudo resize2fs /dev/vg_name/lv_name [new_size]

3. Shrink the Logical Volume

After resizing the filesystem, you can shrink the logical volume using:

sudo lvresize -L [new_size] /dev/vg_name/lv_name

Example:

To shrink a logical volume to 300 MB:

sudo resize2fs /dev/vg_name/lv_name 300M  # Resize filesystem first
sudo lvresize -L 300M /dev/vg_name/lv_name  # Then shrink the logical volume

Important Notes:

  • Always back up important data before performing these operations.
  • Ensure the new size is larger than the used space in the filesystem to avoid data loss.

If you have further questions or need clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!