Reduce the size of an LVM logical volume
|Debian (Etch, Lenny, Squeeze)|
|Ubuntu (Lucid, Maverick, Natty)|
To reduce the size of an existing LVM logical volume
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.
/dev/vg0/foo is a logical volume of size 120GB. You wish to reduce its size by 40GB to 80GB.
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/foo
or the final size that you want to achieve:
lvreduce --size 80G /dev/vg0/foo
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
Verify the new size of the logical volume using the
This should give a response of the form:
--- Logical volume --- LV Name /dev/vg0/foo VG Name vg0 LV UUID CbqMvN-g5pj-OF79-GD1e-xmAA-55Tn-Q0McFc 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
See Troubleshooting LVM.
Snapshot origin volumes cannot be reduced in size
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’.
An alternative to
lvreduce is to use the
lvresize --size -40G /dev/vg0/foo
lvresize --size 80G /dev/vg0/foo
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.