Will btrfs automatically compress existing files when compression is enabled?












25















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 cause that to happen?










share|improve this question




















  • 1





    You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

    – sep332
    Jan 16 '14 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 '14 at 19:40











  • A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

    – zaTricky
    Oct 15 '16 at 8:10


















25















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 cause that to happen?










share|improve this question




















  • 1





    You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

    – sep332
    Jan 16 '14 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 '14 at 19:40











  • A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

    – zaTricky
    Oct 15 '16 at 8:10
















25












25








25


5






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 cause that to happen?










share|improve this question
















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 cause that to happen?







btrfs compression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 15 '16 at 16:44







ændrük

















asked May 1 '12 at 3:35









ændrükændrük

42k61195341




42k61195341








  • 1





    You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

    – sep332
    Jan 16 '14 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 '14 at 19:40











  • A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

    – zaTricky
    Oct 15 '16 at 8:10
















  • 1





    You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

    – sep332
    Jan 16 '14 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 '14 at 19:40











  • A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

    – zaTricky
    Oct 15 '16 at 8:10










1




1





You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

– sep332
Jan 16 '14 at 19:13





You don't have to reboot, you could just sudo mount -o remount / and the new fstab options will take effect.

– sep332
Jan 16 '14 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 '14 at 19:40





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 '14 at 19:40













A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

– zaTricky
Oct 15 '16 at 8:10







A note regarding compress-force. Normal compress has a feature in that if it detects that compression has little to no benefit, it doesn't bother continuing the compression for that particular file (thereby saving wasted CPU). By using compress-force, it attempts useless compression anyway. Good examples where this applies are for files that are already compressed (multimedia, zip files, etc). In other words, compress-force is generally a bad idea. ;)

– zaTricky
Oct 15 '16 at 8:10












6 Answers
6






active

oldest

votes


















26














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


























  • btrfs fi defragment -r -clzo /path/to/fs

    – David Goodwin
    Jul 30 '15 at 14:25






  • 1





    What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

    – Geremia
    Sep 20 '16 at 14:02













  • Make sure to use "-r" the recursive flag for compressing within directories.

    – Salami
    Oct 14 '16 at 17:30



















10














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






  • 2





    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






  • 3





    There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

    – Salami
    Oct 14 '16 at 17:28





















8














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:




  • 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






