Settings compression for a filesystem
Hi!
I do have a bunch of BTRFS on LUKS backup disks. Plasma desktop mounts them unter /media… however, it does not mount with compression enabled. I do have some older backup disks which are in /etc/fstab including mount option "compress=zstd".
Is there any way to tell BTRFS to always use a certain compression algorithm for all newly written files (and of course existing files which use compression) without adding an entry in fstab for each disk?
I thought about
btrfs property set MOUNTPOINT compression zstd
but that sets the property just on the root inode of the mounted filesystem. Does it propagate? The manpage does not seem to have any information on that.
If not, well then I add the entries to fstab.
Thanks,
Signature · 1 line
Martin
Quoted 15 lines · Martin Steigerwald
Hi!
I do have a bunch of BTRFS on LUKS backup disks. Plasma desktop mounts them unter /media… however, it does not mount with compression enabled. I do have some older backup disks which are in
/etc/fstabincluding mount option "compress=zstd".Is there any way to tell BTRFS to always use a certain compression algorithm for all newly written files (and of course existing files which use compression) without adding an entry in fstab for each disk?
I thought about
btrfs property set MOUNTPOINT compression zstd
Quoted 8 lines
but that sets the property just on the root inode of the mounted filesystem. Does it propagate? The manpage does not seem to have any information on that.
If not, well then I add the entries to fstab.
Thanks,
You can use btrfs property set <file> compression zstd[1] on directories and files. This enables compression for any new writes to those directories and files. If you set compression on a directory, any new files and directories will inherit the property, while existing files and directories won't.
After mounting your disks you can use find to set compression recursively:
# find /media/btrfs/ -exec btrfs prop set {} compression zstd \;This will enable the compresison flag, but not re-compress existing data. In order to recompress any existing data you have to rewrite it or use btrfs filesystem defragment[2] with the '-c' flag to compress the files, however this does not guarantee that all of the data will be recompressed.
In addition to btrfs propterty set, it is possible to use setfattr, chattr or mount options to set compression [3]
[1] https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs-property
[2] https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs-filesystem#SUBCOMMAND
[3] https://wiki.tnonline.net/w/Btrfs/Compression
Forza - 04.11.21, 16:14:31 CET:
Quoted 10 lines
You can use
btrfs property set <file> compression zstd[1] on directories and files. This enables compression for any new writes to those directories and files. If you set compression on a directory, any new files and directories will inherit the property, while existing files and directories won't.After mounting your disks you can use find to set compression recursively:
# find /media/btrfs/ -exec btrfs prop set {} compression zstd \;
So it just inherits to the newly created files and directories in that directory directly.
Ah, I see… then in case I set it on the root inode of a new empty filesystem it just works, otherwise… I'd need to use find unless I choose to add an entry for each of the disks.
Thanks,
Signature · 1 line
Martin