Sub topic 6
Extending the Logical Volume
This chapter covers the lvextend step: enlarging a logical volume (LV) so it takes up free extents in its volume group (VG). It assumes you can use sudo on the command line, know what a block device, partition and mount point are, and can read df and lsblk output. It also assumes you have already met physical volumes (PVs), volume groups and logical volumes in the earlier chapters.
By the end you should be able to choose between -L and -l, predict how much space a command will add, restrict which disks the new space comes from, and recognize the errors that lvextend reports.
What lvextend changes, and what it does not
An LV is a mapping from a contiguous range of logical addresses to extents on one or more PVs. lvextend adds extents to that mapping. It updates the LVM metadata and the device-mapper table, and the block device /dev/vg_data/lv_app becomes larger immediately, while it is in use.
The filesystem on top of the LV knows nothing about this. df will still report the old size until the filesystem is grown, which the next chapter covers. Treat the work as two separate operations:
- Make the block device bigger (
lvextend). - Make the filesystem fill the block device (
resize2fsorxfs_growfs).
Growing an LV is safe on a mounted, busy volume. No data moves, and nothing is rewritten. Only new extents are appended.
Check the free space first
lvextend can only use extents that are free in the volume group. Before you run it, confirm how much there is.
sudo vgs vg_data
sudo lvs vg_dataIn the vgs output, the VFree column is the unallocated space. If VFree is smaller than what you asked for, the command fails and changes nothing. If it is zero, you must first add capacity with pvcreate and vgextend, or pvresize on an enlarged disk, as described in the previous chapters.
For exact numbers, ask for specific units and fields:
sudo vgs --units g -o vg_name,vg_size,vg_free,vg_extent_size vg_data
sudo lvs --units g -o lv_name,lv_size,lv_path vg_dataThe extent size matters because all LVM sizes are rounded to whole extents. The default is 4 MiB.
Specifying the size: -L versus -l
There are two options that set the size, and they take different kinds of values.
| Option | Long form | Unit of the value | Example |
|---|---|---|---|
| `-L` | `--size` | Bytes, with a suffix such as `M`, `G`, `T` | `-L +20G` |
| `-l` | `--extents` | Extents, or a percentage | `-l +100%FREE` |
The sign in front of the value changes its meaning:
- With a
+, the value is added to the current size.-L +20Gmeans "make it 20 GiB bigger." - With no sign, the value is the final size.
-L 120Gmeans "make it exactly 120 GiB."
Mixing these up is a common mistake. If the LV is 100 GiB, -L 20G asks for an LV of 20 GiB. lvextend refuses, because the new size is smaller than the current one. The command is safe for this reason: it never shrinks a volume. lvreduce does that, and it is a different and riskier tool.
Growing by a fixed amount
sudo lvextend -L +20G /dev/vg_data/lv_appThe path can be written as /dev/vg_data/lv_app or as vg_data/lv_app. Both name the same LV. A successful run prints something like this:
Size of logical volume vg_data/lv_app changed from 100.00 GiB (25600 extents) to 120.00 GiB (30720 extents).
Logical volume vg_data/lv_app successfully resized.Growing to an absolute size
sudo lvextend -L 150G /dev/vg_data/lv_appThis is useful in scripts, because running it twice gives the same result. If the LV is already 150 GiB, LVM reports that the size is unchanged and exits with an error status rather than growing again. A +20G command, by contrast, adds 20 GiB every time it runs.
Growing by a share of free space
Percentages work with -l, and the suffix decides what the percentage refers to:
| Value | Meaning |
|---|---|
| `+100%FREE` | Add all remaining free extents in the VG |
| `+50%FREE` | Add half of the free extents |
| `+25%VG` | Add 25% of the total size of the VG |
| `100%VG` | Make the LV as large as the whole VG (only possible if nothing else uses it) |
| `+10%ORIGIN` | Used with snapshots, relative to the origin volume |
The most common form is:
sudo lvextend -l +100%FREE /dev/vg_data/lv_appUse it when this LV is the only one in the VG that needs to grow. If other LVs will need room later, take a fixed amount instead, so you keep a reserve. A VG with some free space left over is also what lets you create a snapshot when you need one.
Rounding
LVM works in whole extents. If you ask for +20G and the extent size is 4 MiB, the amount divides evenly. If you ask for +10M, LVM rounds up to the next multiple of the extent size, which is 12 MiB. The lvextend output reports the actual new size, so read it.
Restricting which disks supply the space
When the VG spans more than one PV, you can name the PV that the new extents must come from by adding it at the end of the command:
sudo lvextend -L +50G /dev/vg_data/lv_app /dev/sdcThis is useful in two cases. First, you may want the new space on a faster disk, or you may want to keep a database off a disk that another workload uses heavily. Second, you may want to avoid a disk you plan to remove from the VG later with pvmove and vgreduce.
If the named PV has fewer free extents than you asked for, the command fails with an insufficient free space message. It does not fall back to other PVs.
The allocation policy of the LV also matters. The default, normal, places new extents wherever there is room. A contiguous policy requires the new extents to sit directly after the existing ones, and lvextend fails when that cannot be done. You can see the policy with lvs -o +lv_allocation_policy.
Layouts that behave differently
The examples so far assume a linear LV, which is the common case. Other layouts follow extra rules.
- Striped LVs spread data across several PVs. To extend one, the new space must come from as many PVs as there are stripes, and each needs enough free extents. A striped LV over two disks cannot grow if only one disk has free space. A message about insufficient suitable allocatable extents is the usual sign.
- Mirrored or RAID LVs need free space on enough PVs to hold each leg. Extending a RAID1 LV by 10 GiB consumes 10 GiB on each leg, so you need 20 GiB free in total, in the right places.
- Thin volumes are extended the same way, but the size you set is the virtual size. It does not consume space in the thin pool until data is written. The pool itself must be extended separately, for example with
lvextend -L +50G vg_data/pool0. Over-provisioning a pool is a risk covered in the safety chapter. - Snapshots of the LV are not affected by growing the origin, but the snapshot's own copy-on-write area may fill up and invalidate it if the origin is written heavily. Check
lvsfor theData%column.
Using lvextend with the filesystem option
You can add -r (--resizefs) to have lvextend call the correct filesystem tool for you after the LV has grown. That is covered in its own chapter. For now, keep in mind that without -r the LV is larger and the filesystem is not, which is a valid and temporary state.
A complete worked example
A server has a volume group vg_data with one logical volume lv_app, mounted at /srv/data. The mount is filling up.
First, inspect:
sudo vgs --units g -o vg_name,vg_size,vg_free vg_data
sudo lvs --units g -o lv_name,lv_size vg_data
df -hT /srv/dataSuppose this shows a VG with 30 GiB free and an LV of 100 GiB. We want to add 20 GiB and keep 10 GiB in reserve.
Extend the LV:
sudo lvextend -L +20G /dev/vg_data/lv_appThen look at both layers:
sudo lvs --units g -o lv_name,lv_size vg_data
df -h /srv/datalvs now reports 120 GiB. df still reports the old size (around 100 GiB, less filesystem overhead). That mismatch confirms step one is done and step two is still to do.
You can also see the new device size directly:
sudo blockdev --getsize64 /dev/vg_data/lv_appThis prints the size in bytes. 120 GiB is 128849018880 bytes.
Common errors and what they mean
| Message (abridged) | Cause | Fix |
|---|---|---|
| `Insufficient free space: 5120 extents needed, but only 2560 available` | The VG does not have enough free extents | Add a PV, use `pvresize`, or ask for less |
| `New size (…) matches existing size` or `Unable to reduce` | You used `-L` without `+` and gave a value that is equal to or less than the current size | Add `+`, or give a larger absolute size |
| `Volume group "vg_data" not found` | Wrong VG name or the VG is not active | Check `sudo vgs` and the spelling |
| `Failed to find logical volume` | Wrong LV name or path | Check `sudo lvs` |
| `Insufficient suitable allocatable extents for logical volume` | A striped, RAID, or `contiguous` allocation cannot be satisfied | Free space on more PVs, or change the allocation policy |
| `Cannot extend ... partial` or a missing PV warning | A PV in the VG is missing | Restore the disk before changing anything |
| `Logical volume ... is not active` | The LV is deactivated | Activate it with `lvchange -ay` |
If you are unsure what a command will do, run it with --test. Nothing is written, and LVM reports what it would do:
sudo lvextend --test -L +20G /dev/vg_data/lv_appHabits that keep this safe
- Read
vgsbefore and after. The change inVFreeshould match what you intended. - Prefer a
+size over an absolute size when you are working by hand, and prefer an absolute size in automation that may be re-run. - Keep a reserve in the VG unless there is a reason not to. Free extents are the only way to grow any LV quickly, and they are needed for snapshots and
pvmove. - Take a backup or a snapshot before changing storage that holds data you cannot recreate. Growing is low-risk, but a typo in a neighboring command such as
lvreduceorlvremoveis not. - Avoid running resize operations on several LVs in the same VG at once. Metadata updates are serialized with locks, but a script that assumes a certain amount of free space can be wrong if another job takes it.
Summary of the decision
- Need a specific amount more:
-L +SIZE. - Need an exact final size:
-L SIZEwith no sign. - Want everything that is left:
-l +100%FREE. - Want part of what is left:
-l +50%FREE. - Need the space on a particular disk: add the PV path to the end of the command.
- Unsure: add
--testfirst.
Exercise
A volume group has 40 GiB free. The logical volume lvlogs is 60 GiB. You run `sudo lvextend -L 80G /dev/vgdata/lvlogs and then, separately, sudo lvextend -L +80G /dev/vgdata/lv_logs`. What happens in each case, and what is the LV's size afterwards if each command succeeds or fails?
Show answer
The first command succeeds. With no sign, 80G is the final size, so the LV grows by 20 GiB to 80 GiB and 20 GiB remains free. The second command asks to add 80 GiB, but only 20 GiB is free, so it fails with an insufficient free space error and changes nothing. The LV stays at 80 GiB.
Exercise
You want lvapp to take half of the free space in vgdata, and you want the new extents to come from /dev/sdc only. Write the command, and name one command that shows afterwards which PVs back the LV.
Show answer
sudo lvextend -l +50%FREE /dev/vgdata/lvapp /dev/sdc. Note that the percentage is calculated from the free space of the VG, but the allocation is limited to /dev/sdc, so the command fails if /dev/sdc has fewer free extents than that. To see the backing PVs, run sudo lvs -o +devices vg_data.
Exercise
After a successful lvextend, lvs shows the LV at 120 GiB but df -h shows the mount at 98 GiB. Is something broken?
Show answer
No. lvextend changed only the block device. The filesystem has not been grown yet. Run resize2fs for ext4, xfs_growfs for XFS, or use lvextend -r next time, then confirm with df.