14.3. Reducing Storage Safely
Reduction is growth run in reverse, and the reversal is where data is lost. An outer layer - a logical volume, a partition, an array component - has no knowledge of the file extents inside it, so shrinking it first discards whatever occupied the removed blocks. This section shrinks the practice ext4 stack offline step by step, records where XFS and Btrfs refuse a reduction and why, and reduces each outer layer only after the layer inside it is demonstrably smaller.
14.3.1. Shrink Support and Filesystems That Require Migration
Reduction is asymmetric. Growing a container is usually just a metadata change; shrinking it can require moving data that lies beyond the new boundary. The safe rule is simple: reduce the filesystem first, verify it, then reduce the layer that contains it. Never reduce a container and hope the filesystem above it has already moved its data.
Figure 14.2. Reduction order. The filesystem is the only layer that knows where its live data is; the outer layers must follow it.
The support matrix is:
| Filesystem | Supported reduction | Requirements and limits |
|---|---|---|
| ext4 | Offline resize2fs |
Filesystem unmounted, e2fsck first, new size large enough for the data |
| XFS | Migration for a reliable reduction | xfs_growfs -D has an experimental shrink path that can refuse a layout; do not plan production reduction around it |
| Btrfs | Online btrfs filesystem resize or btrfs device remove |
Target device must still hold its allocated chunks; may need a balance |
| LVM LV | lvreduce |
Filesystem must already be smaller; LVM checks ext4 but not every filesystem |
| LUKS mapping | cryptsetup resize --size |
Only after the data below is smaller; shrinking the underlying RAID or disk is a separate step |
| md RAID | mdadm --grow --size or --array-size |
Filesystem and all redundancy members must fit the new component size |
XFS deserves a precise statement because older guidance says only "XFS
cannot shrink." Debian 13's xfsprogs 6.13 and the 6.12 kernel expose an
experimental data-section reduction through xfs_growfs -D. It is not a
routine supported operation: it refuses a target that leaves too little
allocation-group space, and the command labels the attempt
[EXPERIMENTAL]. The practice filesystem rejects an undersized target:
# xfs_growfs -D 1000 /srv/xfs
meta-data=/dev/vdb isize=512 agcount=6, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=1
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
= exchange=0 metadir=0
data = bsize=4096 blocks=786432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=0
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
= rgcount=0 rgsize=0 extents
[EXPERIMENTAL] try to shrink unused space 1000, old size is 786432
xfs_growfs: XFS_IOC_FSGROWFSDATA xfsctl failed: Invalid argument
The geometry is standard output; the [EXPERIMENTAL] and
XFS_IOC_FSGROWFSDATA lines are standard error. The command exits nonzero
and leaves the data section at its old size. For a reliable XFS reduction, create the smaller filesystem on the new
storage and copy the data, as in Section 14.4.1. The migration gives you
a rollback copy and does not depend on an experimental resize path.
14.3.2. Shrinking Ext4 Offline and Reducing Its Containing Volume
The practice ext4 filesystem is still mounted after the growth exercise. Reduction begins by unmounting it, so no application can write while the filesystem metadata is being changed:
# umount /srv/stack
The command is silent. Run a forced check with preen mode:
# e2fsck -f -p /dev/stackvg/stacklv
stacklv: 13/196608 files (0.0% non-contiguous), 37756/781312 blocks
-f forces a full check even if the filesystem looks clean; -p answers
safe repair questions automatically and exits if a problem needs human
intervention. If it does stop, rerun e2fsck -f without -p, read the
problem, and make sure the restore material from Section 14.1.2 is
available before proceeding.
Shrink the filesystem to 1 GiB:
# resize2fs /dev/stackvg/stacklv 1024M
resize2fs 1.47.2 (1-Jan-2025)
Resizing the filesystem on /dev/stackvg/stacklv to 262144 (4k) blocks.
The filesystem on /dev/stackvg/stacklv is now 262144 (4k) blocks long.
Only now can the containing logical volume be reduced. lvreduce checks
the filesystem size before changing the mapping:
# lvreduce -L 1024M /dev/stackvg/stacklv
File system ext4 found on stackvg/stacklv.
File system size (1.00 GiB) is equal to the requested size (1.00 GiB).
File system reduce is not needed, skipping.
Size of logical volume stackvg/stacklv changed from 2.98 GiB (763 extents) to 1.00 GiB (256 extents).
Logical volume stackvg/stacklv successfully resized.
The "reduce is not needed, skipping" line refers to LVM's own filesystem helper: the filesystem is already the requested size, so LVM only reduces the volume. The warning is not a sign that the filesystem shrank twice. Mount the volume and verify both its size and its data:
# mount /dev/stackvg/stacklv /srv/stack
The command is silent.
# df -h /srv/stack
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/stackvg-stacklv 974M 65M 849M 8% /srv/stack
# sha256sum -c /home/john/debian-handbook/storage-migration/stack-keep.sha256
/srv/stack/keep.bin: OK
The free extents remain in the volume group:
# vgs stackvg
VG #PV #LV #SN Attr VSize VFree
stackvg 1 1 0 wz--n- 2.98g 1.98g
The VG still owns the space that the LV released. That space can be allocated to another LV, or the PV can be reduced only after the VG has no extents on the part being removed. Section 14.4.2 shows the extent move that makes a PV removable.
The options used in the reduction are:
| Command | Option | Description |
|---|---|---|
e2fsck |
-f |
Force a full filesystem check |
e2fsck |
-p |
Preen: repair safe problems without asking; stop on others |
resize2fs |
SIZE |
Shrink or grow to an explicit size, such as 1024M |
lvreduce |
-L SIZE |
Reduce the LV to an absolute size |
lvreduce |
-l -N |
Reduce by a number of extents instead of an absolute size |
The order is not optional. lvreduce may refuse to truncate an ext4
filesystem that is still larger than the requested LV, but it cannot
protect a filesystem type it does not understand, and it cannot protect
data that was never shrunk. Always let resize2fs finish and verify the
filesystem before reducing the LV.
14.3.3. Btrfs Device Resizing and Allocation Constraints
Btrfs can resize a device while the filesystem is mounted, but the
filesystem's allocation model makes the operation less predictable than
df suggests. Btrfs allocates data, metadata, and system chunks across
the devices. A device can be larger than the files it holds, yet still be
unable to shrink because the chunks already allocated on that device do
not fit in the smaller size.
The practice filesystem has one 4 GiB device and one 2 GiB device after the growth in Section 14.2.3. Try to shrink device 1 to 256 MiB:
# btrfs filesystem resize 1:256M /srv/btr
Resize device id 1 (/dev/vdg) from 4.00GiB to 256.00MiB
ERROR: unable to resize '/srv/btr': No space left on device
The first line is standard output; the ERROR line is standard error and
the command exits nonzero. The message is about allocation, not about the
amount of file data reported by df: device 1 already has more than
256 MiB of chunks assigned to it. The 256 MiB target also sits at
Btrfs's documented lower limit for a resize: btrfs-progs warns when a
request is below it, and the kernel rejects smaller sizes, so even an
empty device cannot be reduced further with this command.
A 512 MiB request fits the allocated chunks and succeeds:
# btrfs filesystem resize 1:512M /srv/btr
Resize device id 1 (/dev/vdg) from 4.00GiB to 512.00MiB
# btrfs filesystem show /srv/btr
Label: 'btrdata' uuid: 30561864-0a3e-4fa1-86c6-f8a471d8a6d3
Total devices 2 FS bytes used 160.31MiB
devid 1 size 512.00MiB used 272.00MiB path /dev/vdg
devid 2 size 2.00GiB used 680.00MiB path /dev/vdh
The device is now 512 MiB but still has 272 MiB of allocated chunks; the
difference is the space available for future allocation, not free file
data. To shrink further, reduce the allocated chunks first. btrfs
balance relocates chunks; btrfs device remove moves all chunks off a
device and removes it. A balance can take a long time and needs free
space on the remaining devices.
Restore the device to its 2 GiB size for the later replacement exercise:
# btrfs filesystem resize 1:2G /srv/btr
Resize device id 1 (/dev/vdg) from 512.00MiB to 2.00GiB
| Btrfs command | Purpose |
|---|---|
btrfs filesystem show MOUNT |
Show per-device sizes and allocated/used space |
btrfs filesystem usage MOUNT |
Show data, metadata, system, and unallocated space |
btrfs filesystem resize DEVID:SIZE MOUNT |
Set one device's size; max uses the whole device |
btrfs balance start MOUNT |
Relocate chunks according to filters |
btrfs device remove DEVICE MOUNT |
Move all chunks off a device and remove it |
btrfs device add DEVICE MOUNT |
Add a device to the filesystem |
The allocation constraint is not a bug. It is the same property that makes Btrfs able to relocate data online: the filesystem knows which chunks live on which device, so it can refuse a shrink that would cut through an allocated chunk instead of silently corrupting it.
14.3.4. Reducing Outer Layers Without Truncating Inner Data
The outer layers have no knowledge of file extents. They can only be reduced after the inner layer has been reduced and checked. A safe order for a stack is:
- Shrink the filesystem to the new size and verify its data.
- Reduce the logical volume or partition that contains it.
- If the volume group is losing a physical volume, move the remaining
extents first with
pvmove, then remove the PV. - If the array is losing a member, reduce the array size only after the filesystem and all remaining members fit.
- If the encryption mapping is being reduced, reduce it only after the underlying device has been reduced; do not shrink the mapping below the filesystem's block device.
- Wipe the removed device's signatures only after the new layout has been mounted and verified.
The practice ext4 reduction stopped at step 2. The VG still has 1.98 GiB
free, which is the correct state after an LV reduction; the PV itself has
not become smaller. To remove a PV from a VG, pvmove moves its extents
to free space on another PV. Section 14.4.2 does that for /dev/vde.
The following operations are not equivalent:
| Operation | What it changes | Safe only when |
|---|---|---|
resize2fs DEVICE SIZE |
Filesystem block count | The filesystem is unmounted and checked |
lvreduce -L SIZE LV |
Logical volume mapping | The filesystem is already no larger than SIZE |
pvresize --setphysicalvolumesize SIZE PV |
PV metadata size | The PV has no allocated extents beyond SIZE |
mdadm --grow --size=SIZE MD |
Array component size | The filesystem and every member fit SIZE |
cryptsetup resize --size SIZE NAME |
Mapping payload size | The device below is already at least SIZE |
parted resizepart N SIZE |
Partition end | The filesystem is smaller than SIZE and the partition is not busy |
The reports already captured answer the allocation question for both
groups. vgs stackvg in Section 14.3.2 still shows 1.98 GiB free after
the reduction: space LVM owns but stacklv no longer uses. The lvs
report in Section 14.2.4 places all of appdata on /dev/vde, and the
pvs report in Section 14.2.2 shows /dev/vdf holding almost 4 GiB
free in the same group. That is exactly the condition pvmove needs - a
destination PV with at least as much free space as the source's
allocated extents - and Section 14.4.2 uses it.