Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    ntfstruncate binary for Debian (resetting NTFS bad clusters counter)

    1st March 2010

    There is an excellent step-by-step instruction on resetting the bad clusters counter of an NTFS partition with linux-ntfs tools. I’ve checked – it works as expected:

    1. Back up important data from partition just in case
    2. Find out size of ‘$Bad’ attribute in $Badclus using ntfsinfo -i 8 partition (partition is for example /dev/sda1). It will be the “Allocated size” value in the “Dumping attribute $DATA (0x80)” (there will be two 0x80 attributes. Only one has an “Allocated size” line). Let us write down (remember) this size as ntfs_size.
    3. Use ntfstruncate partition 8 0x80 ‘$Bad’ 0 to set $Bad’s attribute length to zero.
    4. Use ntfstruncate partition 8 0x80 ‘$Bad’ ntfs_size to set $Bad’s attribute length back to proper value ntfs_size which was recorded in step 2.
    5. Boot into Windows and run chkdsk -f diskname. It will find errors and should fix them.

    However, Debian’s ntfsprogs package does not have the ntfstruncate binary.

    Here’s how you can easily build one yourself (you may need a few extra packages with build tools for that):

    1. apt-get source ntfsprogs
    2. cd linux-ntfs-2.0.0
    3. ./configure && make extra
    4. cd ntfsprogs && ./ntfstruncate

    You can also install ntfstruncate system-wide, but I have no idea if that will interfere with the already-installed ntfsprogs package, so I just used this binary directly from linux-ntfs-2.0.0/ntfsprogs.

    Bad clusters happen not only when cloning an NTFS partition between 2 physical hard disk drives. Once, after a brief blackout (with a turned on PC, and not on a UPS), the SMART status of my new HDD started showing 1 ‘Pending sector’. Correspondingly, all the SMART tests (performed with a smartctl utility) reported read errors. To help my HDD examine and fix the problem itself, I performed a write operation to that single unreadable sector, which restored it (and reset the ‘Pending sector’ counter back to zero). It was possible, because not the physical sector itself, but the hidden CRC field had errors after power failure; modern hard drives can detect and fix this kind of errors upon write operations (read operations only mark the sector as ‘pending’, because data read is not consistent with the stored CRC).

    However, NTFS partition still had 4096 bytes in ‘bad clusters’. A little research revealed the presence of internal NTFS bad clusters counter, which can be reset following the procedures above.

    StumbleUponDeliciousCiteULikePocketKindle ItEvernotePinterestShare

    3 Responses to “ntfstruncate binary for Debian (resetting NTFS bad clusters counter)”

    1. Netanel_H Says:

      Thanks for the useful information. One note: ‘copy paste’ of the commands may cause errors in ntfstruncate, because ’0×80′ is NOT the same as ‘0x80‘. the first may cause error, the second end with success.

    2. Bogdan Says:

      Thanks for noticing and reporting. This is because of wp_texturize.
      I think I’ve fixed this issue now (every ‘x’ between digits is now wrapped into ‘code’ tag), but I haven’t tried if that works.

    3. Bogdan Says:

      Also, the link to linux-ntfs no longer takes to the proper page. I’ll resolve that issue as time permits.

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>