Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

lvextend

Make a logical volume bigger — with -r also its file system, while it stays mounted.

Level
RHCSA exam
Group
LVM
Needs root
Yes
Package
lvm2
Also called
lvresize

What it does

lvextend -L +SIZE adds space; -L SIZE sets the total size; -l +N / -l +100%FREE work with extents. The VG needs enough free space (add disks with vgextend).

Always add -r (--resizefs): it runs xfs_growfs or resize2fs after the LV grew. Without it the file system keeps its old size. lvresize can grow and shrink with the same options.

How to write it

lvextend (-L [+]SIZE | -l [+]EXTENTS) [-r] [OPTION]... VG/LV [PV...]
lvresize (-L [+|-]SIZE | -l [+|-]EXTENTS) [-r] [OPTION]... VG/LV

Options 28

Most used

-L, --size [+]SIZE
New size or + added size, like +2G or 10G.
-l, --extents [+]N[%VG|%LV|%PVS|%FREE|%ORIGIN]
In extents or percent, like +100%FREE.
-r, --resizefs
Also grow the file system.
-n, --nofsck
Do not check the file system before resizing.
--fs checksize|resize|resize_fsadm|ignore
How to handle the file system (newer lvm2).
--fsmode manage|offline|nochange
May LVM mount or unmount for the resize (newer lvm2).
-i, --stripes N, -I, --stripesize SIZE
Stripes for the new part.
-m, --mirrors N
Mirrors (mirror LVs).
--alloc POLICY
Allocation policy.
--poolmetadatasize [+]SIZE
Grow the metadata of a thin pool.
--type TYPE
Segment type.
--nosync
Do not sync new mirror parts.
--usepolicies
Use the autoextend policy from lvm.conf (thin pools, snapshots).
-f, --force
Do not ask.
-A, --autobackup y|n
Back up the metadata.
--noudevsync
Do not wait for udev.
--reportformat basic|json
Output format.

Common LVM options

-t, --test
Test only; change nothing.
-v, --verbose
More output (repeat for more).
-q, --quiet
Less output.
-y, --yes
Answer yes to questions.
-d, --debug
Debug output.
--config STRING
Override lvm.conf settings for this command only.
--commandprofile STRING, --profile STRING
Use a configuration profile.
--devices PV, --devicesfile STRING
Limit the devices LVM looks at.
--driverloaded y|n, --nolocking, --lockopt STRING, --nohints, --journal STRING
Special and debug settings.
-h, --help, --longhelp
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Add 2 GiB with the file system

    lvextend -r -L +2G /dev/vgdata/lvdata
      Size of logical volume vgdata/lvdata changed from 5.00 GiB to 7.00 GiB.
      Logical volume vgdata/lvdata successfully resized.

    Works online for XFS and ext4.

  2. 2Set a total size

    lvextend -r -L 10G /dev/vgdata/lvdata

    10 GiB in total (no +).

  3. 3Use all free space in the VG

    lvextend -r -l +100%FREE /dev/vgdata/lvweb

    Common after vgextend.

  4. 4Add extents

    lvextend -r -l +25 /dev/vgfiles/lvfiles

    25 × PE size.

  5. 5Check the result

    df -h /data; lvs vgdata

    df must show the new size too.

  6. 6Forgot -r? Grow the file system later

    xfs_growfs /data
    resize2fs /dev/vgdata/lvweb

    XFS by mount point, ext4 by device.

  7. 7Grow the root file system

    lvextend -r -L +5G /dev/rhel/root

    Online, no reboot.

  8. 8Grow a swap LV

    swapoff /dev/rhel/swap; lvextend -L +1G /dev/rhel/swap; mkswap /dev/rhel/swap; swapon -a

    Swap must be recreated (check that the UUID in fstab still matches, or use the LV path).

  9. 9Only use space of a chosen PV

    lvextend -r -L +2G /dev/vgdata/lvdata /dev/vdd

    New extents come from vdd.

  10. 10Grow a thin pool before it fills

    lvextend -L +5G vgdata/pool1

    A full thin pool stops all writes in its volumes.

Watch out

  • Without -r: LV bigger, file system not. df -h shows the problem.
  • "Insufficient free space": add a PV with vgextend first.

Exit codes

0Done.
5Error.