How to unmark an NTFS cluster as bad?

14

5

How do I unmark clusters as bad in NTFS?

Background

I mistakenly ran

>chkdsk /R

on my SSD, where

/R: Locates bad sectors and recovers readable information (implies /F)
/F: Fixes errors on the disk

And now i have a cluster marked as bad on my drive. I need to un-mark that cluster as bad.

Note: chkdsk has an option to re-evalute a cluster and return it to use:

/B: NTFS only: Re-evaluates bad clusters on the volume (implies /R)

Unfortunately that option will only un-mark the cluster if it is no longer bad. I need the cluster to be un-marked regardless.

How do i un-mark an NTFS cluster as bad?

Why are you doing this?

It doesn't matter why i, and hundreds of others, are asking the question. But the problem is that there's a bad sector on my drive. It's time to replace the drive with a new one. The way to do that is to mirror the SSD onto another SSD using Windows software mirroring.

Unfortunately, a known bug in Windows NTFS mirroring prevents the mirror from completing, as documented in KB325615:

Cannot Create Software Mirror If Disk Contains Bad Blocks

DMIO operates below the file system, and if it finds I/O errors while reading from a sector on the source disk or while trying to write the data to the destination disk, it aborts the mirroring operation.

The obvious workaround was to shrink the OS volume, so that the bad sector is past the end of the volume. In Windows 7, when you attempt to Shrink a volume it will automatically move files out of the way.

enter image description here

This is a good thing. In the olden days if you wanted to shrink a volume, you had to use a defragmentation tool that would push all the files towards the front of the drive; leaving slack space at the end.

Unfortunately there is now an unmovable file in the way: $BadClus. The Shrink defrag operation notes the unmovable file in the Event Log:

A volume shrink analysis was initiated on volume OS (C:). This event log entry details information about the last unmovable file that could limit the maximum number of reclaimable bytes.

Diagnostic details:

  • The last unmovable file appears to be: \$BadClus:$Bad:$DATA
  • The last cluster of the file is: 0xdc1ded
  • Shrink potential target (LCN address): 0xa91bd9
  • The NTFS file flags are: -S--D
  • Shrink phase: <analysis>

So:

  • i can't mirror the volume until the bad sectors are removed
  • shrinking the volume will remove the bad sectors
  • i can't shrink the volume until the sparse $BadClus file is moved
  • i can't move $BadClus while it physically occupies bad clusters
  • $BadClus will physically occupy bad clusters while NTFS thinks the cluster is bad

How do i un-mark a cluster as bad?

For people ghosting drives, too

The solution for my problem would also work for the most common case:

Someone ghosts a drive containing bad sectors to a new drive, and then the good drive still has those clusters marked as bad, even though they are good. It so happens that they have a workaround available to them:

>chkdsk /B

Except that doesn't work in my case. (And even if it did work in my case, it's not the question i am asking.)

Bonus Chatter

Of course the Kingson SSD doesn't maintain spare sectors. If it did, it could transparently remap the spare sector for me, and i wouldn't have NTFS trying to over-think thinkgs.

SpinRite

i tried SpinRite'ing the SS drive. It comes across the defective sector, but is unable to get any values from the drive:

══════════════════╤═══════════════════════════╤═════════════════════════════════
cylinder : 7,183  │     data samples : 1,999  │  first uncertain bit : · · · · ·
  sector :    17  │   unique samples :     0  │   last uncertain bit : · · · · ·
    head :   187  │  discarded sples :     0  │   uncertain bit span : · · · · ·

The number of data samples counts up to 2,000, then cycles back to zero, and keeps going.

enter image description here

After about 20 loops (i.e. 40,000 data samples) i gave up.

Cloning

Again; lets not confuse the question with the example. The question is how to un-mark clusters as bad in NTFS. Long after i give up, and throw away the SSD, the question will still remain. Don't confuse my problem for the question. That doesn't mean that i might try to actually solve my problem:

DriveImageXML reaches the bad sector, and aborts.

GParted fails to load. A graphical boot screen appears, then a console window scrolls text by, followed by black screen nothing

Clonezilla refuses to clone my SSD:

This disk contains mismatched GPT and MGR partition: /dev/sdb
It will confuse Clonezill and might make the saved image useless or fail to clone the disk.

Please fix htis issue then restart Clonezilla again.
Program terminated.

enter image description here

How do i unmark a cluster as bad in NTFS?

Ian Boyd

Posted 2013-12-26T17:55:34.783

