Sometimes you dont want COW, because COW is copy on write and causes fragmentation where there are alot of reads and writes all over the place (Torrents, Virtual Disks used by VMWARE & XEN & HYPERV and the like, databases,  etc)

My script below will go thru every file in the CURRENT WORKING FOLDER and uncow them (the uncow’ing happens with the python script which is not my script but Alex Bennee script – Here is how it uncows: make empty sized file, make new empty file C+attribute meaning COW disabled – because COW can only be enabled and disabled on empty files – then copys data from original to this new COW disabled file, then deletes original, and renames new COW disabled file to match original – end result: same filename, same data, but nocow). Found script here: In the section “Can copy-on-write be turned off for data blocks? is like a file defragmentor (defrag), and my whole script is like a filesystem/directory defragmentor (defrag) – the difference being that a defragmentor works block by block and does a MUCH better job, but this tool works file by file. With that said my script (and have the disadvantage that there should be enough free space to fit the biggest file in the filesystem (meaning FREESPACE should be bigger than SIZE-OF-BIGGEST-FILE)

Note it would be wise to run on files that are the most fragmented (aka have the most extents) – check out my mostfragged script at the bottom of this article to find those files: mostfragged

Actual Script is here:

Requirement for (besides having a BTRFS filesystem) is having python:

If you just want the script:

Now to use this

Also note that my copy paste script below will download Alex Bennée to /root/ and then run it on every file and folder within the current folder that your in(all the way down recursively). This will not jump across symlinks. This just uses output of find to point files & folders at uncow.




Leave a Reply

Your email address will not be published. Required fields are marked *