How to Reduce the Size of an LVM Logical Volume
In this article, I’ll show you how to reduce 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 and you must know how to reduce the size of an existing LVM logical volume without loosing your data.
Prerequisites
Shrinking a logical volume is likely to destroy any filesystem located on that volume if you do not make appropriate preparations. If you want to preserve existing files then you will need to:
- reduce the size of the filesystem by the required amount, then
- reduce the size of the underlying block device (the logical volume) to match that of the filesystem.
These instructions cover the second step only. The method for the first step will depend on the type of filesystem. Filesystems that can be shrunk include ext2, ext3, ext4 and reiserfs.
Some filesystems cannot be shrunk, 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.
Scenario
Suppose that /dev/vg0/mimastech is a logical volume of size 120GB. You wish to reduce its size by 40GB to 80GB.
Hint: 1. You must backup the data on the logical volume you want to shrink first.
A logical volume can be shrunk using the lvreduce command. You can specify either the amount by which you want to reduce the size of the volume:
# lvreduce --size -40G /dev/vg0/mimastech
or the final size that you want to achieve:
# lvreduce --size 80G /dev/vg0/mimastech
Because of the high potential for data loss, lvreduce asks for confirmation:
WARNING: Reducing active logical volume to 80.00 GB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce foo? [y/n]:
If the logical volume contains a filesystem that you wish to preserve then you must not make the volume smaller than the filesystem. This would be a good time to check that you have specified:
- the correct volume group and
- the correct size (including units).
If you decide to proceed and the operation is successful then you should see a response of the form:
Reducing logical volume foo to 80.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 CbqMvN-g5pj-OF79-GD1e-xmAA-55Tn-Q0McSe LV Write Access read/write LV Status available # open 0 LV Size 80.00 GB Current LE 20480 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:100
“Snapshot origin volumes cannot be reduced in size” Error
You may face the following error:
Snapshot origin volumes cannot be reduced in size yet.
indicates that one or more snapshots exist of the logical volume that you are attempting to reduce in size. At the time of writing (as of version 2.02.66) LVM did not support this, so if you want to shrink the volume from which the snapshots were made then you will need to delete the snapshots. You can identify them using the lvs command, looking in the column headed ‘Origin’.
Hint: 1. We can use lvresize as an Alternative to lvreduce
An alternative to lvreduce is to use the lvresize command:
# lvresize --size -40G /dev/vg0/mimastech
OR
# lvresize --size 80G /dev/vg0mimastech
The difference is that lvreduce can only reduce the size of a volume, whereas lvresize can increase or reduce it. lvreduce is recommended here because it may catch some errors, but either choice would be reasonable.
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:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.