How to Increase the size of an LVM logical volume on Linux systems

undefined

In this article, I’ll show you how to increase the size of a LVM logical volume on Linux systems (RPM Family “Redhat / CentOS  / Scientific Linux” and Debian Family “Debian / Ubuntu” and other families ). As a system administrator, you will face this scenario many times and you must know how to increase the size of an existing LVM logical volume.

Background

Be aware that extending a logical volume does not by itself let you to store more files in a filesystem located on that volume. To successfully increase the size logical volume and this increase propagates to the filesystem, then you will need to do two changes:

  1. increase the size of the underlying block device (the logical volume), then
  2. increase the size of the filesystem to fill the block device.

Here’s we cover the first step only. The method for the second step will depend on the type of filesystem (and in some cases there will be no practicable method). See below for further information.

Scenario

Suppose that /dev/vg0/mimastech is a logical volume of size 80GB. You wish to increase its size by 40GB to 120GB.

A logical volume can be extended using the lvextend command. You can specify either the amount by which you want to increase the size of the volume:

# lvextend --size +40G /dev/vg0/mimastech

or the final size that you want to achieve:

# lvextend --size 120G /dev/vg0/mimastech

If successful you should see a response of the form:

  Extending logical volume mimastech to 8.00 GB
  Logical volume foo successfully resized
  • Testing

Verify the new size of the logical volume using the lvdisplay command:

# lvdisplay /dev/vg0/mimastech

This should give a response of the form:

  --- Logical volume ---
  LV Name                /dev/vg0/mimastech
  VG Name                vg0
  LV UUID                w2q9ZN-hKnN-CLGf-6Z5g-e1QZ-DCKX-1DYZSe
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                120.00 GB
  Current LE             30720
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:85

You should not at this stage expect to see any increase in the amount of usable space within whatever filesystem located on the logical volume, for example, as reported by the df command: it is only the size of the underlying block device that has been changed.

Next steps

If the logical volume contains a filesystem then you will probably now want to extend it to fill the newly available space. Filesystems that can be extended include ext2, ext3, ext4, jfs, reiserfs and xfs. See:

Some filesystems cannot be extended, either because their design makes this impracticable or because the necessary software has not been written. In that case your only option is to move the files somewhere else, then recreate the filesystem, then move the files back.

Hint:
1. We can use lvresize as an Alternative to lvextend.

An alternative to lvextend is to use the lvresize command:

# lvresize --size +40G /dev/vg0/mimastech

OR

# lvresize --size 120G /dev/vg0/mimastech

The difference is that lvextend can only increase the size of a volume, whereas lvresize can increase or reduce it. This makes lvresize more powerful but more dangerous. If you accidentally reduce the size of a volume without first reducing the size of the filesystem contained within it then the filesystem is likely to be damaged irreparably. For scenarios similar to the one described here, lvextend is recommended because mistakes of this type are not then possible.

Summary

In this article, we have explained how to to reduce the size of a LVM logical volume on Linux systems by using both lvreduce and lvresize. Actually, it’s too rare for any systems administrator to reduce a logical volume “for me I always increase the size of a logical volumes”. You MUST backup your existing data first before reducing the size of your logical volumes .

I hope this article is good enough for you.
See you in other articles.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

One Comment to How to Increase the size of an LVM logical volume on Linux systems

Leave a Reply

Your email address will not be published. Required fields are marked *