{"id":12475,"date":"2019-03-27T02:05:54","date_gmt":"2019-03-27T02:05:54","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12475"},"modified":"2019-03-27T02:05:54","modified_gmt":"2019-03-27T02:05:54","slug":"how-to-check-bad-sectors-or-bad-blocks-on-hard-disk-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/how-to-check-bad-sectors-or-bad-blocks-on-hard-disk-in-linux\/","title":{"rendered":"How to Check Bad Sectors or Bad Blocks on Hard Disk in Linux"},"content":{"rendered":"<p>Let us start by defining a bad sector\/block, it\u2019s a section on a disk drive or flash memory that can not be read from or written to anymore, as a result of a fixed\u00a0<a href=\"https:\/\/www.tecmint.com\/defragment-linux-system-partitions-and-directories\/\" target=\"_blank\" rel=\"noopener\">physical damage on the disk<\/a>\u00a0surface or failed flash memory transistors.<\/p>\n<p>As bad sectors continue to accumulate, they can undesirably or destructively affect your disk drive or flash memory capacity or even lead to a possible hardware failure.<\/p>\n<p>It is also important to note that the presence of bad blocks should alert you to start thinking of getting a new disk drive or simply mark the bad blocks as unusable.<\/p>\n<p>Therefore, in this article, we will go through the necessary steps that can enable you determine the presence or absence of bad sectors on your Linux disk drive or flash memory using certain\u00a0<a href=\"https:\/\/www.tecmint.com\/ncdu-a-ncurses-based-disk-usage-analyzer-and-tracker\/\" target=\"_blank\" rel=\"noopener\">disk scanning utilities<\/a>.<\/p>\n<p>That said, below are the methods:<\/p>\n<h3>Check Bad Sectors in Linux Disks Using badblocks Tool<\/h3>\n<p>A\u00a0<strong>badblocks<\/strong>\u00a0program enables users to scan a device for bad sectors or blocks. The device can be a hard disk or an external disk drive, represented by a file such as\u00a0<strong>\/dev\/sdc<\/strong>.<\/p>\n<p>Firstly, use the\u00a0<a href=\"https:\/\/www.tecmint.com\/fdisk-commands-to-manage-linux-disk-partitions\/\" target=\"_blank\" rel=\"noopener\">fdisk command<\/a>\u00a0with superuser privileges to display information about all your disk drives or flash memory plus their partitions:<\/p>\n<pre>$ sudo fdisk -l\r\n<\/pre>\n<div id=\"attachment_23211\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/List-Linux-Filesystem-Partitions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23211\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/List-Linux-Filesystem-Partitions.png\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/List-Linux-Filesystem-Partitions.png 774w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/List-Linux-Filesystem-Partitions-768x415.png 768w\" alt=\"List Linux Filesystem Partitions\" width=\"774\" height=\"418\" aria-describedby=\"caption-attachment-23211\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23211\" class=\"wp-caption-text\">List Linux Filesystem Partitions<\/p>\n<\/div>\n<p>Then scan your Linux disk drive to check for bad sectors\/blocks by typing:<\/p>\n<pre>$ sudo badblocks -v \/dev\/sda10 &gt; badsectors.txt\r\n<\/pre>\n<div id=\"attachment_23214\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/Scan-Hard-Disk-Bad-Sectors-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23214\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/Scan-Hard-Disk-Bad-Sectors-in-Linux.png\" alt=\"Scan Hard Disk Bad Sectors in Linux\" width=\"695\" height=\"173\" aria-describedby=\"caption-attachment-23214\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23214\" class=\"wp-caption-text\">Scan Hard Disk Bad Sectors in Linux<\/p>\n<\/div>\n<p>In the command above,\u00a0<strong>badblocks<\/strong>\u00a0is scanning device\u00a0<strong>\/dev\/sda10<\/strong>\u00a0(remember to specify your actual device) with the\u00a0<code>-v<\/code>\u00a0enabling it to display details of the operation. In addition, the results of the operation are stored in the file\u00a0<strong>badsectors.txt<\/strong>\u00a0by means of output redirection.<\/p>\n<p>In case you discover any bad sectors on your disk drive, unmount the disk and instruct the operating system not to write to the reported sectors as follows.<\/p>\n<p>You will need to employ\u00a0<strong>e2fsck<\/strong>\u00a0(for ext2\/ext3\/ext4 file systems) or\u00a0<strong>fsck<\/strong>\u00a0command with the\u00a0<strong>badsectors.txt<\/strong>\u00a0file and the device file as in the command below.<\/p>\n<p>The\u00a0<code>-l<\/code>\u00a0option tells the command to add the block numbers listed in the file specified by filename (<strong>badsectors.txt<\/strong>) to the list of bad blocks.<\/p>\n<pre>------------ <strong>Specifically for ext2\/ext3\/ext4 file-systems<\/strong> ------------ \r\n$ sudo e2fsck -l badsectors.txt \/dev\/sda10\r\n\r\nOR\r\n\r\n------------ <strong>For other file-systems<\/strong> ------------ \r\n$ sudo fsck -l badsectors.txt \/dev\/sda10\r\n<\/pre>\n<h3>Scan Bad Sectors on Linux Disk Using Smartmontools<\/h3>\n<p>This method is more reliable and efficient for modern disks (ATA\/SATA and SCSI\/SAS hard drives and solid-state drives) which ship in with a\u00a0<strong>S.M.A.R.T<\/strong>\u00a0(Self-Monitoring, Analysis and Reporting Technology) system that helps detect, report and possibly log their health status, so that you can figure out any impending hardware failures.<\/p>\n<p>You can install\u00a0<strong>smartmontools<\/strong>\u00a0by running the command below:<\/p>\n<pre>------------ <strong>On Debian\/Ubuntu based systems<\/strong> ------------ \r\n$ sudo apt-get install smartmontools\r\n\r\n------------ <strong>On RHEL\/CentOS based systems<\/strong> ------------ \r\n$ sudo yum install smartmontools\r\n<\/pre>\n<p>Once the installation is complete, use\u00a0<strong>smartctl<\/strong>\u00a0which controls the\u00a0<strong>S.M.A.R.T<\/strong>\u00a0system integrated into a disk. You can look through its man page or help page as follows:<\/p>\n<pre>$ man smartctl\r\n$ smartctl -h\r\n<\/pre>\n<p>Now execute the\u00a0<strong>smartctrl<\/strong>\u00a0command and name your specific device as an argument as in the following command, the flag\u00a0<code>-H<\/code>\u00a0or\u00a0<code>--health<\/code>\u00a0is included to display the\u00a0<strong>SMART<\/strong>\u00a0overall health self-assessment test result.<\/p>\n<pre>$ sudo smartctl -H \/dev\/sda10\r\n<\/pre>\n<div id=\"attachment_23215\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/Check-Linux-Hard-Disk-Health.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23215\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/Check-Linux-Hard-Disk-Health.png\" alt=\"Check Linux Hard Disk Health\" width=\"764\" height=\"139\" aria-describedby=\"caption-attachment-23215\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23215\" class=\"wp-caption-text\">Check Linux Hard Disk Health<\/p>\n<\/div>\n<p>The result above indicates that your hard disk is healthy, and may not experience hardware failures any soon.<\/p>\n<p>For an overview of disk information, use the\u00a0<code>-a<\/code>\u00a0or\u00a0<code>--all<\/code>\u00a0option to print out all\u00a0<strong>SMART<\/strong>\u00a0information concerning a disk and\u00a0<code>-x<\/code>\u00a0or\u00a0<code>--xall<\/code>\u00a0which displays all\u00a0<strong>SMART<\/strong>\u00a0and\u00a0<strong>non-SMART<\/strong>\u00a0information about a disk.<\/p>\n<p>In this tutorial, we covered a very important topic concerning\u00a0<a href=\"https:\/\/www.tecmint.com\/defragment-linux-system-partitions-and-directories\/\" target=\"_blank\" rel=\"noopener\">disk drive health diagnostics<\/a>, you can reach us via the feedback section below to share your thoughts or ask any questions.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/check-linux-hard-disk-bad-sectors-bad-blocks\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let us start by defining a bad sector\/block, it\u2019s a section on a disk drive or flash memory that can not be read from or written to anymore, as a result of a fixed\u00a0physical damage on the disk\u00a0surface or failed flash memory transistors. As bad sectors continue to accumulate, they can undesirably or destructively affect &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/how-to-check-bad-sectors-or-bad-blocks-on-hard-disk-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Check Bad Sectors or Bad Blocks on Hard Disk in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12475","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12475"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12475\/revisions"}],"predecessor-version":[{"id":12476,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12475\/revisions\/12476"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}