I have a USB HDD.
I want to mount it with compression enabled. I can do in the fstab of my system or even using udev rules. The problem is that I won't mount my USB HDD on my computer only. Up to now, I used to trigger a terminal each time I mounted it.
Then, I discovered chattr +c
. This is working very well but I want to use LZO instead of ZLIB. Is there any way to be more specific and define the compression algorithm once for all?
Best Answer
btrfs will compress every file changed since it was mounted if you use:
If you want to see to it that ALL files get compressed this way, I've got a little script I wrote to do it...
The above only works on my
$HOME
directory - but you can use it on anything or everything as you like. It's also got the-n
operand fed tosh
as is so you can see for yourself whatsh
is currentlynot
doing before removing it to tell it to do it.Anyway, first it queries
du
for files inhuman-readable
format (probably redundant here since we strip that in the next step anyway) that are larger than1MB
or$((1024*1024)).
It
|pipes
its info tosed
which strips off everything before the leading/, "quotes"
the filename, builds thebtrfs filesystem defragment -verbose -flush-to-disk -compress-lzo \filename
command and hands it over a|pipe
tosudo sh
to execute.Again, it won't do anything so long as
sh --no-execute
is in effect, though.I think some very recent
btrfs
userspace tool builds do defragment entire directories recursively, but if so it's a pretty new thing, so I've always had to do stuff like this.