Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I chose btrfs as the format of my / filesystem in the Ubuntu 12.04 LTS installer. After the installation completed, I added compress=lzo to the mount options in /etc/fstab and rebooted.

Will the existing files be automatically compressed now, or must I explicitly do something to force that to happen?

share|improve this question
    
You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect. –  sep332 Jan 16 at 19:13
    
NB that you may need to use the compress-force option or some files will still remain uncompressed no matter what you do... –  rogerdpack Mar 12 at 19:40
add comment

5 Answers

up vote 14 down vote accepted

You will have to run btrfs fi defragment to force recompression of existing data. Otherwise, only new data will be compressed.

From the FAQ:

...consider remounting with -o compress, and either rewrite particular files in-place, or run btrfs fi defragment to recompress everything. This may take a while.

share|improve this answer
add comment

I've made what Norbert Fabritius said, but I didn't notice any compression in the existing files - df -h / before btrfs fi defragment = 658MB | df -h / after btrfs fi defragment = 658MB. New files are ok. Searching a little bring me this quote:

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 '{}' \;

After this, my / it's occupping 656MB - nothing huge, but certainly there is compression.

Source: https://btrfs.wiki.kernel.org/index.php/Problem_FAQ#Defragmenting_a_directory_doesn.27t_work

Hope this help.

Sorry my english.

share|improve this answer
    
1. When using btrfs, do not use or trust df. 2. For a better compression ratio, use zlib (however, it's slower) –  ignis Nov 4 '13 at 12:00
    
Shouldn't your command line include defrag -clzo or defrag -czlib instead of just defrag, if you want to actually compress things? –  jbo5112 Nov 17 '13 at 5:14
add comment

According to Oracle's documentation, you can compress existing files on an existing, online filesystem by defragmenting each file in it with the -c, -clzo, or -czlib options. LZO is recommended for speed.

find / -xdev \( -type f -o -type d \) -exec btrfs filesystem defragment -v -clzo -- {} +

This uses the find command to run the btrfs defragmenter on every file in the root filesystem (given by the slash right after the "find" command at the beginning). If you have other subvolumes, you can use it again with the path of a subvolume (I have one at /home, for example) instead of the single slash.

You'll need root privileges for this, so add sudo to the front if you need to.

See:

share|improve this answer
add comment

According to https://btrfs.wiki.kernel.org/index.php/Mount_options#List_of_options following compression algorithms are available:


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. 

Note: This post is answer for the additional question what type of compression algorithms are available which was asked below...so please don't blame me.

share|improve this answer
add comment

Compression is enabled by default in Btrfs, so unless you explicitely disabled it, it should be compressed.

share|improve this answer
7  
Not true, you have to pass compression= "your favorite compression algorithm" in fstab to enable it. –  turbo Jul 24 '12 at 12:36
    
@turbo What compression algorigthms are available? –  hexafraction Oct 27 '12 at 0:26
    
looks like there are 2 compressions currently allowed (well, 3 if you count "none"): btrfs.wiki.kernel.org/index.php/… –  rogerdpack Jun 14 '13 at 23:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.