I want all my files in an ext4 filesystem not fragmented because of reasons. Sadly e4defrag
(advised here: How to defrag an ext4 filesystem) fails to defragment several files. What are my alternatives?
The filesystem has all files in it already (they are not to be changed in any way) and it is almost full. There are several free blocks (according to df -h
: 434M available of 85G and 80G used) which can be used as buffer. I do not need the filesystem mounted while defragmenting. Moreover, I have other filesystem available with enough space to use as a buffer.
One idea I have is to move the files to other filesystem and then copy them back somehow telling the filesystem to store them contiguously.
[EDIT]
I have just found that I cannot rely on e4defrag
output. It counts files with more than one extent as fragmented, while it knows that the extents are contiguous:
$ sudo filefrag file.file
file.file: 1 extent found
$ sudo e4defrag -vc file.file
e4defrag 1.45.5 (07-Jan-2020)
<File>
[ext 1]: start 22388736: logical 0: len 32768
[ext 2]: start 22421504: logical 32768: len 32768
[ext 3]: start 22454272: logical 65536: len 32768
[ext 4]: start 22487040: logical 98304: len 27962
Total/best extents 4/1
Average size per extent 126266 KB
Fragmentation score 0
[0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
This file (file.file) does not need defragmentation.
Done.