I would like to compress the whole filesystem. Both existing and new files. This is my fstab file, what should i add to achieve that? And how can i check if it works? Thanks in advance.
Just to be sure I understand, you want on-the-fly (automatic) compression (?)
If yes, you are currently using BTRFS, which natively features transparent compression.
Good info:
https://wiki.archlinux.org/title/Btrfs#Compression
.
https://en.opensuse.org/SDB:BTRFS#Compressed_btrfs_filesystems
Yes I want automatic compression, and thank you for providing the guides. I ran this command: btrfs filesystem defragment -r -v -czstd / and added this to fstab:
and I used this tool to check if it did something, does this mean it works?:
This is only about your way of posting code (not about your poblem).
PLease, to make your posts better consumable by technical oriented people:
Append ,compress=zstd
to the first btrfs line in your fstab, the one with the /
Compression is an all or nothing option so all subvolumes will have it enabled. Some people like to specify it for every subvolume, which signifies intent and optimism that tomorrow will be better than today.
This will affect all newly written data. Are you sure you want existing data to be compressed? For example if the purpose is to reduce SSD wear, compressing existing data would not usually be beneficial.
If you are sure, check if you have snapshots on the volume.
btrfs subvolume list /
Anything there that looks like a snapshot?
Do you use snapper?
snapper --iso list --disable-used-space
I would delete all snapshots before proceeding. The only thing to keep is the writable snapshot with the *
and 0
which is the same thing.
Are you a heavy reflink user? For example do you use cp -r --reflink=always
a lot? Or just once on a huge data set? If so, proceeding may be a bad idea.
echo 'surely there are no more reflinked copies' && btrfs -v filesystem defragment -r -czstd /
Ah snap, forgot something: That just defragments and compresses the single /
subvolume. So add the paths for the other subvolume mounts to the command or process them separately.
... / /var /usr/local /path/to/some/subvol /and/so/on
That’s nice because you won’t accidentally defrag snapshots even if you don’t delete them. However, it would still increase space use a lot if you kept them.
Finally the compsize
utility is nice to admire your handiwork.
$ compsize -x /usr
Processed 357890 files, 209726 regular extents (226158 refs), 186098 inline.
Type Perc Disk Usage Uncompressed Referenced
TOTAL 52% 7.1G 13G 14G
none 100% 3.8G 3.8G 3.8G
zstd 34% 3.3G 9.7G 10G
While I know it’s not a proper solution to your problem, just keep in mind that next time you can set file system option compress=zstd
right from the start while installing the system. Only saying this here again, because it’s absolutely not obvious that it will work if you add that file system option during installation.
It is absolutely obvious that this will work for the new files. It is even documented.
Maybe I missed something, but for me it wasn’t obvious how to enable compression in the installer, so I was happy setting the file system option worked.
I installed slowroll yesterday by setting the values of / in the opnsuse partitioner. With the values noatime,compress=zstd:3. In fact the occupied space is about half.
I hope the snappers work though
I once applied compression by the same methods suggested by other expert users above. It worked, compressed data, but for whatever reason, after a few reboots, the system won’t get past the login screen. After typing in password, the screen would go black and ask me to type password again. Tried loading recent snapshots from the time the system was working fine but the behavior was the same. Only after loading a snapshot prior to applying the compression, I could get past the login screen. After that I didn’t want to take risk again, so I reinstalled the system and added compress=zstd while installing the OS.
BTW, I read that zstd compression is set to lever 3 by default anyway. So, no need to specify 3 unless you want a different level like 1/2/4/etc.
Hi @SeriousHoax Thanks for the clarification zstd! I’m inexperienced and have used only opensuse for 90%. However I have a mx linux vm installed 6/7 months ago with these parameters: noatime,compress=zstd:3, and the timeshifts have always worked well. However I must clarify that I start this os very little.
It’s okay @Keyran17, I’m also inexperienced and I just told you so that you can learn about the default level.
You can find this info and more in their official doc:
https://btrfs.readthedocs.io/en/latest/Compression.html#:~:text=This%20will%20enable%20the%20zstd%20algorithm%20on%20the%20default%20level%20(which%20is%203)
Hi @SeriousHoax
Thanks for the link and for sharing your experience.
bye
Thank you all for the help
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.