How to shrink an LVM Logical Volume

How to shrink an LVM Logical Volume

Solution Verified - Updated April 6 2016 at 11:53 PM -

Environment

  • Red Hat Enterprise Linux (RHEL) 5
  • Red Hat Enterprise Linux (RHEL) 6
  • Red Hat Enterprise Linux (RHEL) 7

Issue

  • How Do I Shrink A LVM Logical Volume?
  • I have a 100Gb LVM logical volume. I need another logical volume that is 20Gb. How do I do this?

Resolution

Note 1: Before modifying any system, it is always recommended to create a backup first as there is an elevated risk of data corruption with reducing a LVM size.
Note 2: Some of the file system commands, such as e2fsck and resize2fs, depend on the file system used. For this example, the file system is ext4.

  1. Find the name of the logical volume that you would like to shrink (This example uses logical volume /dev/vg0/lv_data):

    # lvs
    
  2. To perform an lvreduce, the disk must be unmounted, so this must be done when there is no need for activity on the disk. Then run a filesystem check to verify data integrity:

    # umount /dev/vg0/lv_data
    # e2fsck -f /dev/vg0/lv_data
    
  3. [RHEL 5 Only] Resize the existing filesystem to 80Gb (ie: 100Gb - 20Gb = 80Gb):

    # resize2fs /dev/vg0/lv_data 80G
    
  4. Resize the logical volume (Note: On RHEL 6 and 7, the lvreduce command can shrink the file system without the need for step 3 above):

    • RHEL 6 and 7:

      # lvreduce -r -L 80G /dev/vg0/lv_data
      
    • RHEL 5:

      # lvreduce -L 80G /dev/vg0/lv_data
      
  5. Then mount the logical volume again:

    # mount /dev/vg0/lv_data
    
  6. Now the volume group has 20G of free space. You can then use lvcreate to create your new logical volume using the 20G free space.

Root Cause

  • lvreduce shipped with RHEL 5 is missing "-r" option, which takes care of resizing underlying filesystem, hence, resize2fs is mandatory before shrinking logical volume.

猜你喜欢

转载自blog.csdn.net/shenghuiping2001/article/details/54583261