Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Linux disk fragments

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the example analysis of Linux disk fragments. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

What is a disk fragment file?

When the file system reads and writes files on the disk sector, it forms a discontiguous whole, which results in disk fragmentation files. This is particularly true for FAT and FAT 32 file systems, and the NTFS file system provides some mitigation. So why does this rarely happen in the Linux operating system (extX)?

In FAT and FAT32 file systems, files are written to the right of the disks adjacent to each other, leaving no room for file growth or updates.

NTFS leaves some space between adjacent files, giving the files some room to grow and update. However, this interval is limited, and the increase of time at any time will also produce disk fragments.

Linux's log file system uses a completely different storage method, which directly distributes each file on disk for storage, leaving free space between each file, so disk fragmentation files are rarely generated.

In addition, how disk fragmentation starts to occur, most Linux file systems automatically try to reorganize files and blocks to make storage contiguous.

Defragment Linux disk files

Unless you use a small disk or frequent read and write space, disk fragmentation files rarely occur in Linux systems. Some situations that can lead to Linux disk fragmentation are as follows:

Edit large video files or RAW pictures with limited disk space

Use disks with very little space on older devices

Disk space utilization exceeds 85%

Store too many small files

Of course, the solution is to change to a hard drive with more space, or clean it up manually.

How to check for disk fragments

We can use the fsck command to detect the disk. Keep in mind that unmount must be detected when testing, otherwise the data may be corrupted. Therefore, it is recommended that you execute the fsck command from Live CD and back up the important files before.

When everything is ready, we execute the following command:

Fsck-fn [/ path/to/your/partition]

Where [/ path/to/your/partition] is the path we want to detect, and a large amount of information will be output during the test, which will eventually report to us the relevant information of a disk fragment:

Note: if the disk fragmentation is more than 20%, we need to defragment it. If it is less than 20%, it can be suspended for the time being.

A simple way to organize the Linux file system

It is not so much to clean up the disk as to delete it and start all over again. The operation mode of Linux is completely different from that of disk demarcation under Windows. Because Linux is a file-based system, we just need to copy all the files on disk to another place, format them, and then copy the backed-up files back. When you copy it back, Liunx automatically arranges the files in a continuous distribution.

1. Back up the source disk file using the following command

Cp-afv [/ path/to/ source disk] / * [/ path/to/ backup folder]

Note: many friends will think that it is better to use dd files to copy files in bulk, but dd has a lower level of operation and will copy a lot of junk information. Our goal is to clean up the disk, so use the cp command.

two。 Now let's delete the source file using the following command

Sudo rm-rf [/ path/to/ source disk] / *

Optional: of course, you can also fill the source disk with 0 directly through the following command to achieve the purpose of emptying.

Sudo dd if=/dev/zero of= [/ path/to/ source disk] / temp-zero.txt

3. You can use the pv command to monitor the execution of dd commands:

Sudo apt-get install pvsudo pv-tpreb | of=of= [/ path/to/ source disk] / temp-zero.txt

4. When the execution is complete, we delete the temporary file

Sudo rm [/ path/to/ source disk] / temp-zero.txt

5. After the disk is zeroed (reliable), we can copy the backed up files back.

Cp-afv [/ path/to/ backup folder] / * [/ path/to/ source disk]

Use e4defrag

If you find the above steps too troublesome, you can also use the e2fsprogs command

1. Install e2fsprogs

Sudo apt-get install e2fsprogs

two。 Executive arrangement

Sudo e4defrag /

Note: although the above commands are convenient, not all systems can be executed successfully.

This is the end of this article on "sample analysis of Linux disk fragments". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report