Add & execute package to Defrag a fragmented Ext3 Volume under BusyBox in Synology CS407? How?

Note: Debunking the myth of Linux Filesystems not getting fragmented. http://www.webupd8.org/2010/03/install-defrag-defragmentation.html

But that's a common misconception and in some cases you do have to defragment your Linux filesystems. This is even confirmed by an Ubuntu developer on a very recent post I stumbled upon just a few minutes ago about ureadahead on the ubuntuforums.
From: Ubuntu Forums Post: http://ubuntuforums.org/showthread.php?t=1434502
The only way to avoid this is defragmenting your disk.

But Linux filesystems don't need defragmenting!

Whoever told you that is deeply mistaken, this is one of the most common myths of Linux.

What is true is that Linux filesystems avoid, where possible, fragmenting their inode tables. This means that the index of how files are split up (fragmented) across the disk, and where those parts are, tends to be kept together as a whole.

That's a good thing; fragmentation of inode tables is a big problem for other filesystems (FATs in that filesystem, etc.) so by keeping them together, it wins a lot of performance.

But the data itself is still fragmented, and spread all over your disk in a random order. And unfortunately during boot, it's the data we need.

One of the future things we want to do is use the ureadahead analysis of what we need during boot to feed into a defragmenter, so everything we need is in one big block on the disk.


Apparently, the CS407 uses a Marvel processer 88f5281 so it might need something like a specially built optware/ entware first. Please, do guide more in this direction if possible.


Based on the steps & lessons in these 2 links I ran the following (key stuff marked & bolded with double Asterix):

Busybox Version:
BusyBox v1.16.1 (2011-04-08 10:15:04 CST) built-in shell (ash) Enter 'help' for a list of built-in commands.

Commandline Input & Output:
CubeStation> /usr/syno/etc.defaults/rc.d/S80samba.sh stop CubeStation> df Filesystem 1K-blocks Used Available Use% Mounted on /dev/md0 2451064 478484 1870180 20% / /tmp 63396 288 63108 0% /tmp /dev/md2 2879637816 2336710312 542825104 81% /volume1 CubeStation> unmount /volume1 -ash: unmount: not found CubeStation> sudo unmount /volume1 -ash: sudo: not found CubeStation> syno_poweroff_task CubeStation> df Filesystem 1K-blocks Used Available Use% Mounted on /dev/md0 2451064 478460 1870204 20% / /tmp 63396 284 63112 0% /tmp CubeStation> vgdisplay CubeStation> e2fsck -v -n -f /dev/md2 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity /lost+found not found. Create? no Pass 4: Checking reference counts Pass 5: Checking group summary information 1.41.12-1613: ********** WARNING: Filesystem still has errors ********** 42150 inodes used (0.02%) 3618 non-contiguous files (8.6%) 20 non-contiguous directories (0.0%) # of inodes with ind/dind/tind blocks: 20326/8705/71 595654428 blocks used (81.44%) 0 bad blocks 114 large files 36634 regular files 4434 directories 0 character device files 0 block device files 0 fifos 1 link 1073 symbolic links (1073 fast symbolic links) 0 sockets

What can I do to DEFRAG the volume FS & the non-contiguous data?

  • One thing I immediately noticed, you typed unmount which is incorrect, should be umount. Also fragmented files are not an issue/error, it simply means that if you're using a magnetic rotating hard disk, the system have to make a few extra disk seeks to the hard disk to piece together your files, this is handled automatically by the system, and it's quite normal to have them. – Lie Ryan Apr 10 '17 at 2:11
  • @LieRyan - Yes, honest mistake. I know what fragmentation is, and I'd like to once in a while do a defrag (which I know most *nix people say is not needed). I'd like to defrag my NAS - How can I add & execute one of the defrag tools in the *nix space? (few linked above) – Alex S Apr 10 '17 at 4:20
  • The old-school method - before defragmentation software in any OS - was simply to move the files to another location, format the original partition/volume, and then move them back. You might even skip the formatting portion. – Christopher Oct 17 '19 at 12:04

When running commands from the internet, it's always a good idea to cross check what the commands does with the manual page.

In your specific case, your e2fsck command:

e2fsck -v -n -f /dev/md2

If we check what this commands does in the e2fsck man page you'll see:

-n Open the filesystem read-only, and assume an answer of ‘no’ to all questions. Allows e2fsck to be used non-interactively. (Note: if the -c, -l, or -L options are specified in addition to the -n option, then the filesystem will be opened read-write, to permit the bad-blocks list to be updated. However, no other changes will be made to the filesystem.)

So what the -n flag does is to do a disk check without repairing any issues it found. You'd want to remove this flag to let it repair issues. You'll get prompts for each issue e2fsck found and try to repairs. If you want e2fsck to just repair everything without prompts, add -p flag:

-p Automatically repair ("preen") the file system without any questions.

| improve this answer | |
  • Appreciate the detailed response. I am already aware of the -n making it "read only" as that was the initial objective to check it for fragmentation - which people say Linux Ext systems never have. I can run it again without the Read flag, but how do I defrag it? – Alex S Apr 10 '17 at 4:17
  • How can I add & execute one of the defrag tools in the *nix space? PS: Please add this part as that is the key part of question that I cant resolve – Alex S Apr 10 '17 at 4:21
  • @AlexS: ext2 filesystem can have fragmentation, but it does not need defragmentation. I can give you scripts/commands to run that means you feel good, if that's what you want, but they won't do any good for the system. Your e2fsck result does not indicate that you need to do any defragmentation. Linux disk allocators and IO scheduler prevents problematic disk fragmentations from forming and makes use of fragmentations to improve throughput. – Lie Ryan Apr 10 '17 at 13:01
  • Most of the stuff on my NAS is media (mostly read only to watch, except when I am uploading new collections to it). I'd like to keep the media as contiguous as possible. I'd really appreciate if you can help me add the right defrag package & execute it on this "limited" BusyBox Linux. PS: I get the throughput v/s contiguous thing - I'd like to make it contiguous. Thanks. Please guide. – Alex S Apr 10 '17 at 18:13
  • @AlexS: I can point you to a Synology's documentation on how to set up cross compiler and build a custom package for your device. But given your lack of basic knowledge about Linux systems maintenance, you are more likely to get into trouble and lose data than any issue you might think you could "fix" by defragging. Note that all existing ext2 defrag software are abandonware, you are very likely to lose data by running a defrag software. They're effectively abandoned experiments because people don't find them doing any better than just "sleep 3h; echo 'defragmentation complete'". – Lie Ryan Apr 11 '17 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.