Situation
While expanding a Logical Volume (LVM) and its filesystem can usually be done “online” without unmounting, shrinking is a different story. Shrinking an ext4 filesystem and its LV requires unmounting the volume, making it an offline operation. If done incorrectly, you risk severe data loss.
Always ensure you have a full backup before proceeding with a shrink operation.
In this scenario, we want to shrink the volume mounted at /data (which is mapped to /dev/mapper/vg_data-lv_data) down to exactly 10G.
Task 1 – Unmount the Filesystem
You must unmount the filesystem before you can resize it. If the filesystem is in use, you’ll need to stop the services accessing it first.
# Unmount the directory
sudo umount /data
(If you get a “target is busy” error, use lsof +D /data or fuser -m /data to find and terminate the processes holding the filesystem open).
Task 2 – Check the Filesystem for Errors
Before resizing, it is mandatory to force a filesystem check to ensure data integrity.
# Check the ext4 filesystem
sudo e2fsck -f /dev/mapper/vg_data-lv_data
Task 3 – Shrink the Filesystem
We first shrink the filesystem. It is highly recommended to shrink the filesystem to a size slightly smaller than your final target for the Logical Volume. This provides a safety margin. Since our target LV size is 10G, we will shrink the filesystem to 9.5G.
# Shrink the filesystem to 9.5G
sudo resize2fs /dev/mapper/vg_data-lv_data 9.5G
Task 4 – Shrink the Logical Volume (LV)
Now that the filesystem is safely small enough, we can reduce the size of the Logical Volume container to our final target of 10G.
# Reduce the LV to the final 10G size
sudo lvreduce -L 10G /dev/mapper/vg_data-lv_data
Note: The system will ask for confirmation and warn you that this operation can destroy data. Type y to proceed.
Task 5 – Extend the Filesystem to Fill the LV
We shrank the filesystem a bit too much (9.5G) to be safe. Now, we expand it so it perfectly fits the newly resized 10G Logical Volume. Running resize2fs without a size parameter automatically fills the available space.
# Extend the filesystem to perfectly match the LV size
sudo resize2fs /dev/mapper/vg_data-lv_data
Task 6 – Remount and Verify
Finally, mount the filesystem back to its original location and verify the new size.
# Mount the filesystem again
sudo mount /data
# Verify the final size
df -h /data
lsblk
Architecture Diagram
This diagram supports Safely Shrinking an LVM ext4 Filesystem and highlights where controls, validation, and ownership boundaries sit in the workflow.
Post-Specific Engineering Lens
For this post, the primary objective is: Change storage allocation safely with reversible checkpoints.
Implementation decisions for this case
- Chose a staged approach centered on lvm to avoid high-blast-radius rollouts.
- Used storage checkpoints to make regressions observable before full rollout.
- Treated ext4 documentation as part of delivery, not a post-task artifact.
Practical command path
These are representative execution checkpoints relevant to this post:
lsblk -f
lvdisplay; vgdisplay; pvdisplay
resize2fs /dev/mapper/<lv>
Validation Matrix
| Validation goal | What to baseline | What confirms success |
|---|---|---|
| Functional stability | service availability, package state, SELinux/firewall posture | systemctl --failed stays empty |
| Operational safety | rollback ownership + change window | journalctl -p err -b has no new regressions |
| Production readiness | monitoring visibility and handoff notes | critical endpoint checks pass from at least two network zones |
Failure Modes and Mitigations
| Failure mode | Why it appears in this type of work | Mitigation used in this post pattern |
|---|---|---|
| Incorrect device target | Data loss risk increases immediately | Require device mapping verification and maintenance window gate |
| Insufficient free extents | Resize fails mid-operation | Pre-calculate growth/shrink plan before execution |
| Rollback ambiguity | Recovery time extends during incident | Create snapshot/backup and rollback notes ahead of change |
Recruiter-Readable Impact Summary
- Scope: deliver Linux platform changes with controlled blast radius.
- Execution quality: guarded by staged checks and explicit rollback triggers.
- Outcome signal: repeatable implementation that can be handed over without hidden steps.