I've been trying out the Btrfs with an SSD drive and like the compress option which is set in the fstab.

However this only applies to the files created after I have installed the operating system and modified the fstab file.

What I would like is to apply the compression to all the files on the system, to see if it improves boot time and application start up times.

Does anybody know of a way that I could apply the change to all files either pre or post installation?

3 Answers 3


I believe you have to run

btrfs fi defragment

after mounting the FS with compression.

Check this out: https://askubuntu.com/questions/129063/will-btrfs-automatically-compress-existing-files-when-compression-is-enabled


When installing you can issue a:

mount -o remount,compress=lzo

Often you will have to do it just as the installer starts installing stuff (maybe you will miss a file or 2. but no biggie). You could check to see if the installer has already mounted the filesystem just before the install stage.

Also make sure you update the /etc/fstab on the installed system. I use the following options that give some other improvements:


You can also try using compress-force=lzo for the install rather than compress=lzo, it makes sure that even files that don't compress that well are still compressed. That would make writes slower but since it's a one time install that might be worth it. But I'm not sure if it improves reads or not.

I have seen another way that involves renaming the mount.btrfs binary and replacing it with a script but when I did it under Ubuntu it messed up as it normally installs to subvolumes @ and @home but everything just got dumped to the root of the filesystem.

Alternatively you can install and then use the defragment, but you must defragment every file individually as the command isn't recursive. This could come in handy to upgrade to the new compression methods that are likely to appear in the newer versions of btrfs, snappy and lz4. Run the following from the / directory.

find -xdev -type f -exec btrfs fi defrag '{}' \;
  • This is the more correct answer. The only drawback to doing post-installation compression is that a lot of files won't be compressed on account of being busy. Tricking the installer by preparing the filesystem beforehand is more effective, but also a lot more difficult for the less experienced user. Commented Sep 8, 2014 at 8:54
  • "you must defragment every file individually as the command isn't recursive" - use -r for recursive defrag: btrfs filesystem defragment -r -v -clzo /
    – bain
    Commented Dec 6, 2014 at 0:51

Like many questions with software - the answers change depending on WHEN they get asked/answered. I'm freshening the answer to help anyone Googling their way into topic. :)

The correct answer for btrfs 3.12 and higher to compress directories/mountpoints POST installation (the required recursive option for defrag was added with btrfs 3.12 released in Nov 2013) :
btrfs filesystem defragment -c -r MOUNTPOINT

Here is the current options from the cli of btrfs version 4.4:
btrfs filesystem defragment
usage: btrfs filesystem defragment [options] | [|...]

Defragment a file or a directory

-v             be verbose
-r             defragment files recursively
-c[zlib,lzo]   compress the file while defragmenting
-f             flush data to disk immediately after defragmenting
-s start       defragment only from byte onward
-l len         defragment only up to len bytes
-t size        target extent size hint

BTRFS Use Case from their wiki for using the recursive param to defrag directories/mount points

BTRFS Changelog entry for v3.12

  • Welcome to Super User. Please be aware you have posted an answer to a question that is years old and already has an accepted answer. Although there is nothing wrong with doing so, just be aware you may not get a response.
    – CharlieRB
    Commented Mar 11, 2016 at 21:38
  • 1
    I'm OK with not getting a response, but the accepted answer is no longer correct. So a Google search results in users getting bad data.
    – Jeff Burns
    Commented Mar 11, 2016 at 22:02
  • And that is a perfectly good reason to post it. Good job.
    – CharlieRB
    Commented Mar 12, 2016 at 23:19

You must log in to answer this question.

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