If you are a Linux user, you may have heard that you do not need to fragment the disk of your Linux File System. You may have noticed that there is no disk fragment tool in the liunx installation package. Why?
To understand why Linux file systems do not require disk fragmentation-But Windows does-you need to understand the principles of disk fragmentation and the differences between Linux and Windows file systems.
What is disk fragmentation?
Many Windows users, or even inexperienced users, are confident that frequent file system fragmentation will increase the computer's speed. However, not many people know the original principles.
Simply put, a disk drive has many sectors, and each sector can store a small segment of data. The storage of files, especially large files, occupies many different sectors. Suppose that you have many file systems, and each file is stored in a series of continuous slices. Later, you updated one of the files, and the size of the files increased. The file system will try to store the new part of the file in the sector next to the original file. Unfortunately, there is no consecutive sector space around it, and the file needs to be split into several segments-these are all automatically performed. When reading this file from a disk, the disk head needs to read each sector across several different physical locations-this reduces the speed.
Disk fragmentation means to move these small file blocks carefully to reduce fragments so that each file can be continuously distributed on the disk.
Of course, if it is a solid state disk, the situation is different. The solid state disk does not move mechanically and should not be fragment-fragment of a U disk usually reduces its life. In the latest version of Windows, you do not need to worry about system fragments. Windows will automatically sort the fragments for you.
Working principle of Windows File System
Microsoft's old fat file system-the last time it was used on Windows 98 and Windows ME, but today's USB flash drives are still using it-it does not intelligently manage files. When you store a file in the FAT file system, the system tries its best to store it near the start of the disk. When you store the second file, it is followed by the first file-one after another. When the size of the original files increases, they will surely produce fragments. There is no room for them to grow.
Microsoft's new NTFS file system-on a PC with Windows XP and 2000-is a little smarter. It will allocate some "buffered" free space around the file on the disk. However, any Windows user will tell you that after a period of use, NTFS file systems still form fragments.
Due to the operating principles of these file systems, they are doomed to require fragment to maintain high performance. Microsoft solves this problem by running a disk fragment process in the background in its latest Windows system.
Operating principle of Linux File System
Linux ext2, ext3, and ext4 file systems -- ext4 is used in Ubuntu and most of the latest Linux releases -- a smarter way to store files. Different from placing multiple files on a disk, the Linux file system distributes all files to the entire disk, leaving a considerable amount of free space between each two files. When files are modified and their volume increases, they usually have enough space to expand. Once fragments are generated, the file system will try to move the entire file to eliminate the fragments, so you do not need a fragment tool.
In this way, when the disk is about to fill up, you may find fragments starting to generate. If the used space exceeds 95% (or even 80%), you will find that the number of fragments starts to increase. But in any case, the design of this file system will not produce fragments under normal circumstances.
If you encounter disk fragmentation problems in Linux, you may need a larger hard disk. If you really want to organize a file system, the simplest way is perhaps the most reliable: To test the file from this partition, delete these files, and then test back these files. When you test the file back to the hard disk, the file system intelligently allocates storage space for the file.
You can use the fsck command to view the disk fragments on the Linux File System-search for "non-contiguous inodes" in the output results.