Sub topic 10
Backups, Shrinking Limits, and Common LVM Mistakes
Assumptions: you can use sudo, read lsblk, df, and lvs output, and understand the difference between a block device, a partition, a logical volume, a filesystem, and a mount point. This chapter focuses on safe capacity changes. Growing storage is usually straightforward. Shrinking storage requires a stricter order and may be impossible for some filesystems.
Back up before changing storage
An LVM resize changes how the kernel maps storage. A mistake in a device path, size, or filesystem command can make data unavailable. A successful command does not prove that the data is safe.
Before resizing, confirm all of the following:
- You have a recent backup of the data.
- You know how to restore at least one file from that backup.
- You know the correct logical volume and its mount point.
- You have enough free space for the operation.
- You have a recovery path if the server does not boot or the filesystem will not mount.
- You have checked the maintenance requirements for the filesystem and distribution.
Record the current layout before making changes:
sudo pvs
sudo vgs
sudo lvs -o lv_name,vg_name,lv_size,lv_attr,devices
lsblk -f
df -hT
findmnt /srv/dataSave this output with the change record. The devices column helps reveal which physical volumes contain an LV. findmnt confirms which filesystem is mounted at a path. These checks reduce the risk of resizing the wrong LV.
A snapshot is not a replacement for a backup. An LVM snapshot can help create a consistent copy while an application is running, but it uses space in the volume group and can become invalid when its copy-on-write area fills. Use a tested backup system for recovery.
Understand what can and cannot shrink
Growing normally follows this order:
- Increase the physical volume or add free space to the volume group.
- Extend the logical volume.
- Grow the filesystem.
Shrinking reverses the last two steps:
- Shrink the filesystem.
- Reduce the logical volume.
The filesystem must be smaller before the block device beneath it becomes smaller. If you reduce the LV first, the filesystem metadata may remain outside the new boundary. That can cause immediate corruption or later data loss.
Filesystem support differs:
| Filesystem | Can grow while mounted | Can shrink | Typical growth tool |
|---|---|---|---|
| ext4 | Yes | Yes, usually offline | `resize2fs` |
| XFS | Yes | No | `xfs_growfs` |
XFS cannot be shrunk in place. If an XFS filesystem is too large, create a smaller filesystem, copy the data to it, update the mount configuration, and then remove the old storage only after verifying the copy. This requires enough temporary capacity and a planned maintenance window.
For ext4, shrinking generally requires the filesystem to be unmounted. The exact commands and order depend on whether the LV contains a filesystem directly or contains another layer such as encryption or a partition table. Do not apply an ext4 shrinking procedure to XFS.
Common mistakes and their consequences
Confusing free space in the filesystem with free space in the VG
df reports unused blocks inside a filesystem. vgs reports unallocated extents in a volume group. These are different resources.
A filesystem can have free space while its LV has no room to grow. Conversely, the VG can have free extents while the filesystem is nearly full. Use both commands when deciding what action is possible.
Extending the LV but not the filesystem
lvextend changes the LV boundary. It does not always grow the filesystem. If you run only lvextend, df may still show the old capacity.
Use the filesystem-specific command or the combined lvextend -r option. Then verify with df -hT.
Using the wrong resize argument
resize2fs expects an ext4 device path, such as /dev/vg_data/lv_app. xfs_growfs expects the mounted XFS mount point, such as /srv/data.
# ext4
sudo resize2fs /dev/vg_data/lv_app
# XFS
sudo xfs_growfs /srv/dataAssuming a larger disk automatically gives LVM more space
After a virtual disk grows, the operating system may need a rescan. A partition may also need to be enlarged, followed by pvresize. Until these steps are complete, the PV and VG may still report their old sizes.
Filling the VG completely
Using -l +100%FREE consumes all currently free extents. That may be appropriate, but it leaves no room for snapshots, emergency growth, or another LV. Reserve space when your operational plan needs it.
Reducing an LV casually
lvreduce can reduce the block device without reducing the filesystem. The --resizefs option may coordinate the operation for supported filesystems, but it does not remove the need to confirm the filesystem, backup, mount state, and target size. Treat every reduction as a migration-level change.
A safe decision path
For routine growth, record the intended size before running the command. A fixed increment such as -L +20G is easier to review than consuming all free space. If you use all free extents, confirm that the result is intentional.
Afterward, compare the before and after values:
sudo lvs -o lv_name,lv_size,lv_attr,devices
sudo vgs
df -hT /srv/data
lsblk -fCheck the application as well. A filesystem reporting more space does not prove that the service can write to it. Confirm ownership, permissions, quotas, and application-specific storage limits.
Exercise
An XFS filesystem is mounted at /srv/data. The volume group has 50 GiB free, and the filesystem is nearly full. You want to add 20 GiB. What is the safe operation, and which command grows the filesystem?
Show answer
Extend the logical volume by 20 GiB, then run sudo xfs_growfs /srv/data, or use sudo lvextend -r -L +20G /dev/vg_data/lv_app after verifying that the device and mount point are correct. Do not attempt to shrink XFS in place.