5

I just installed new instance of Fedora 33 and enabled compression for my root volume via compress=zstd:3 mount option. I enabled compression of /usr with chattr +x /usr.

I would like to disable compression for /var directory and according to https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#FILE_ATTRIBUTES I should be able to use chattr +X /var but the tool from F33 does not understand this option. In https://btrfs.wiki.kernel.org/index.php/Compression there is a command btrfs property set /var compression "" however I am not able to tell if this works or not. Any file on my filesystem has no "compression" property set, this does not make sense.

I am assuming that btrfs automatically compresses all files by default when mounted with compress option, but it looks like by default it only compresses files and directories with the +c ("compression") flag explicitly set.

2 Answers 2

1

Per the current wiki page on compression:

Can I set compression per-subvolume?

Currently no, this is planned. You can simulate this by enabling compression on the subvolume directory and the files/directories will inherit the compression flag.

Also per the wiki page:

Compression to newly written data happens:

  1. always -- if the filesystem is mounted with -o compress-force
  2. never -- if the NOCOMPRESS flag is set per-file/-directory
  3. if possible -- if the COMPRESS per-file flag (aka chattr +c) is set, but it may get converted to NOCOMPRESS eventually
  4. if possible -- if the -o compress mount option is specified

Note, that mounting with -o compress will not set the +c file attribute.

So if you don't want a directory compressed, you have two options:

  • Be on a filesystem (not just subvolume) mounted without the compress option, and have no properties set to compress it.
  • Be on a filesystem with the compress option set (but not forced), and have the property of NOCOMPRESS set.

The chattr attributes currently only enable compression (with the +c flag). There is no flag to disable compression. The X flag does something different.

If you want to disable compression, you should use the btrfs property command which can turn compression on/off:

btrfs property set <file> compression none

This should apply to all newly written data to the file/directory.

Also from the wiki:

Note, in kernel versions before v5.14 you could disable compression by passing an empty string instead of explicitly mentioning none or no. Since kernel version 5.14, an empty string resets to default behavior.

So setting compression to "" on your system should have disabled compression, but on more recent kernels you should pass none/no instead.

Also per the wiki there is no builtin tool to check the compression of data, but you can use compsize to check on newly written data.

1

I should be able to use chattr +X /var

e2fprogs define no such attribute as X (uppercase x), see chattr.1 for a full list of supported attributes.

The following steps can be used to force decompress /var and prevent btrfs from compressing any new writes. To be on the safe side, it's best to proceed after the /var filesystem is unmounted.

mv /var /var.old

# or use `btrfs subvolume create /var` if it was originally a subvolume
mkdir /var

# Tell btrfs that we don't want compression here
# chattr +m /var can be used as well
btrfs property set /var compression none

# Do not leave out the `/.` after /var.old !
cp -a --reflink=never /var.old/. /var

# Please make sure that the copy is working before removing /var.old
rm -rf /var.old # or `btrfs subvolume remove /var` for subvolume

You can check if compression is disabled with

compsize -x /var

The above command should report TOTAL 100%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .