BTRFS is a modern file system that supports transparent compression to reduce disk usage and improve read/write performance. You can enable BTRFS compression on a per-subvolume basis, which means that you can enable compression for specific directories or file systems.
To set up automatic BTRFS compression for a user share, you can follow these steps:
Identify the subvolume that contains the user share that you want to compress. You can use the btrfs subvolume list command to view a list of all subvolumes in your BTRFS file system.
Enable compression for the subvolume by setting the compress attribute to one of the supported compression algorithms (e.g., zstd, lzo, zlib, none). You can use the btrfs property set command to set the attribute:
Python Code
sudo btrfs property set -ts /path/to/subvolume compress <algorithm>
For example, to enable zstd compression for the /mnt/userdata subvolume, you can use the following command:
sudo btrfs property set -ts /mnt/userdata compress zstd
Modify the mount options for the subvolume to enable automatic compression for newly created files. You can add the compress-force=<algorithm> option to the subvolume's mount options in the /etc/fstab file:
UUID=<UUID> /path/to/mount btrfs subvol=/path/to/subvolume,compress-force=<algorithm> 0 0
For example, to enable zstd compression for newly created files on the /mnt/userdata subvolume, you can modify the corresponding line in /etc/fstab as follows:
UUID=<UUID> /mnt/userdata btrfs subvol=/mnt/userdata,compress-force=zstd 0 0
Alternatively, you can use the mount command to modify the mount options for the subvolume:
sudo mount -o remount,compress-force=<algorithm> /path/to/mount
For example, to modify the mount options for the /mnt/userdata subvolume, you can use the following command:
sudo mount -o remount,compress-force=zstd /mnt/userdata
After following these steps, all newly created files and directories in the user share will be automatically compressed using the specified compression algorithm. Existing files will not be compressed automatically, but you can compress them manually using the btrfs filesystem defragment command with the --compress option.
Hope it will help.