There may be several reasons to switch to Btrfs, for me personally it’s because my KF2 server is eating up too much space, and Btrfs supports both compression and deduplication. Neither ext4 nor XFS have these so on CentOS I have no other option than Btrfs. Beware, RH deprecated it, so the 8.x series won’t have it, but until then, it’s pretty darn sweet. I’m pretty sure EPEL or some other repo will pick it up afterwards anyway.
Anyhow, to migrate your /home to Btrfs:
- Make sure you’ll be able to access your server as root after the operation, because remember, your
/homewon’t be accessible for a little while.
- Boot into a live CD with GParted included, e.g. SystemRescueCD or GParted Live.
- Start GParted and shrink your root (/) filesystem to a reasonable size, like 5G.
- Create a new, Btrfs formatted partition on the free space with GParted or
- Mount your root filesystem under the live environment, e.g.
mkdir /mnt/root mount /dev/vda2 /mnt/root
/dev/vda2 is the identifier of your root partition, check with
fdisk -l, YMMV.
- Rename your /home, e.g.
pushd /mnt/root mv home home-old popd
- Add the new partition to
UUID=487fd25d-cbcf-44e7-a835-4411ae5183d1 /home btrfs defaults,compress-force=zlib 0 0
You can check the partition’s UUID with
- Unmount your root, e.g.
- Copy your files from
/home. There are several options for this,
- Fix file permissions, if needed (shouldn’t be with
- Fix SELinux contexts, e.g.
restorecon -rv /home.
If you’re curious how much space you save with compression and stuff:
yum install gcc btrfs-progs-devel git clone https://github.com/kilobyte/compsize.git cd compsize make ./compsize /home
To me it’s quite impressive:
# compsize /home Processed 4126 files, 224846 regular extents (224847 refs), 1750 inline. Type Perc Disk Usage Uncompressed Referenced Data 41% 12G 28G 28G none 100% 3.3G 3.3G 3.2G zlib 34% 8.7G 25G 25G