Hard disk bad track detection tutorial under Linux

  

Winchester disk: (hard disk principle)

The general principle is that the non-working time head stays in the landing zone; when the data needs to be read, the head leaves the landing zone. Relying on the rotation of the disc produces lift to suspend the data on the surface of the disc. Because the disk rotates very fast, and the head is very close to the disk (one thousandth of the hair), if the vibration or external force, even the voltage is unstable, the magnetic head and the high-speed rotating disk may be generated. Physical contact, causing irreparable physical damage.

When your disk: When reading a file or running a program, the hard disk repeatedly reads the disk and makes a mistake, prompting the file to be corrupted, etc., or it takes a long time to succeed; sometimes it may appear Deadlock; io wait for no reason to increase or stay high; the sound of the hard disk suddenly changed from the normal friction sound to a strange sound; the system can not start normally, there is a message such as "IO error"; mkfs, when a certain schedule stops Finally, the error is reported and cannot be completed; every time the system is booted, it will automatically run fsck to scan the disk error; when FDISK is executed on the hard disk, it will go back and forth repeatedly to a certain progress; if your disk has the above situation, you need to perform the disk in time. Bad track detection to test disk availability and back up data immediately.

Read-only detection of the disk: sudo badblocks -s -v /dev/sd* Because the disk needs to be detected, the speed is very slow, do not power off during the detection process, do not carry out the hard disk Do not remove the hard disk for any operation, do not physically damage, do not vibrate, etc.

The detection process can be terminated midway, or you can specify the block to restart. Sudo badblock -s -v /dev/sd* last start

If you see Pass completed after the test is completed, 0 bad blocks found.

So congratulations, this disk passed the test, no bad Road (bad block). You can use

with confidence. However, if one of the blocks is stagnant during the detection process and the report indicates a bad block, then the cup has …… your disk has bad sectors. Regardless of the type of bad sectors, it is recommended that you first back up your data! Back up your important data and try to fix it. If you have important data but can't read it (the disk is abnormal), stop using it and find a professional to fix it. Bad track repair/shield Common bad sectors are classified into the following types: logical bad sectors 0 track damage physical bad sectors

Bad sectors generally appear in separate or combined form. Logical bad track repair: fsck -a /dev/sd* is as simple as that. For more fsck usage you can check it out here or check out the man page.