share|improve this answer

































    2














    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

































      2














      According to ArchWiki:




      Tip: Compression can also be enabled per-file without using the
      compress mount option; simply apply chattr +c to the file. When
      applied to directories, it will cause new files to be automatically
      compressed as they come.




      Very nice! God bless BTRFS!



      Also, from 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.







      share|improve this answer































        -9














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






        share|improve this answer



















        • 11





          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











        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f129063%2fwill-btrfs-automatically-compress-existing-files-when-compression-is-enabled%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        26














        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


























        • btrfs fi defragment -r -clzo /path/to/fs

          – David Goodwin
          Jul 30 '15 at 14:25






        • 1





          What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

          – Geremia
          Sep 20 '16 at 14:02













        • Make sure to use "-r" the recursive flag for compressing within directories.

          – Salami
          Oct 14 '16 at 17:30
















        26














        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


























        • btrfs fi defragment -r -clzo /path/to/fs

          – David Goodwin
          Jul 30 '15 at 14:25






        • 1





          What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

          – Geremia
          Sep 20 '16 at 14:02













        • Make sure to use "-r" the recursive flag for compressing within directories.

          – Salami
          Oct 14 '16 at 17:30














        26












        26








        26







        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















        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














        share|improve this answer



        share|improve this answer








        edited Aug 20 '12 at 2:20









        ændrük

        42k61195341




        42k61195341










        answered May 1 '12 at 17:28









        Norbert FabritiusNorbert Fabritius

        28433




        28433













        • btrfs fi defragment -r -clzo /path/to/fs

          – David Goodwin
          Jul 30 '15 at 14:25






        • 1





          What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

          – Geremia
          Sep 20 '16 at 14:02













        • Make sure to use "-r" the recursive flag for compressing within directories.

          – Salami
          Oct 14 '16 at 17:30



















        • btrfs fi defragment -r -clzo /path/to/fs

          – David Goodwin
          Jul 30 '15 at 14:25






        • 1





          What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

          – Geremia
          Sep 20 '16 at 14:02













        • Make sure to use "-r" the recursive flag for compressing within directories.

          – Salami
          Oct 14 '16 at 17:30

















        btrfs fi defragment -r -clzo /path/to/fs

        – David Goodwin
        Jul 30 '15 at 14:25





        btrfs fi defragment -r -clzo /path/to/fs

        – David Goodwin
        Jul 30 '15 at 14:25




        1




        1





        What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

        – Geremia
        Sep 20 '16 at 14:02







        What about the autodefrag mount option? Does that also make it compress previously uncompressed files when it auto-defrags?

        – Geremia
        Sep 20 '16 at 14:02















        Make sure to use "-r" the recursive flag for compressing within directories.

        – Salami
        Oct 14 '16 at 17:30





        Make sure to use "-r" the recursive flag for compressing within directories.

        – Salami
        Oct 14 '16 at 17:30













        10














        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






        • 2





          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






        • 3





          There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

          – Salami
          Oct 14 '16 at 17:28


















        10














        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






        • 2





          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






        • 3





          There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

          – Salami
          Oct 14 '16 at 17:28
















        10












        10








        10







        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













        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












        share|improve this answer



        share|improve this answer










        answered May 17 '13 at 16:37









        J. NetoJ. Neto

        10112




        10112













        • 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






        • 2





          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






        • 3





          There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

          – Salami
          Oct 14 '16 at 17:28





















        • 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






        • 2





          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






        • 3





          There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

          – Salami
          Oct 14 '16 at 17:28



















        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





        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




        2




        2





        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





        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




        3




        3





        There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

        – Salami
        Oct 14 '16 at 17:28







        There's a "-r" recursive flag so you can just do this now: btrfs fi defrag -r -czlib ~/stuff

        – Salami
        Oct 14 '16 at 17:28













        8














        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:




        • 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






        share|improve this answer






























          8














          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:




          • 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






          share|improve this answer




























            8












            8








            8







            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:




            • 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






            share|improve this answer















            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:




            • 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







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 3 '13 at 13:56

























            answered Sep 5 '13 at 21:12









            GeoffGeoff

            20123




            20123























                2














                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






























                  2














                  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




























                    2












                    2








                    2







                    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















                    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














                    share|improve this answer



                    share|improve this answer








                    edited Mar 16 '13 at 20:42

























                    answered Mar 16 '13 at 11:22









                    Rostislav StribrnyRostislav Stribrny

                    59337




                    59337























                        2














                        According to ArchWiki:




                        Tip: Compression can also be enabled per-file without using the
                        compress mount option; simply apply chattr +c to the file. When
                        applied to directories, it will cause new files to be automatically
                        compressed as they come.




                        Very nice! God bless BTRFS!



                        Also, from 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.







                        share|improve this answer




























                          2














                          According to ArchWiki:




                          Tip: Compression can also be enabled per-file without using the
                          compress mount option; simply apply chattr +c to the file. When
                          applied to directories, it will cause new files to be automatically
                          compressed as they come.




                          Very nice! God bless BTRFS!



                          Also, from 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.







                          share|improve this answer


























                            2












                            2








                            2







                            According to ArchWiki:




                            Tip: Compression can also be enabled per-file without using the
                            compress mount option; simply apply chattr +c to the file. When
                            applied to directories, it will cause new files to be automatically
                            compressed as they come.




                            Very nice! God bless BTRFS!



                            Also, from 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.







                            share|improve this answer













                            According to ArchWiki:




                            Tip: Compression can also be enabled per-file without using the
                            compress mount option; simply apply chattr +c to the file. When
                            applied to directories, it will cause new files to be automatically
                            compressed as they come.




                            Very nice! God bless BTRFS!



                            Also, from 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.








                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 12 '15 at 2:58









                            GeremiaGeremia

                            1216




                            1216























                                -9














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






                                share|improve this answer



















                                • 11





                                  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
















                                -9














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






                                share|improve this answer



















                                • 11





                                  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














                                -9












                                -9








                                -9







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






                                share|improve this answer













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







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered May 6 '12 at 11:16









                                DiegoDiego

                                11




                                11








                                • 11





                                  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














                                • 11





                                  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








                                11




                                11





                                Not true, you have to pass compression= "your favorite compression algorithm" in fstab to enable it.

                                – turbo
                                Jul 24 '12 at 12:36





                                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





                                @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





                                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


















                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f129063%2fwill-btrfs-automatically-compress-existing-files-when-compression-is-enabled%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                                How to change which sound is reproduced for terminal bell?

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?