How to defrag ext4 - e2fsprogs installed but no defrag

Is not the e4defrag supposed to be part of the e2fsprogs package that when I try to install claims it is already in the kernal?

1 Like

Could you be thinking of e2freefrag? I don't see an e4defrag package listed anywhere and it's not listed on my device even though i have e2fsprogs installed (19.07.3).

Do you really need that? I haven used any defrag in decades...


I was drawing at straws ... uneducated in the world of Linux and a career Windows user, the concept of file permissions often escapes me. When I copied files on my OpenWRT Linux server using the cp command sourcing from a NTFS USB disk to the espressobin internal drive (native SATA), I found that while I could still access the original files on that server, I could not access the new files I copied when accessing them via a Samba share to Kodi on my Android TV device. which was share d from the OpenWRT device. Since I could access all files equally from a Windows Samba share to the same OpenWRT server, it was not obvious at first that the default file permissions of the cp copy command were at a level of 500 and that permission level needed for the Android was 755. So since everything appeared perfect from a Windows Samba share to the same OpenWRT device, that at first led me to believe that something was corrupted in the copy routine, particularly since I was doing something I had never done before, copying a large repository on "foreign" Linux via the cp command and from very two dissimilar file systems, NTFS to EXT4.

First wrongly assuming that the file copy was corrupt, I first spent hours trying to unmount my drive to run a fsck on it (actually e2fsck) but at last I discovered that I had the Windows WinSCP program running and while i wasn't paying attention, each time I rebooted the server, the application would cycle and re-attach to OpenWRT and into the same directory I had originally selected, a tree off the /mnt directory which I too late discovered after much grief that this was enough to keep the unmount "umount" command from working because some process had the /mnt directory open, e.g. here it was WinSCP. Then once I discovered that and killed WinSCP, I at last got the drive unmounted and I ran e2fsck where it reported dis-contiguous directories and files as the only abnormality so at that point while still grasping at straws, I did research with a few posts stating that extX file systems needed defrag even though it was not common practice. At this point came my post looking for a way to defrag.

From there and after taking a long break for a meal, the 'lost concept' of file permissions slapped me in the face and I went back to check and indeed that was the abnormality instead of a corrupt file copy (which would have likely been the culprit if the underlying OS had been Windows.) Therefore I fixed a single file permissions problem and learned a lot in the process which I will retain if my current cycle stays in tact to where next year I will encounter the same problem, do an online search and once again will return to my original post here discovering it to be new news , lost in my forgetful mind. Still the good news remains that because of this forum, no matter if later I discover I am the one to answer my own question, I still come out the winner having re-discovered it, no matter how abstract the method.