System and processes

The lvextend command

Grows a logical volume using the free space of its volume group.

Syntax

sudo lvextend [opciones] -L +<tamaño> /dev/<grupo>/<lv>Try it in the terminal →

Most useful options

-L +tamañoSize of the volume, in gigabytes or megabytes. With + it is added to the current size: +2G adds 2 GB; without the sign it is the final size.
-l +extensionesLike -L, but in logical extents. It accepts percentages such as +100%FREE to use all the free space.
-rAlso grows the filesystem, so you do not have to do it by hand.
-nSkips the fsck before resizing when the filesystem asks for one. You may need -f.
-tTest mode: checks the operation without writing metadata.
-fSkips checks and protections. Use it with extreme caution.

Copy-ready examples

$ sudo vgschecks the free space of the group before extending.
$ sudo lvextend -t -L +2G /dev/datos/websimulates the 2 GB extension without touching anything. Run this test first.
$ sudo lvextend -L +2G /dev/datos/webadds 2 GB to the web volume.
$ sudo lvextend -r -L +2G /dev/datos/webadds 2 GB and also grows the filesystem it holds.
$ sudo lvextend -l +100%FREE /dev/datos/webuses all the free space in the group for the web volume.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
Insufficient free space: 512 extents needed, but only 0 availableYou asked for more extents than the group has free. The numbers change from case to case.Check the free space with sudo vgs, ask for less or add a disk with vgextend.
Please specify either size or extents but not both.You used -L and -l at the same time.Keep only one of the two options.

Typical mistakes

  • With -L +2G, the 2G are added to the current size. Without the + sign you give the final size of the volume.
  • Without -r the volume grows, but the filesystem inside it keeps its old size. It must be grown too.
  • If the group has no free space, the operation fails. Add a PV with vgextend first.

Differences from similar commands

  • lvreduce: shrinks the volume. It is the opposite operation and much more delicate.
  • 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. lvextend changes the volume.

FAQ

What does lvextend do?

It reserves more extents from the group for the volume. The data it already holds is not modified.

And the filesystem?

With -r, lvextend grows it too. Without -r, you have to do it yourself afterwards.

How do I say how much to grow?

With +, for example -L +2G or -l +100%FREE. Without the sign, the number is the final size of the volume.

More System and processes commands

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