问题描述
在Ubuntu 12.04 LTS安装程序中,我选择btrfs作为/
文件系统的格式。安装完成后,我在/etc/fstab
的安装选项中添加了compress=lzo
并重新启动。
现在是否会自动压缩现有文件,或者我必须明确执行某些操作来导致这种情况发生?
最佳方案
您将必须运行btrfs fi defragment
来强制重新压缩现有数据。否则,将仅压缩新数据。
从the FAQ:
…consider remounting with
-o compress
, and either rewrite particular files in-place, or runbtrfs fi defragment
to recompress everything. This may take a while.
次佳方案
我已经做了Norbert Fabritius所说的,但是我没有注意到现有文件中的任何压缩-df -h /在btrfs fi碎片整理之前= 658MB | df -h /btrfs fi碎片整理后= 658MB。可以保存新文件。搜索一点带给我这个报价:
Running this:
# btrfs filesystem defragment ~/stuff
does not defragment the contents of the directory.
This is by design. btrfs fi defrag operates on the single filesystem object passed to >it. This means that the command defragments just the metadata held by the directory >object, and not the contents of the directory. If you want to defragment the contents >of the directory, something like this would be more useful:
# find -xdev -type f -exec btrfs fi defrag '{}' \;
在此之后,我/它占用了656MB-没什么大的,但是肯定有压缩。
来源:https://btrfs.wiki.kernel.org/index.php/Problem_FAQ#Defragmenting_a_directory_doesn.27t_work
希望能有所帮助。
对不起,我的英语。
第三种方案
根据Oracle的文档,您可以通过使用-c,-clzo或-czlib选项对其中的每个文件进行碎片整理,从而压缩现有在线文件系统上的现有文件。建议使用LZO以提高速度。
find / -xdev \( -type f -o -type d \) -exec btrfs filesystem defragment -v -clzo -- {} +
这使用find命令在根文件系统中的每个文件上运行btrfs碎片整理程序(由开头的”find”命令后的斜杠给出)。如果还有其他子卷,则可以将其与子卷的路径(例如,我在/home中有一个)一起使用,而不是使用单个斜杠。
为此,您需要root特权,因此如果需要,可以在前面添加sudo。
看到:
-
http://docs.oracle.com/cd/E37670_01/E37355/html/ol_use_case1_btrfs.html
-
https://btrfs.wiki.kernel.org/index.php/UseCases#How_do_I_defragment_many_files.3F
第四种方案
根据https://btrfs.wiki.kernel.org/index.php/Mount_options#List_of_options,可以使用以下压缩算法:
compress,compress-force
Enable compression. Starting with kernel 2.6.38 you can choose the algorithm for compression:
- compress=zlib - Better compression ratio. It's the default and safe for olders kernels.
- compress=lzo - Faster compression.
- compress=no - Disables compression (starting with kernel 3.6).
compress-force= - Enable compression even for files that don't compress well, like videos and dd images of disks. The options compress-force=zlib and compress-force=lzo works for kernels >2.6.38.
Note that old (before 2012) btrfs-progs versions will probably fail some operations (e.g. fsck) on filesystems with LZO compression.
注意:本文是针对以下问题的回答:哪种类型的压缩算法可用,如下所示…所以请不要怪我。
第五种方案
根据ArchWiki:
Tip: Compression can also be enabled per-file without using the
compress
mount option; simply applychattr +c
to the file. When applied to directories, it will cause new files to be automatically compressed as they come.
非常好!愿上帝保佑BTRFS!
另外,从the BTRFS wiki:
Can I force compression on a file without using the compress mount option?
Yes. The utility
chattr
supports setting file attribute c that marks the inode to compress newly written data.