How to Extend/Reduce LVM’s (Logical Volume Management) in Linux – Part II

Previously we have seen how to create a flexible disk storage using LVM. Here, we are going to see how to extend volume group, extend and reduce a logical volume. Here we can reduce or extend the partitions in Logical volume management (LVM) also called as flexible volume file-system.

Extend/Reduce LVMs in Linux

Extend/Reduce LVMs in Linux

Requirements
  1. Create Flexible Disk Storage with LVM – Part I
When do we need to reduce volume?

May be we need to create a separate partition for any other use or we need to expand the size of any low space partition, if so we can reduce the large size partition and we can expand the low space partition very easily by the following simple easy steps.

My Server Setup – Requirements
  1. Operating System – CentOS 6.5 with LVM Installation
  2. Server IP – 192.168.0.200

How to Extend Volume Group and Reduce Logical Volume

Logical Volume Extending

Currently, we have One PV, VG and 2 LV. Let’s list them one by one using following commands.

# pvs
# vgs
# lvs
Logical Volume Extending

Logical Volume Extending

There are no free space available in Physical Volume and Volume group. So, now we can’t extend the lvm size, for extending we need to add one physical volume (PV), and then we have to extend the volume group by extending the vg. We will get enough space to extend the Logical volume size. So first we are going to add one physical volume.

For adding a new PV we have to use fdisk to create the LVM partition.

# fdisk -cu /dev/sda
  1. To Create new partition Press n.
  2. Choose primary partition use p.
  3. Choose which number of partition to be selected to create the primary partition.
  4. Press 1 if any other disk available.
  5. Change the type using t.
  6. Type 8e to change the partition type to Linux LVM.
  7. Use p to print the create partition ( here we have not used the option).
  8. Press w to write the changes.

Restart the system once completed.

Create LVM Partition

Create LVM Partition

List and check the partition we have created using fdisk.

# fdisk -l /dev/sda
Verify LVM Partition

Verify LVM Partition

Next, create new PV (Physical Volume) using following command.

# pvcreate /dev/sda1

Verify the pv using below command.

# pvs
Create Physical Volume

Create Physical Volume

Extending Volume Group

Add this pv to vg_tecmint vg to extend the size of a volume group to get more space for expanding lv.

# vgextend vg_tecmint /dev/sda1

Let us check the size of a Volume Group now using.

# vgs
Extend Volume Group

Extend Volume Group

We can even see which PV are used to create particular Volume group using.

# pvscan
Check Volume Group

Check Volume Group

Here, we can see which Volume groups are under Which Physical Volumes. We have just added one pv and its totally free. Let us see the size of each logical volume we have currently before expanding it.

Check All Logical Volume

Check All Logical Volume

  1. LogVol00 defined for Swap.
  2. LogVol01 defined for /.
  3. Now we have 16.50 GB size for / (root).
  4. Currently there are 4226 Physical Extend (PE) available.

Now we are going to expand the / partition LogVol01. After expanding we can list out the size as above for confirmation. We can extend using GB or PE as I have explained it in LVM PART-I, here I’m using PE to extend.

For getting the available Physical Extend size run.

# vgdisplay
Check Available Physical Size

Check Available Physical Size

There are 4607 free PE available = 18GB Free space available. So we can expand our logical volume up-to 18GBmore. Let us use the PE size to extend.

# lvextend -l +4607 /dev/vg_tecmint/LogVol01

Use + to add the more space. After Extending, we need to re-size the file-system using.

# resize2fs /dev/vg_tecmint/LogVol01
Expand Logical Volume

Expand Logical Volume

  1. Command used to extend the logical volume using Physical extends.
  2. Here we can see it is extended to 34GB from 16.51GB.
  3. Re-size the file system, If the file-system is mounted and currently under use.
  4. For extending Logical volumes we don’t need to unmount the file-system.

Now let’s see the size of re-sized logical volume using.

# lvdisplay
Resize Logical Volume

Resize Logical Volume

  1. LogVol01 defined for / extended volume.
  2. After extending there is 34.50GB from 16.50GB.
  3. Current extends, Before extending there was 4226, we have added 4607 extends to expand so totally there are 8833.

Now if we check the vg available Free PE it will be 0.

# vgdisplay

See the result of extending.

# pvs
# vgs
# lvs
Verify Resize Partition

Verify Resize Partition

  1. New Physical Volume added.
  2. Volume group vg_tecmint extended from 17.51GB to 35.50GB.
  3. Logical volume LogVol01 extended from 16.51GB to 34.50GB.

Here we have completed the process of extending volume group and logical volumes. Let us move towards some interesting part in Logical volume management.

Reducing Logical Volume (LVM)

Here we are going to see how to reduce the Logical Volumes. Everyone say its critical and may end up with disaster while we reduce the lvm. Reducing lvm is really interesting than any other part in Logical volume management.

  1. Before starting, it is always good to backup the data, so that it will not be a headache if something goes wrong.
  2. To Reduce a logical volume there are 5 steps needed to be done very carefully.
  3. While extending a volume we can extend it while the volume under mount status (online), but for reduce we must need to unmount the file system before reducing.