0 track damage repair: use 1 track instead of zero track (operational caution should be cautious) The general process is to format the whole disk, then re-partition, edit the partition table to use 1 track, thus reviving the hard disk. Physical bad sectors Physical bad sectors have no repair possibilities and can only be shielded. If you have already performed bad track detection, then you must already know the approximate location of the bad sectors (bad blocks) and the size of the bad blocks. You need to: backup the hard disk data to delete all hard disk partitions based on the location and size of the bad blocks, and estimate the occupied space ( For example, a total of 100 blocks, the disk size is 100g, 20-30 is damaged, then the bad block is partitioned in the interval of 20-30g (connected: the partition should be 0-15| 15-35| 35-100, the middle 15-35g is a partition with bad sectors. To expand the partition with bad sectors, the value should not be too small, so as to avoid bad sectors being divided into other partitions. Isolation 15-35g partition (that is, no mount, no read/write, no operation), your disk free space is reduced, but the remaining space is available (bad sectors are blocked)

Because physical bad sectors have diffusion Sex, so it is recommended to let the disk "retire" as soon as possible ……

partition table repair tool If your partition table has been damaged, it is recommended to use testdisk to fix it. He can quickly restore the partition table, it is very easy to use (fix my hard drive n times! The weapon is also ~)

sudo apt-get install -y testdisk

Love the disk, love the data disk Valuable, data is priceless

Do not wait for the disk to have problems before thinking that the data has not been backed up; not until the paper is lost, I think it will be paid tomorrow; don't wait for rm to think of deleting important files. It is. Backing up your data is not that difficult and doesn't take much time, so please back up in time to protect the priceless data!

In the long-term operation of the disk, it will inevitably lead to bad sectors. The Linux server running in the computer room is no exception. The following describes how Linux repairs bad sectors of the disk. Remind that the server or server must be u>Computer
After disconnecting the network, do this after stopping other work. After a bad track on a computer hard disk, if it is not replaced or technically processed, there will be more bad sectors and frequent crashes and data loss. It is best to re-partition the hard disk in the bad sectors of the hard disk, divide the bad track part into a separate area, and hide it. There are two ways to fix the bad sectors of the hard disk under Linux. I will introduce the two methods below. They are modified in the ext2 file format. The same applies to the ext3 format, because ext3 is only ext2+journal.

Repair Method 1

In order to check for bad sectors, you can use the mkfs.ext2 command with the parameter -C to check the hard disk in read-only mode. We use the man command to view “mkfs.ext2” need to bring the parameters, enter the following command:

#man mkfs.ext2

The result can be seen by the display “mkfs.ext2&rdquo ; functions and parameters that can be supported.

#man mkfs.ext2mke2fs [ -c |  -l filename ] [ -b block-size ] [ -f fragment-size ] [ -i……

The above code indicates that the -c is used to check for bad sectors before creating the file system, -b is The size of the block, the size of the -f fragmentation. This operation has clearly told us that we can use the “mkfs.ext2 -c” option to check the hard disk in the "read-only" mode. This command will check the hard disk when formatting the hard disk and mark the wrong hard disk <block”. Formatting the hard disk in this way requires considerable patience, because after the command is run, the hard disk is checked one by one. The practice is as follows:

# mkfs.ext2 -c /dev/hda1sata with mkfs.ext2 -c /dev/sda1

Repair Method 2

According to experience, bad sectors It usually spreads to other areas, especially the adjacent "block”. In addition, some "block" will have the following situation: one or two of 16 reading and writing will have read and write errors. The specific repair method is similar to this, as follows: Enter the following command: # man badblocks

Check the parameters of badblocks, and you can see the function that can be supported by the display. And parameters.

NAMEbadblocks - search a device for bad blocksbadblocks [ -svwnf ] [ -b block-size ][ -c blocks_at_once ] [ -i input_file ][ -o output_file ] [ -p num_passes ] device [ last-block ] [ start-block ]-b block-size-c number of blocks…… The above instructions indicate that badblocks check for bad sectors on a device; -b is the size of the block, -c is the number of checks, -i The output file, -o input file, -p is the number passed.

The hard drive will specify a size of “block” when formatting. The default value is “block 4K ”(4K/block). “badblocks” When checking bad sectors, I don't know the “block-size” specified in the future when I want to format, so I have to tell “badblocks” block size”.

“-c number of blocks” is the number of checks, the default is 16 times. Such commands require patience. The syntax is as follows:

# badblocks -b 4096 -c 16 /dev/hda1 -o hda-badblocks-list


where, “badblocks” Block, check each block 16 times, and output the result to the file "hda-badblocks-list".

“hda-badblocks-list” is a text file with the following contents:

# cat hda-badblocks-list5124951250512515125351254……61245……


If you want to find suspicious "blocks” and together “mark”, you can do more operations on suspicious blocks:

# badblocks -b 4096 -c 1 /Dev/hda1 -o hda-badblocks-list.1 63000 51000


“badblocks” 4096 bytes for one “block”, each “block” check 1 time , output the result to the "hda-badblocks-list.1" file, starting with the 51000 block and ending with the 63000 block. The time spent this time is relatively short, and the hard disk generates a sound of “嘎嘎嘎嘎” in a short period of time. The output is not exactly the same due to different inspection conditions.

# cat hda-badblocks-list.151248512505125151253……6124361245……

Repeat the above operations several times, depending on the conditions, so the results are different. After multiple operations, the final "hda-badblock-list.final" is generated, and finally the hard disk is formatted. Enter the following code:

#man mkfs.ext2

The results can be seen to show the functions and parameters that can be supported by “mkfs.ext2 ”.

NAME mke2fs – create an ext2/3 filesystemmkfs.ext2 is used to create an ext2/3 system file.

Summary

The above is the solution to the bad sectors of the hard disk under Linux. I hope these methods can bring you help.

The hard disk has bad sectors. If it is not because of aging problems, it means that there are some irregularities in the use. For example, the hard disk is defragmented too frequently, the memory is too small, and the application software frequently accesses the hard disk. Ignoring the dust-proof processing of the hard disk can also cause the mechanical head of the hard disk to cause mechanical failure due to difficulty in positioning. In addition, the overclocking of the CPU causes the FSB to increase, forcing the hard disk to work under excessive voltage for a long time, which may also cause a malfunction. Therefore, the usual use of the hard disk should be based on careful operation.

Copyright © Windows knowledge All Rights Reserved