USE AT YOUR OWN RISK – HAVE A BACKUP PRIOR TO RUNNING

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 uncow.py 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 uncow.py copys data from original to this new COW disabled file, then uncow.py deletes original, and renames new COW disabled file to match original – end result: same filename, same data, but nocow). Found script here: https://btrfs.wiki.kernel.org/index.php/FAQ In the section “Can copy-on-write be turned off for data blocks?

Uncow.py 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 uncow.py) 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 uncow.py 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: https://raw.githubusercontent.com/stsquad/scripts/master/uncow.py

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

If you just want the uncow.py script:

Now to use this uncow.py

Also note that my copy paste script below will download Alex Bennée uncow.py 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 *