Sub topic 2
Reading the Current Layout Before Changing Anything
This chapter covers the read-only commands you run before you resize anything. It assumes you can use the Linux command line with sudo, know what block devices, partitions, and mount points are, and can read df and lsblk output. It also assumes you have met the PV, VG, and LV layering from the previous chapter. Nothing here changes the disk. You can run every command on a production server.
Why look before you change
Every resize command acts on a name: a disk, a volume group, a logical volume, or a mount point. If the name is wrong, the command fails or, worse, succeeds on the wrong object. A typo in pvcreate /dev/sdc can destroy data on a disk you thought was empty. The inspection step answers four questions:
- Which logical volume sits under the mount point that is filling up?
- Which volume group does that logical volume belong to?
- Which physical disks or partitions supply that volume group?
- What filesystem is on the volume, and how full is it?
If the volume group already has free space, you can skip adding a disk. If the mount point is not on LVM at all, none of the later chapters apply, and you need to find that out now.
The commands and what each answers
| Command | Question it answers | Columns to read first |
|---|---|---|
| `df -hT /srv/data` | Which device is mounted here, what filesystem is it, and how full is it? | Filesystem, Type, Size, Avail, Use% |
| `lvs` | Which logical volumes exist and how large are they? | LV, VG, Attr, LSize |
| `vgs` | How much space does each volume group have, and how much is unallocated? | VG, #PV, #LV, VSize, VFree |
| `pvs` | Which devices back each volume group, and how much of each is unused? | PV, VG, PSize, PFree |
| `lsblk -f` | How do disks, partitions, LVM devices, filesystems, and mount points nest? | NAME, FSTYPE, MOUNTPOINTS |
pvs, vgs, and lvs usually need root, so run them with sudo. Without it they often print permission warnings or nothing.
Work from the mount point down
Start at the symptom, the full mount point, and follow the stack down toward the hardware. The order below is the reverse of the order you will later build capacity: you grow from the disk up.
The commands from the Topic Spine run in this order:
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/dataYou can run them in any order. Reading them in the order of the diagram is easier because each result tells you what to look for in the next one.
Step 1: identify the device with df
df -hT /srv/dataFilesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_data-lv_app ext4 79G 61G 14G 81% /srv/dataThree facts come out of this single line.
- The device path shows whether LVM is involved. A path under
/dev/mapper/or/dev/<vg>/means a logical volume. A path like/dev/sda2or/dev/nvme0n1p1means the filesystem sits directly on a partition, and LVM commands will not help. - The Type column picks the grow tool later.
ext4usesresize2fs.xfsusesxfs_growfs. - Size is smaller than the logical volume. An 80 GiB volume shows about 79G here because the filesystem keeps some space for its own metadata. The Avail value is also lower than Size minus Used, because ext4 reserves 5% of blocks for root by default.
The device mapper name vg_data-lv_app joins the volume group and logical volume names with a hyphen. If either name contains a hyphen, the mapper name doubles it. A volume named lv-app in group vg-data appears as vg--data-lv--app. The same volume is also reachable at /dev/vg-data/lv-app, and that form is the easier one to read and type.
If the mount point is not obvious, findmnt prints the source device directly:
findmnt -no SOURCE,FSTYPE /srv/data/dev/mapper/vg_data-lv_app ext4findmnt also resolves cases where a path is a subdirectory of a larger mount, such as /srv/data/uploads inside /srv/data. Always check the mount that actually contains the full path.
Step 2: name the logical volume with lvs
sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_app vg_data -wi-ao---- 80.00g
lv_logs vg_data -wi-ao---- 10.00gMatch the LV and VG from the df path: vg_data-lv_app is the LV lv_app in the group vg_data. Note the LSize of 80.00g. This is the number lvextend will change, and df will not follow it until the filesystem is grown as well.
The Pool, Origin, Data%, and the later columns are empty because these are plain (linear) volumes. If you see values in Pool or Data%, the volume is a thin volume or a snapshot, and its sizing rules differ from what this tutorial covers.
To see which physical device each volume lives on, add the devices column:
sudo lvs --units g -o lv_name,vg_name,lv_size,lv_path,devices LV VG LSize Path Devices
lv_app vg_data 80.00g /dev/vg_data/lv_app /dev/sdb(0)
lv_logs vg_data 10.00g /dev/vg_data/lv_logs /dev/sdb(20480)The number in parentheses is the first physical extent that the volume occupies on that device. Here lv_app starts at extent 0 and takes 20480 extents, which at 4 MiB per extent is 80 GiB. lv_logs starts right after it. If a volume is spread over several disks, it lists several entries.
Step 3: check unallocated space with vgs
sudo vgs VG #PV #LV #SN Attr VSize VFree
vg_data 1 2 0 wz--n- <100.00g <10.00gThe VFree column is the most important number in the whole inspection. It is space inside the volume group that no logical volume uses yet. It decides which path you take:
- If VFree is at least as large as the growth you need, you can go straight to
lvextend. No new disk is required. - If VFree is too small, you must first add capacity to the group, either with a new disk or with an enlarged existing one. Later chapters cover both.
The < sign means "slightly less than". LVM rounds sizes to two decimals and flags values that rounding made look larger than they are. The group is just under 100 GiB because LVM keeps a small metadata area at the start of each physical volume.
The #PV and #LV columns count the physical and logical volumes in the group. The Attr string wz--n- has the letter z in second position, which means the group is resizable. A group that is exported or partial shows a different letter in the third or fourth position, and you should resolve that before resizing anything.
If you need the extent size, ask for it:
sudo vgs -o vg_name,vg_extent_size,vg_free_count,vg_freevg_free_count is the number of free extents. This is the unit that lvextend -l works in.
Step 4: find the backing disks with pvs
sudo pvs PV VG Fmt Attr PSize PFree
/dev/sdb vg_data lvm2 a-- <100.00g <10.00gEach row is a device that LVM has labeled as a physical volume. This output tells you:
- What backs the group. Here the whole disk
/dev/sdbis the physical volume. On other servers it is a partition such as/dev/sda3or/dev/nvme0n1p3. You need to know which, because the enlarged-disk procedure later in the tutorial works on the partition, not on the disk. - How much each device has free. PFree on a device is the unused part of that device. The sum across all devices in a group equals the group's VFree.
- Whether a device is healthy. The
a--in Attr means allocatable, not exported, and not missing. Anmin the third position means LVM cannot find the device. Do not resize a group that has a missing physical volume.
A physical volume with an empty VG column belongs to no group. It was prepared with pvcreate but never added with vgextend, so it is free to use. Use sudo pvs -a to also list devices that are not physical volumes at all.
Step 5: see the whole tree with lsblk
lsblk -fNAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 vfat FAT32 3A1C-9F02 510M 1% /boot/efi
└─sda2 ext4 1.0 0b6f2c7e-5d3a-4b1c-8e44-1f7a90d2c6aa 12.1G 38% /
sdb LVM2_member LVM2 001 Qk2vYd-8mXa-Pq0h-7sLd-Zt3n-uV1c-aB9eRw
├─vg_data-lv_app ext4 1.0 9d1e44b0-2c7a-4f6b-a3d5-6e0b8c1f7a21 14G 77% /srv/data
└─vg_data-lv_logs ext4 1.0 4a7c1b92-0e5d-47a8-9c36-b2f1d8e03c55 7.5G 9% /var/log/app
sdcRead it as a tree. The disk sdb has the type LVM2_member, which confirms it is a physical volume. The two logical volumes hang under it with their filesystems and mount points. The FSUSE% column here (77%) differs slightly from the df figure above because it comes from a different reading; treat df as the reference for capacity and lsblk as the map of what is attached to what.
The last line, sdc, has no partitions, no filesystem, and no mount point. It is a candidate for the "new disk" path. Before you use it, confirm it is really unused. A disk with an empty FSTYPE column can still hold a partition table or old signatures that the tree does not show.
Device names such as sdb and sdc can change between reboots when disks are added or removed. Rely on sizes, serial numbers, or /dev/disk/by-id/ paths when several disks look alike.
The mount-point column is called MOUNTPOINTS in recent util-linux versions (2.37 and later) and MOUNTPOINT in older ones. Both work with -o, but ask for the name your system supports.
Adjusting the output
The default columns are fine for a first look. These options help when you want precise numbers or output for a script.
- Fixed units.
sudo vgs --units gshows sizes in GiB. Lowercase unit letters mean powers of 1024 (gis GiB). Uppercase mean powers of 1000 (Gis GB). Mixing the two is a common reason a requested size does not match what you expected. - Chosen columns.
-opicks columns. A leading+adds to the defaults instead of replacing them, as insudo pvs -o +pv_used. - No header or decoration.
--noheadingsremoves the header row, which suits scripts. - Structured output.
sudo vgs --reportformat jsonprints JSON on LVM versions that support it. - Verbose detail.
sudo vgdisplay vg_data,lvdisplay, andpvdisplayprint long reports, including the extent size and the free and allocated extent counts.
Save a snapshot before you start. If something looks wrong afterward, you can compare it to the original:
{
date
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/data
} > ~/lvm-before-$(date +%F).txt 2>&1Common misreadings
- A full filesystem and a full volume group are different problems. If
dfshows 99% andvgsshows VFree of 40g, you only needlvextendand a filesystem grow. If VFree is 0, you need new capacity first. - A larger disk is not larger LVM capacity yet. If a virtual disk was enlarged,
lsblkshows the bigger size, butpvsstill shows the old PSize until the partition and the physical volume are resized. A gap between thelsblksize and thepvssize is the sign that you need the enlarged-disk procedure. - Several logical volumes in one group compete for the same VFree. If another team's volume in
vg_datais also growing, checkvgsagain right before you extend. - Unmounted volumes look fine in
lvs. The sixth Attr character isowhen a volume is open (usually mounted) and-when it is not. A volume that is not mounted will not show up indf, so a missingdfline does not mean the volume is gone. - Several mounts can share one device name. Bind mounts and containers can show the same source device twice.
findmntshows the real source.
Decoding the Attr strings
The Attr column packs several facts into a short string. These are the positions that matter for resizing.
| Command | Position | Letter | Meaning |
|---|---|---|---|
| `lvs` | 1 | `-` | Plain linear volume. Other letters mean thin, snapshot, RAID, and so on. |
| `lvs` | 2 | `w` | Writable. `r` means read-only and cannot be extended in the usual way. |
| `lvs` | 5 | `a` | Active. `-` means the volume is not active. |
| `lvs` | 6 | `o` | Open, for example mounted. |
| `vgs` | 1 | `w` | Writable. |
| `vgs` | 2 | `z` | Resizable. |
| `pvs` | 1 | `a` | Allocatable, so new extents can be taken from it. |
| `pvs` | 3 | `m` | Missing device. Stop and investigate. |
A short pre-change checklist
Before moving to the next chapter, write down these values for the volume you plan to grow:
- The mount point, the device path, and the filesystem type (from
df -hT). - The LV name, VG name, and current LSize (from
lvs). - VFree for the group, and the extent size if you plan to use
-l(fromvgs). - The backing physical volumes and whether each is a whole disk or a partition (from
pvsandlsblk). - Any candidate disk, with its size and serial number confirmed against the hypervisor or cloud console.
With these values in hand, every later command has a definite target and an expected result you can compare against.
Exercise
df -hT /srv/data shows the Filesystem as /dev/mapper/vg_app-lv_db with type xfs. sudo vgs shows vg_app with VFree of 0. Which volume group and logical volume are involved, which tool will later grow the filesystem, and what must you do before you can extend the logical volume?
Show answer
The volume group is vg_app and the logical volume is lv_db. The filesystem is XFS, so it is grown with xfs_growfs on the mount point. Because VFree is 0, the group has no unallocated space, so you must first add capacity: either a new disk with pvcreate and vgextend, or an enlarged existing disk with pvresize. Only then can lvextend take more extents.
Exercise
lsblk shows a virtual disk sda as 200G, but sudo pvs shows the physical volume /dev/sda3 with PSize 100G, and vgs shows VFree of 0. What does this difference mean, and why can't you extend the logical volume yet?
Show answer
The disk was enlarged at the hypervisor level, but LVM has not picked up the new space. The partition sda3 has not been grown to fill the disk, and the physical volume has not been resized with pvresize, so the volume group still sees only 100G and has no free extents. You must rescan the device, grow the partition, and run pvresize before lvextend has anything to allocate.
Exercise
Why should you run sudo wipefs /dev/sdc with no options, and not pvcreate, when you are unsure whether /dev/sdc is empty?
Show answer
Without options, wipefs only lists the filesystem, RAID, and LVM signatures it finds on the device and erases nothing. pvcreate writes an LVM label to the disk and can destroy existing data. Listing signatures first lets you confirm the disk is unused and is the one you intended.