LVM and growth

Treat shrinking as a migration

Avoid casual in-place shrinking and choose a copy-and-verify migration when filesystem support or risk is uncertain.

8 minute lesson

~~~

Shrinking is more dangerous than growing because removing blocks can destroy live filesystem data.

Growing adds empty space nobody uses yet. Shrinking takes blocks away, and if the filesystem hasn’t fully vacated them first, you cut into real data. The two operations look symmetric on the command line. They are not symmetric in risk.

Why in-place shrinking is hostile

Some filesystems cannot shrink at all. XFS is the big one: there is no shrink support, full stop. If your data volume is XFS, migration is your only option.

ext4 can shrink, but only offline. The supported workflow requires an unmounted filesystem, filesystem checks, exact ordering, and backups:

sudo umount /srv/data
sudo e2fsck -f /dev/vg0/data
sudo resize2fs /dev/vg0/data 80G     # shrink the filesystem FIRST
sudo lvreduce -L 80G vg0/data        # then the volume, never below the fs size

Order is everything. Reduce the logical volume before the filesystem, or reduce it below the filesystem’s new size, and you’ve amputated live data. Unit confusion between the two commands has destroyed plenty of filesystems. lvreduce --resizefs exists and sequences both steps for you, but the operation still happens in place, on your only copy, with downtime.

The migration alternative

A new smaller volume plus verified copy is often clearer:

sudo lvcreate -L 80G -n data-new vg0
sudo mkfs.ext4 /dev/vg0/data-new
sudo mount /dev/vg0/data-new /mnt/data-new
sudo rsync -aHAX /srv/data/ /mnt/data-new/

Then verify before switching anything:

sudo rsync -aHAX --checksum --dry-run /srv/data/ /mnt/data-new/
# no output = the trees match

Stop writers, run one final rsync to catch late changes, swap the mounts, and keep the old volume around until the application has run happily for a few days. That’s your rollback: remount the original.

My advice: treat any shrink request as a migration by default. The copy approach costs temporary disk space and a short cutover window. The in-place approach bets the only copy of your data on getting order and units right.

Given an oversized volume, compare in-place shrink with new-volume migration. Choose the safer plan and state how you will verify every required file arrived.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →