System and processes
The lvreduce command
Reduces the size of an LVM logical volume. It is the most delicate LVM operation: if the volume ends up smaller than the data it holds, information is lost.
Most useful options
-L TAMAÑOFinal size of the volume. With -L -5G it reduces 5 GB from the current size-rResizes the filesystem on the volume first so that it fits-tTest mode: runs the checks without changing anything-fDoes not ask for confirmation. Use it only in reviewed scriptsCopy-ready examples
$ sudo lvreduce -t -L 80G /dev/vg_datos/lv_fotossimulates the reduction to 80 GB without touching anything. Always run this test first.$ sudo lvreduce -r -L -20G /dev/vg_datos/lv_fotosremoves 20 GB: it shrinks the filesystem first and then the volume.$ sudo lvs vg_datoschecks the sizes before and after, in the LSize column.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| THIS MAY DESTROY YOUR DATA (filesystem etc.) | The final size is smaller than the data the filesystem already uses. Information is cut off. | Calculate the used space with df -h before shrinking and leave a margin. |
| resize2fs: On-line shrinking not supported | The ext4 filesystem is mounted. To shrink ext4 it must be unmounted first. | Unmount the volume and check the filesystem with e2fsck before shrinking. |
| WARNING: Running as a non-root user. Functionality may be unavailable. | You do not have administrator rights. | Put sudo in front of the command. |
Typical mistakes
- Shrinking the volume does not shrink the filesystem inside it. Both steps must be done in order, unless you use -r.
- The freed space returns to the volume group and becomes available to other volumes, not to the system.
- Some filesystems, such as XFS, can never be shrunk. Check the type before trying.
Differences from similar commands
- lvextend: enlarges a volume. It is the opposite operation and much safer.
lvresize: enlarges or shrinks depending on the sign of the size. When shrinking, the same precautions as with lvreduce apply.resize2fs: changes the size of the ext filesystem, not of the volume. When shrinking by hand it runs before lvreduce.
Security
Reducing a volume can erase data without warning if the filesystem uses more space than remains. Back up first, test with -t and check the filesystem with e2fsck. A mistake here can be irreversible.
FAQ
How do I shrink an ext4 volume without losing data?
Unmount it, check it with e2fsck, shrink the filesystem with resize2fs and then the volume with lvreduce.
Can I shrink a mounted volume?
With ext4 it must be unmounted. XFS does not support shrinking.
What happens to the space I free?
It returns to the volume group, and you can assign it to another volume with lvextend.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course