115

Why is defragmenting unnecessary in Ubuntu?

JJJ
  • 103
Zango
  • 5,011
  • 3
    It is not unnecessary, and depending on your use, you may want to defrag every once in a while. XFS/ext4 are both simple to defrag. Just use the tools for them, they will be done in no time. EXT4 (Ubuntu default - https://ext4.wiki.kernel.org/index.php/Ext4_Howto#Online_defragmentation) – Apache May 12 '14 at 15:37

5 Answers5

66

The underlying filesystems used by Ubuntu, like ext2 and ext3, simply don't need defragmenting because they don't fragment files in the same way as NTFS. There are more details at ext3 - Wikipedia, the free encyclopedia

blade19899
  • 26,704
Dave Child
  • 1,315
  • 4
    Ubuntu is actually using ext4 now. – Marco Ceppi Aug 05 '10 at 12:50
  • 20
    ext4 is based on ext3 is based on ext2. :) – Broam Aug 05 '10 at 16:28
  • 52
    -1. Actually, they might very well need defragmentation, just to a much lesser degree. – andol Aug 05 '10 at 19:06
  • Agree with @andol: if you actually read that link it clearly says there is fragmentation, and there might be even a tool included to do so. – Nanne Dec 01 '12 at 08:51
  • 3
    If you have a SSD you do not have to defragment it either. – Lekensteyn Dec 01 '12 at 08:52
  • 4
    @andol, having some fragmentation does not mean you need to defrag. Windows "needs" it because it creates ridiculous levels of fragmentation. A small amount doesn't make any real difference, and Linux is very good at keeping it to an absolute minimum. – psusi Nov 18 '13 at 02:23
  • 2
    Here there is a briefly and simple explanation of how ext2fs works to avoid big fragmentation issues: http://geekblog.oneandoneis2.org/index.php/2006/08/17/why_doesn_t_linux_need_defragmenting But still it suffers a little bit. – Akronix May 19 '14 at 10:13
59

Some argue that it's actually a myth that we don't need defragmentation. It's argued that we do in fact need it, but only once the filesystem gets pretty full (i.e. less than ~10% free space). Tools are available for defragging such as e2defrag.

popey
  • 23,667
  • 17
    And those "some" are correct. It's not possible to not-fragment if there's just plain nowhere else left to write. – maco Aug 14 '10 at 03:41
  • 2
    Well one could argue that when you have less than 10% free space defragging for more free space isn't going to be your biggest problem and that a new hard disc could be wiser decision ;-) – Rinzwind May 10 '11 at 09:44
  • 7
    Watch out! Taken from this website:http://en.wikipedia.org/wiki/Ext3#Defragmentation " There is no online ext3 defragmentation tool that works on the filesystem level. An offline ext2 defragmenter, e2defrag, exists but requires that the ext3 filesystem be converted back to ext2 first. But depending on the feature bits turned on in the filesystem, e2defrag may destroy data; it does not know how to treat many of the newer ext3 features." – Celso Jan 22 '12 at 17:34
  • 7
    @Celso, see http://launchpad.net/e2defrag... it now does understand ext3/4. – psusi Jul 13 '13 at 18:28
26

Fragmentation is the product of writing files in the first available open blocks on a drive. Over time, as files get created and deleted, small sections of disk open up, which causes newly written files to be split over several such openings. This can reduce performance, although it was much more of a problem in the past with slow hardware and slow disks.

The default filesystem in Ubuntu, ext4 (and until recently, ext3) are designed to limit fragmentation of files as far as possible. When writing files, it tries to keep the blocks used sequential or close together. This renders defragmentation effectively unnecessary.

psusi
  • 37,551
9

See this link. It gives quite a detailed explanation of how files are stored in Windows and in Linux, and why Linux filesystems usually do not need to be defragmented.

  • 3
    A link only answer isn't very useful if the link broke, please add a sum up of the article. – PhoneixS Jan 08 '20 at 11:54
  • 1
    But... The top voted answer is just a link to Wikipedia. – Daniel Darabos Oct 01 '21 at 20:08
  • 1
    Links seems to be broken, here is an archived version: https://web.archive.org/web/20160711220346/http://geekblog.oneandoneis2.org/index.php/2006/08/17/why_doesn_t_linux_need_defragmenting – Derkades Oct 29 '21 at 13:28
4

Ext4 Howto - Ext4 According to this article ext4 defragments on the fly but they are working on a defrag tool. I personally don't think it is needed except maybe for file servers that get heavy use.

blade19899
  • 26,704