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
/home
won’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
cfdisk
+mkfs.btrfs
. - Mount your root filesystem under the live environment, e.g.
mkdir /mnt/root
mount /dev/vda2 /mnt/root
Where /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
/mnt/root/etc/fstab
, e.g.
UUID=487fd25d-cbcf-44e7-a835-4411ae5183d1 /home btrfs defaults,compress-force=zlib 0 0
You can check the partition’s UUID with blkid
.
- Unmount your root, e.g.
umount /dev/vda2
. - Reboot.
- Copy your files from
/home-old
to/home
. There are several options for this,cp
,rsync
, etc. - Fix file permissions, if needed (shouldn’t be with
rsync
). - 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
Enjoy.