Reputation: 18 244

@ThomasW. why even ask if you can't answer for how to fix it in linux? if all you want to say is that if fixing it from a linux live cd is fine then you don't know how but he should add a linux tag. – barlop – 2014-06-26T17:32:42.477

If your using MBR for the disk partition sgdisk -z /dev/sdb will wipe of the GPT, and the clonezilla will copy it. https://www.backup-utility.com/articles/clonezilla-this-disk-contains-mismatched-gpt-and-mbr-4348.html

– cybernard – 2018-10-10T00:33:30.360

Do you want a Windows solution or would using Linux be ok? – Thomas Weller – 2013-12-26T18:28:30.837

2

@ThomasW. i don't mind a self-booting tool; using whatever OS it likes. Of course i'd prefer a GUI tool. i got tired of using command lines in 1990. i started to looking into using CreateFile to open the volume directly; but realized i'd have to start from scratch, parsing all the undocumented data structures. i opened the volume directly for editing in my favorite hex editor but had the same down-side, having to manually parse hex structures.

– Ian Boyd – 2013-12-26T19:09:03.503

Answers

7

I'll answer the title question nothing more.1

First, do note that, if the sector is truly bad, unmarking it won't make it readable. So your cloning software is likely to choke on reading it instead.

In NTFS, a cluster is marked as bad by assigning it to a special stream, $BadClus:$Bad, a sparse file.

What you need is to

  • edit its runlist to remove the corresponding allocated block(s)
  • mark the corresponding cluster(s) as free in $Bitmap.

  • To unmark all bad blocks, there's ntfsfix -b -d (-b=clear bad block list, -d=clear/don't set "dirty" flag) (another method with ntfstruncate does exactly the same2).

    • It might introduce minor inconsistencies into metadata (in my case, a few indices apparently became unsorted), I'm not sure why, so either run chkdsk -f by hand or omit -d to trigger it at Windows startup if / in case you get FS errors.
  • To clear a specific block is much more difficult since I didn't find any existing software that can do this out of the box3. NTFS Bad Sectors Resolution: The $BadClus metafile - Katy's code describes the way - basically, it's editing the runlist and bitmap by hand.


1 Only because handling bad sectors + NTFS + cloning is too broad a topic. I'll gladly answer ones directly related to the matter at hand.
2 checked the source code of ntfsfix v2015.3.14.
3 for the insistent ones, these can't do it: ntfscat(can't read unreadable sectors),ntfscp(can't write to offset), ntfstruncate,ntfsfallocate,dd(can't open $BadClus:$Bad for writing)

ivan_pozdeev

Posted 2013-12-26T17:55:34.783

Reputation: 1 468

This should be selected as Best Answer. – Hashim – 2018-04-11T23:58:55.117

1

I had a hard drive that developed some bad clusters. I replaced it with a known good drive. The restore process restored the bad cluster data as well as the other data. This was on a Windows 7 Enterprise computer.

My solution was to run "chkdsk d: /b" (as has been suggested previously). The /b tells it (for NTFS only) to rescan previously marked bad clusters. At least in my case (and I would suspect all versions that support /b), it clears the bad cluster list immediately before beginning the read scan. Once you see the message "Removing X clusters from the Bad Clusters File" you should be able to kill the chkdsk process (as it is only reading data).

Note: The potential does exist for chkdsk to be updating the bad clusters file at the instant you kill the process if it happened to find a bad sector at the beginning of the drive. I took the risk and it successfully reset the bad clusters file without the need to download a bunch of other programs that require a full chkdsk afterward anyway. YMMV.

CasaDeRobison

Posted 2013-12-26T17:55:34.783

Reputation: 111

This actually worked. After Step 2 you just close then cmd window. Then run chkdsk d: /f which will say CHKDSK discovered free space marked as allocated in the volume bitmap. and following Windows has made corrections to the file system.. – Davor Josipovic – 2016-07-04T18:00:11.853

0

Since you are trying to mirror your disk (and it appears you are using Windows 7), there is another approach:

Use the built-in tool to create a backup to be restored on a good disk. Go to Control Panel, System and Security, Backup. There, create a system image and also a system repair disk.

After that, you can replace the old faulty disk with a good one, then retore the system to its state using the system repair disk and the backup made.

João Paulo

Posted 2013-12-26T17:55:34.783

Reputation: 1

0

the package gddrescue (gddrescue - GNU data recovery tool) should do the job for you.

