I'm in the middle of generating a 3 TB drive image with GNU ddrescue
, and realizing it will be too big for the target drive (since the empty space is filled with 0xAA instead of 0x00, so instead of using a sparse output file, I need actual compression).
The output file is on a btrfs filesystem, which supports per-file compression, but by which method?
To apply compression to existing files, use the
btrfs filesystem defragment -calg
command, wherealg
is eitherzlib
,lzo
orzstd
. For example, in order to re-compress the whole file system with zstd, run the following command:# btrfs filesystem defragment -r -v -czstd /
This re-compresses existing files, but seems to be for folders of files, not individual files?
- It also says:
Tip: Compression can also be enabled per-file without using the
compress
mount option; to do so applychattr +c
to the file. When applied to directories, it will cause new files to be automatically compressed as they come.
It's not clear if that will re-compress existing files, though.
Setting the compression property on a file using
btrfs property set <file> compression <zlib|lzo|zstd>
will force compression to be used on that file using the specified algorithm.
This seems like it's for forcing compression of files that would not normally be compressed because they contain data that isn't very compressible?
Which command do I want to convert the entire existing file to (default LZO) compression, and to continue compressing any more data that is written to it in the future, without changing the compression of other files on the volume?
lsattr
. Then I tried #1 without-c
and nothing happened. It defragged without paying attention to the compressed bit (finishing immediately). Then I tried #1 with-c
on the whole folder, and it compressed the files (as reported bycompsize
) but didn't change the attributes of them! So only the one I changed hasc
on it, the rest don't, even though they were compressed by defrag, too. So the compressed attribute and defrag compression have nothing to do with each other?btrfs filesystem defragment -r -clzo /path/to/folder
."