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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值