====== Ubuntu - LVM - Reduce the size of an LVM logical volume ====== To reduce the size of an existing LVM logical volume ---- ===== 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. 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/vg01/foo or the final size that you want to achieve: lvreduce --size 80G /dev/vg01/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 ---- ===== Testing ===== Verify the new size of the logical volume using the **lvdisplay** command: lvdisplay /dev/vg01/foo This should give a response of the form: --- Logical volume --- LV Name /dev/vg01/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 ---- ===== Troubleshooting ===== * [[Ubuntu:LVM:Troubleshooting LVM|Troubleshooting LVM]] ---- ===== Errors ===== ==== Snapshot origin volumes cannot be reduced in size ==== The 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**'. ===== Alternatives ===== ==== lvresize ==== An alternative to **lvreduce** is to use the **lvresize** command: lvresize --size -40G /dev/vg01/foo or: lvresize --size 80G /dev/vg01/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. ---- ===== See also ===== * [[Ubuntu:Filesystem:Reduce the size of an ext2, ext3 or ext4 filesystem|Reduce the size of an ext2, ext3 or ext4 filesystem]] * [[Ubuntu:LVM:Increase the size of an LVM logical volume|Increase the size of an LVM logical volume]]