logo
Retrieve the name of the device
Retrieve bad blocks from a disk: badblocks
Check and repair a Linux file system: fsck
Mark bad sectors as 'unusable' sectors: fsck and badblocks

Retrieve the name of the device

To get the name of the device you want to test, you can use the 'fdisk -l' command as root (or sudo 'command') as for all the following commands. Another way is to look in the '/etc/fstab' file. For the rest of this article the disk name will be '/dev/sdX'.

Retrieve bad blocks from a disk: badblocks

This command line utility is used to find sectors of a device that can not be used due to permanent damage, like physical damage. You can run it in read only mode (default), or in read/write non destructive (preserve data) mode.
 
 #read only
 badblocks -sv /dev/sdX
 
 #read/write non destructive partition need to be unmounted
 badblocks -nsc /dev/sdX
 

Check and repair a Linux file system: fsck

fsck must be run on an unmounted device (umount /dev/sdX) if it is not needed by your system. You can also run it on the system device.
To check all the partitions now:
 
 shutdown -Fr now
 
To check a partition we just create an empty file named 'forcefsck' on the root of the partition:
 
 touch partitionMountpointPath/forcefsck
 
To check an unmounted ext3 partition n and interactively fix it:
 
 fsck -t ext3 /dev/sdXn
 
To check an unmounted ext3 partition n and fix it automatically (can be dangerous):
 
 fsck -at ext3 /dev/sdXn
 
To check your partition n every 10 boots:
 
 tune2fs -c 10 /dev/sdXn
 

Mark bad sectors as 'unusable' sectors: fsck and badblocks

Fsck can use badblocks to find the bad blocks and add it to the bad block inode to mark it as unusable. We can ask for a simple read only test '-c', or a non destructive read/write test '-cc'.
 
 fsck -cct ext3 /dev/sdXn
 
I hope this article helped you to fix your computer. :)
Be The First To Comment.

Add a comment:





You can use these HTML tags: <br><a><i><b>