Jump to content

How to setup BTRF compression automatic apply for usershare


Recommended Posts

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:

  1. 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.
  2. 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.

Link to comment
1 hour ago, Hellomynameisleo said:

How do I make it so UNRAID does ZSTD compression for all the files in the usershares and does it for all new ones including all files in the subdirectories as well automatically? I'm unable to see an option for it in the GUI

GUI option will be available for v6.12, for the complete filesystem, not just a share, fou now you can enable that manually for a specific share or the whole fs.

Link to comment
1 hour ago, Dubai Housekeeping said:

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:

  1. 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.
  2. 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.

I've tried the code in the unraid terminal but it doesn't seem to work as its in python. Is there a native code that works in the terminal right out of the gate?

Link to comment
6 minutes ago, JorgeB said:

Use

btrfs property set /mnt/disk_path/share compression zstd

 

Replace disk_path with disk1, disk2, cache, etc, note that you need to use the disk path, it won't work with /mnt/user, and if the shares resides in more than one disk you must set that for all disks where it exists.

thanks I used "btrfs property set /mnt/disk1/Backup compression zstd" and "btrfs property set /mnt/disk2/Backup compression zstd". I copied over a test file over to the shared named "Backup" but the filesize hasn't changed.

Link to comment
3 minutes ago, JorgeB said:

File size won't change, used size can be less, assuming the files are compressible.

I've tested documents and images but they remain the same "size on disk" on properties. How do I see if comprression is enabled or the differenence between the uncompressed/compressed size to confirm because byte for byte there isn't a reduction at all or change compared to the original file.

Link to comment
2 hours ago, JorgeB said:

It should be working but let me take a look later, it's been some time since I've tested.

I've tried a bunch some other things but can't get confirmation if its working. Is there a way to see if comrpession is actually enabled and see how much its actually comrpessed?

I'm looking through the SMB share on windows 10 and don't see the files I copy over to UNRAID disk 1 being compressed at all

Link to comment
50 minutes ago, JonathanM said:

Try creating a very large empty file, and see if the actual used space increases. Maybe make the file half the total size of the remaining space on the drive.

https://www.windows-commandline.com/how-to-create-large-dummy-file/

image.png.acd69829aeb7840d4c8d6eca12d025ed.png

I've created an 5GB empty text tile and it doesn't compress anything as shown in the picture. I've even set it to the highest compression setting too.

Edited by Hellomynameisleo
Link to comment
47 minutes ago, Hellomynameisleo said:

image.png.acd69829aeb7840d4c8d6eca12d025ed.png

I've created an 5GB empty text tile and it doesn't compress anything as shown in the picture. I've even set it to the highest compression setting too.

Enabling compression in BTRFS will not automatically compress existing files. Compression will only apply to files created after the setting is applied. 

Link to comment

Like mentioned before the reported size of the file won't change, this is part of my dropbox folder totaling 5.71GB.

 

Disk1 is btrfs with zstd=10, disk2 is btrfs no compression, disk3 is zfs with lz4 compression

imagem.png

 

P.S. since was compressing the whole disk I used

mount -o remount,compress=zstd:10 /mnt/disk1

to enable compression

Link to comment
9 minutes ago, JorgeB said:

Like mentioned before the reported size of the file won't change, this is part of my dropbox folder totaling 5.71GB.

 

Disk1 is btrfs with zstd=10, disk2 is btrfs no compression, disk3 is zfs with lz4 compression

imagem.png

 

P.S. since was compressing the whole disk I used

mount -o remount,compress=zstd:10 /mnt/disk1

to enable compression

I've used both "btrfs property set /mnt/disk2/Backup/test/ compression zstd:15" and "mount -o remount,compress=zstd:15 /mnt/disk2". And then checked it and it still doesn't work... it may be buggy for me. I've tested comrpession with 7zip and it compresses a good 30%. With both set it has no compression as far as I can see when checking unraid GUI, or command line.

Link to comment
14 hours ago, JorgeB said:

Like mentioned before the reported size of the file won't change, this is part of my dropbox folder totaling 5.71GB.

 

Disk1 is btrfs with zstd=10, disk2 is btrfs no compression, disk3 is zfs with lz4 compression

imagem.png

 

P.S. since was compressing the whole disk I used

mount -o remount,compress=zstd:10 /mnt/disk1

to enable compression

With that command do you have to apply it every time you start up the array or reboot?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...