Date: 2021jan23
OS: Linux
Distro: Fedora
Q. Fedora: enable btrfs compression
A. This worked for me on a VM.
(I had a couple missteps which I'll omit for your benefit)
- Installed Fedora 33 on a fresh VM, btrfs is the default
for / and /home. While ext4 is used for /boot
But compression is not enabled.
- At one point I messed up and tried to reboot in single user mode
but was denied with "Root account is locked" so had to delete the
entire VM and try again. So next time I unlocked root with
`sudo passwd root`. If your system is on the internet, you add can
`PermitRootLogin no` to /etc/ssh/sshd_config for safety
- Add the compress option to /etc/fstab
Before
UUID=nnn / btrfs subvol=root 0 0
UUID=nnn /boot ext4 defaults 1 2
UUID=nnn /home btrfs subvol=home 0 0
With the option
UUID=nnn / btrfs subvol=root,compress 0 0
UUID=nnn /boot ext4 defaults 1 2
UUID=nnn /home btrfs subvol=home,compress 0 0
- Remount
mount -o remount /home
mount -o remount /
That will only compress new files.
- To compress existing files do
btrfs filesystem defragment -r /home
btrfs filesystem defragment -r /
This only took a few seconds on my new system but may take a while
for a full filesystem.
- Look at how it went
dnf install compsize
compsize /home
compsize /
This will show you how well the compress when and the type of compression being used.
It was zlib for me.
Example output
Processed 140058 files, 133128 regular extents (196786 refs), 80886 inline.
Type Perc Disk Usage Uncompressed Referenced
TOTAL 93% 14G 15G 12G
none 100% 13G 13G 10G
zlib 41% 628M 1.4G 1.4G
zstd 28% 42M 148M 148M
From
https://github.com/kilobyte/compsize
- That's it!
- Optionally you can specify the type of compression in /etc/fstab
using compress=zlib compress=zstd compress=lzo compress=no