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 18GB more. 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

<span style="font-style: inherit; font-variant: inherit; font-stretch: inherit

  • 95 Users Found This Useful
這篇文章有幫助嗎?

相關文章

S.M.A.R.T (smartctl) commands and test

Installation of Smartcl in Ubuntu $ sudo apt-get install smartmontools Installation of Smartcl...

How to: Replacing a failed drive in a Linux Software RAID1 configuration (mdraid)

Scenario: A drive has failed in your linux RAID1 configuration and you need to replace it....

Check disk details

lsblk -o name,label,size,fstype,mountpoint,modefdisk -l

How to Increase the size of a Linux LVM by expanding the Disk

This post will cover how to increase the disk space for a VMware virtual machine running Linux...

Setup Flexible Disk Storage with Logical Volume Management (LVM) in Linux – PART 1

Logical Volume Management (LVM) makes it easier to manage disk space. If a file system needs more...

Powered by WHMCompleteSolution