Fandom

How To Wiki

How to defragment an ext3 filesystem

1,795pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

In general ext3 filesystems have very low fragmentation, so you don't need to defragment. This is because the kernel places files on the hard drive intelligently, reducing any fragmentation. Ext3 fragmentations is generally less than 10%. But if you use and ext3 filesystem to store large files, add and deleting them, on a mostly full partition, fragmentations can become very high. Greater than 50%. This is how to you can defragment a partitions.


ToolsEdit


Checking FragmentationEdit

Display partition's fragmentation percentageEdit

  • unmout the partition
  • Execute: fsck -nvf /dev/sdb2
  • Example output of a partition with 79.5% fragmentation:
fsck from util-linux-ng 2.16
e2fsck 1.41.9 (22-Aug-2009)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

1955 inodes used (0.08%)
    1554 non-contiguous files (79.5%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 1660/1224/0
3706004 blocks used (72.40%)
0 bad blocks
1 large file

1825 regular files
121 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
1946 files


Display files that are fragmentedEdit

  • Execute: shake -pvv /mnt/ext3_partition/ | awk '{ printf("%06d,%s\n", $4, $8) }' | sort > fragmented_file_list.txt
  • Wait a long time, for it to complete
  • When done, view fragmented_file_list.txt
  • Example output:
    • First column is # of fragments
    • Second column is the file that is fragmented
000001,/mnt/ext3_partition/file1.avi
000002,/mnt/ext3_partition/file2.avi
004597,/mnt/ext3_partition/file3.avi


DefragmentingEdit

  • Install shake
  • Make sure the partition is mounted with the "user_xattr" option
    • To check execute: mount
      • Example output: /dev/sdb2 on /mnt/ext3_partition type ext3 (rw,noatime,user_xattr)
    • If you don't have that option add it to /etc/fstab
      • Example: /dev/sdb2 /mnt/ext3_partition ext3 auto,noatime,user_xattr 0 0
  • Run shake to defragment
    • Execute: shake --old=0 --bigsize=0 /mnt/ext3_partition
  • Wait a long time for the process to finish


Optimizing the defragmentation Edit

  • Make as much free space as possible.
    • You wont be able to do a good defragmentation without empty space to move blocks. 15% or greater is recommended.
  • Keep a log of fragmentation, before and after, to show the improvements
    • Execute before: shake -pvv /mnt/ext3_partition/ | awk '{ printf("%06d,%s\n", $4, $8) }' | sort > fragmented_file_list-before.txt
    • Execute after: shake -pvv /mnt/ext3_partition/ | awk '{ printf("%06d,%s\n", $4, $8) }' | sort > fragmented_file_list-after.txt
    • And compare
  • Running shake multiple times, can remove more fragmentation


ReferencesEdit

Also on Fandom

Random Wiki