Grab a Debian based standalone distro (CD or USB stick) install gddrescue with "sudo apt-get install gddrescue" then clone the SSd by opening a terminal window and issuing:

ddrescue -f /dev/sda /dev/sdb ./ddrescue.log

(where /dev/sda is the source and /dev/sdb is the target SSD)

ddrescue will try to recover the bad block and if unable skip it.

When finished chkdsk /f /b should complete the job.

visnotjl

Posted 2013-12-26T17:55:34.783

Reputation: 1

0

It looks like your goal is to shrink the size of the partition, and that Windows will not shrink it because of the $BadClus file, which exists due bad clusters.

I have an alternate solution for you which should shrink the drive without having to directly deal with the $BadClus file. Use Partition Wizard to shrink the partition. Partition Wizard is easy to use, is free for non-commercial use, can be run from inside Windows with a GUI, or from a CD or USB boot which runs a small Linux then gives you the same GUI. This program can also recover erased partitions, and convert between MBR and GPT partition tables.

I have run into problems with Windows not shrinking a partition past a certain point, then I will try Partition Wizard on the same partition which does it with no problem. I suppose the Partition Wizard is willing to ignore the $BadClus file. I have been using this program for over 8 years and finally bought the Pro version, because they earned it. I found this program as a replacement for PQMagic that I bought in 1996, which was a fabulous DOS partitioning program for smaller drives.

Erik

Posted 2013-12-26T17:55:34.783

Reputation: 1

0

First the best way to go is to clone the drive. Then use chkdsk /B on the new working drive.

Now as far as unmarking a real bad sector that is tricky. You could use:

Either product should remap the bad sector then CHKDSK /B should unmark it.

Download gparted or partedmagic ISO. Boot from it, and shrink the partition.

This will work because windows is NOT running so this software shrink the partition no matter what. Then chkdsk /B will handle the rest.

If all this fails you are now in for an ugly road of pain. You need to get a sector editor and manually edit the file system. Unfortunately, it is beyond the scope of my knowledge for NTFS. For FAT or FAT32 it is super simple.

cybernard

Posted 2013-12-26T17:55:34.783

Reputation: 11 200

@IanBoyd I believe partedmagic has a fail safe graphics mode you could try. – cybernard – 2018-10-10T00:26:12.527

As an SSD, there are no spare sectors to remap into. That is why the drive's SMART continues to note a Pending Sector Count of zero, and a Reallocated Sector Count of zero. – Ian Boyd – 2013-12-26T19:03:58.533

Katy Coe has an excellent blog that starts to delve into the guts of NTFS. But my eyes glazed over when i had to start calculating offsets, logical cluster numbers, virtual cluster numbers, and the fact that $BadClus is a spare file that is actually the size of the entire volume. i'd almost certainly destroy my (functioning) drive. – Ian Boyd – 2013-12-26T19:07:18.997

2Actually an SSD has tons of spare sectors. In fact a 120gb ssd probably has up to 8gb of spare sectors. Why your drive didn't remap it automatically is unknown to me. Use gparted and shrink the partition. – cybernard – 2013-12-26T19:07:51.780

It very well might be that this is an old, now discontinued, now unsupported, 64 GB Kingston drive. Or maybe it's just a bug in the drive's firmware where they forgot to implement sector remapping. – Ian Boyd – 2013-12-26T19:12:03.033

Also, drive cloning fails when they encounter the bad sector (at least DriveImageXML did).

– Ian Boyd – 2013-12-26T23:45:54.850

Make a bootable cd of gparted. Shrink the partition size to it minimum and then clone it. You can even use gparted to copy the partition over. If that fails you can also try Clonezilla. – cybernard – 2013-12-26T23:58:01.207

GParted fails to boot. It shows a graphical menu screen, then a console screen decompressing things, then a black screen that stays black for (at least) four minutes (at which point i hit the reset button). Clonezilla refuses to use the source disk (it's confused by an MBR partition on a dynamic disk). – Ian Boyd – 2013-12-27T00:49:24.107

Boot clonezilla english, whatever keymap you want, Enter shell,cmd You will get a prompt: Try to lsblk to identify the source and destination hard drive designations. It is critical you get the source and destination right. Change the sda and sdb below to match your system. There will be no going back and no further prompts until its done. Here is the command dd conv=noerror if=/dev/sda of=/dev/sdb bs=512 – cybernard – 2013-12-27T02:43:32.260

lsscsi may also provide helpful information in identifying the correct source and destination designations. – cybernard – 2013-12-27T03:05:13.890