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 -calgcommand, where
zstd. 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
compressmount option; to do so apply
chattr +cto 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.
- https://btrfs.wiki.kernel.org/index.php/Compression#Can_I_force_compression_on_a_file_without_using_the_compress_mount_option.3F says
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?