Let’s wee what are the 5 steps below.

  1. unmount the file system for reducing.
  2. Check the file system after unmount.
  3. Reduce the file system.
  4. Reduce the Logical Volume size than Current size.
  5. Recheck the file system for error.
  6. Remount the file-system back to stage.

For demonstration, I have created separate volume group and logical volume. Here, I’m going to reduce the logical volume tecmint_reduce_test. Now its 18GB in size. We need to reduce it to 10GB without data-loss. That means we need to reduce 8GB out of 18GB. Already there is 4GB data in the volume.

18GB ---> 10GB

While reducing size, we need to reduce only 8GB so it will roundup to 10GB after the reduce.

# lvs
Reduce Logical Volume

Reduce Logical Volume

Here we can see the file-system information.

# df -h
Check File System Size

Check File System Size

  1. The size of the Volume is 18GB.
  2. Already it used upto 3.9GB.
  3. Available Space is 13GB.

First unmount the mount point.

# umount -v /mnt/tecmint_reduce_test/
Unmount Parition

Unmount Parition

Then check for the file-system error using following command.

# e2fsck -ff /dev/vg_tecmint_extra/tecmint_reduce_test
Scan Parition for Errors

Scan Parition for Errors

Note: Must pass in every 5 steps of file-system check if not there might be some issue with your file-system.

Next, reduce the file-system.

# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test 8GB
Reduce File System

Reduce File System

Reduce the Logical volume using GB size.

# lvreduce -L -8G /dev/vg_tecmint_extra/tecmint_reduce_test
Reduce Logical Partition

Reduce Logical Partition

To Reduce Logical volume using PE Size we need to Know the size of default PE size and total PE size of a Volume Group to put a small calculation for accurate Reduce size.

# lvdisplay vg_tecmint_extra

Here we need to do a little calculation to get the PE size of 10GB using bc command.

1024MB x 10GB = 10240MB or 10GB

10240MB / 4PE = 2048PE

Press CRTL+D to exit from BC.

Calculate PE Size

Calculate PE Size

Reduce the size using PE.

# lvreduce -l -2048 /dev/vg_tecmint_extra/tecmint_reduce_test
Reduce Size Using PE

Reduce Size Using PE

Re-size the file-system back, In this step if there is any error that means we have messed-up our file-system.

# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test
Resize File System

Resize File System

Mount the file-system back to same point.

# mount /dev/vg_tecmint_extra/tecmint_reduce_test /mnt/tecmint_reduce_test/
Mount File System

Mount File System

Check the size of partition and files.

# lvdisplay vg_tecmint_extra

Here we can see the final result as the logical volume was reduced to 10GB size.

Verify Logical Volume Size

Verify Logical Volume Size

In this article, we have seen how to extend the volume group, logical volume and reduce the logical volume. In the next part (Part III), we will see how to take a Snapshot of logical volume and restore it to earlier stage.

Reference: http://www.tecmint.com/extend-and-reduce-lvms-in-linux/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 智慧社区背景与挑战 随着城市化的快速发展,社区面临健康、安全、邻里关系和服务质量等多方面的挑战。华为技术有限公司提出智慧社区解决方案,旨在通过先进的数字化技术应对这些问题,提升城市社区的生活质量。 2. 技术推动智慧社区发展 技术进步,特别是数字化、无线化、移动化和物联化,为城市社区的智慧化提供了可能。这些技术的应用不仅提高了社区的运行效率,也增强了居民的便利性和安全性。 3. 智慧社区的核心价值 智慧社区承载了智慧城市的核心价值,通过全面信息化处理,实现对城市各个方面的数字网络化管理、服务与决策功能,从而提升社会服务效率,整合社会服务资源。 4. 多层次、全方位的智慧社区服务 智慧社区通过构建和谐、温情、平安和健康四大社区模块,满足社区居民的多层次需求。这些服务模块包括社区医疗、安全监控、情感沟通和健康监测等。 5. 智慧社区技术框架 智慧社区技术框架强调统一平台的建设,设立数据中心,构建基础网络,并通过分层建设,实现平台能力及应用的可持续成长和扩展。 6. 感知统一平台与服务方案 感知统一平台是智慧社区的关键组成部分,通过统一的RFID身份识别和信息管理,实现社区服务的智能化和便捷化。同时,提供社区内外监控、紧急救助服务和便民服务等。 7. 健康社区的构建 健康社区模块专注于为居民提供健康管理服务,通过整合医疗资源和居民接入,实现远程医疗、慢性病管理和紧急救助等功能,推动医疗模式从治疗向预防转变。 8. 平安社区的安全保障 平安社区通过闭路电视监控、防盗报警和紧急求助等技术,保障社区居民的人身和财产安全,实现社区环境的实时监控和智能分析。 9. 温情社区的情感沟通 温情社区着重于建立社区居民间的情感联系,通过组织社区活动、一键呼叫服务和互帮互助平台,增强邻里间的交流和互助。 10. 和谐社区的资源整合 和谐社区作为社会资源的整合协调者,通过统一接入和身份识别,实现社区信息和服务的便捷获取,提升居民生活质量,促进社区和谐。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值