Skip to content

Instantly share code, notes, and snippets.

@windli2018
windli2018 / freecount.pl
Created August 24, 2020 23:39
used in shrink xfs filesystem
#!/usr/bin/perl -T
# Get from https://xfs.org/index.php/Shrinking_Support with some small fix to support lvm
use strict;
use warnings;
my $fd;
$ENV{PATH} = "/usr/sbin";
$ENV{LC_ALL} = "C";
@windli2018
windli2018 / shrink xfs filesystem on lvm.md
Last active February 15, 2026 02:21
shrink xfs filesystem

According to https://xfs.org/index.php/Shrinking_Support :
"Currently XFS Filesystems can't be shrunk."
You need backup the data and recreate the file system to shrink it.
But if you have a big xfs filesystem with not too much space used, For example, a 2T xfs volume with 100G data.
And you can take some risk to lose data. Here is a way to shrink it without using new space.
The idea is:
1.temporary reduce the logic volume size, you can still read from xfs filesystem even after the partition or volume is shrunk if the real data is not wrote at the shrunk part
2.create a new volume
3.copy data