LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Linux - Hardware (http://www.linuxquestions.org/questions/forumdisplay.php?f=18)
-   -   Resetting NTFS bad sectors list with ntfstruncate (http://www.linuxquestions.org/questions/showthread.php?t=492114)

bleargh 10-13-2006 11:00 AM

Resetting NTFS bad sectors list with ntfstruncate
 
I cloned my Windows/Linux triple boot drive onto a larger drive with the dd command, and it is running smoothly (they have the same cylinder/head/sector settings, as far as the computer can tell, so I've had no problems). I need to resize my partitions to take up the extra space, though, and ntfsresize doesn't want to work because my old drive had some bad sectors. (dd copied the bad sectors list along with everything else. The new drive does not have any bad sectors; it just thinks it does.)

I know it's possible to make ntfsresize work around the bad sectors with a command-line switch, but, since my new drive isn't actually bad, I'd rather do it Right and reset the bad sectors list. This is possible using the ntfstruncate command, as explained on the ntfsclone documentation page, but the instructions are not complete (and the wiki and forum have been down for the last few days, so I can't get any help over there). The instructions say:

Quote:

Reseting the bad sectors list after cloning

When you clone a partition from a disk with bad sectors to a
new disk, Windows still reports bad sectors on the new disk. This is
because, by design, ntfsclone copies everything, including the bad
sector list.

While this is not strictly ntfsclone-related, some people may use the
following procedure to reset the bad sector list after cloning:
  1. Back up important data from partition just in case
  2. Find out size of ‘$Bad’ attribute in $Badclus using ntfsinfo
  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 which was recorded in step 2.
  5. Boot into Windows and run chkdsk. It will find errors and should fix them.
Unless you’re certain that the bad clusters were just an error, It is recommended to do a full surface scan using either your hard disk manufacturer’s tools or chkdsk /r after doing this.
The problem is that I don't know how to do #2. What command is used to display the $Bad attribute? What command is used to display ntfs_size?

stress_junkie 10-13-2006 04:21 PM

I think that you are going to a lot of trouble for a negligible amount of disk space. If you really wanted to do this then this is what I would have done, and which you could still do.

On the original hard disk install Norton Ghost on Windows.

Make a full backup of Windows onto an external or extra internal disk using Norton Ghost.

Use tar under Linux to back up the Linux partitions onto an external or extra internal disk.

You don't really need to back up the partition table since you want to create new partition sizes. If you did want to backup the MBR and extended partitions then you could use the dd command on Linux to back up the MBR, and use sfdisk on Linux to back up the extended partitions in the partition table.
Code:

dd if=hda of=mbr.dd bs=512 count=1 conv=notrunc,noerror
sfdisk -d /dev/hda > mbr.sfdisk

But the important thing is that you don't need to do that because you are going to create the partitions on the new disk the size that you want them to be.

Then on the new disk use the bootable Norton Ghost CD to restore the backup of Windows onto the new disk. The should be bootable at this point. You then boot Windows and run chkdsk /R to find the bad blocks.

Then boot a live Linux CD and use fdisk to create your extra partitions any size that you want.

Under Linux use the tar command to restore the data to the partitions.

Then you have to use chroot to recreate the LILO or GRUB boot sector. This is how. If your Linux root partition is on /dev/hda2 and you have GRUB boot loader then do this:
Code:

mkdir /mnt/new
mount /dev/hda2 /mnt/new
mount --bind /dev /mnt/new/dev
mount --bind /proc /mnt/new/proc
chroot /mnt/new /bin/bash
. /etc/profile
. /etc/bash.bashrc
grub-install /dev/hda

If you use LILO then I believe that running the lilo executable will do the job. I haven't used LILO for a long time.

You might also want to format your swap partition while you're in there. If it is /dev/hda3 then do this:
Code:

mkswap /dev/hda3
exit
sync
umount /mnt/new

Then you reboot the machine. You should see the LILO or GRUB menu at the appropriate time during the reboot.

That's how I would have done it.

The problem with using the dd or partimage utilities is that they have to be restored back into a partition of the same size as the original. Using Norton Ghost in Windows and tar in Linux avoids this problem. Since you can restore your LILO or GRUB boot sector using a live Linux CD and the chroot utility then that appears to me to be the most flexible way to do backups.

bleargh 10-13-2006 04:49 PM

Quote:

Originally Posted by stress_junkie
I think that you are going to a lot of trouble for a negligible amount of disk space.

A lot of trouble?? And then you give me five pages of instruction on how I could have done it differently? I am not asking how to clone my drive. I've already done that and everything works fine. And I did it in a much simpler way than you. I don't even have Norton Ghost. All I had to do was install System Rescue CD onto a memory stick and type
Code:

dd if=/dev/hda of=/dev/hdc
Anyway, my question is not about cloning; it's about resetting the bad sectors list. It's not even necessary; I can just use ntfsresize --bad-sectors to resize it. But I would like to reset it. I just don't understand what command is used.

stress_junkie 10-13-2006 05:10 PM

I was telling you how you could have avoided being in your current situation. I think you are making a mistake trying to use Linux utilities to modify an NTFS partition.

If you look at the commands that I showed it isn't very much, and the entire post isn't five pages. So you only entered one command, so far. You've still got to resize your partitions.

bleargh 10-13-2006 06:39 PM

Quote:

Originally Posted by stress_junkie
I was telling you how you could have avoided being in your current situation. I think you are making a mistake trying to use Linux utilities to modify an NTFS partition.

If you look at the commands that I showed it isn't very much, and the entire post isn't five pages. So you only entered one command, so far. You've still got to resize your partitions.

I don't know; that sounds like a lot of work to me. I already resized the partitions with QTParted from the System Rescue CD. The only sticking point was the NTFS drive with bad sectors, which QTParted refuses to resize (but which most people don't have to deal with; they'd already be done a week ago when I finished resizing the other partitions). It can easily be done with ntfsresize, with the --bad-sectors switch, but QTParted doesn't support that switch yet. I decided to just do that for now and resized it with something like

Code:

ntfsresize -s 73432432543 /dev/hda2
(I don't remember the exact number; I just made the volume size as close as possible to the device size that I set earlier with QTParted. Incidentally, how do I copy everything on the screen (or in the screen buffer) to a text file for instances like this where I want to show what I am doing to someone online?)

So now my Windows should be taking up the full 70 GB or so available, as I wanted, but it would still be nice to reset the bad sectors list, seeing as how there aren't actually any bad sectors. I figured out that typing

Code:

ntfsinfo -i 8 /dev/hda2
or something like that displays $Bad and $Badclus, but I am not sure which value I am looking for. I tried to just do the ntfstruncate clearing command, and see which number it affected, whereupon I could reset the affected number, but then I realized System Rescue CD doesn't have ntfstruncate; it's an extra that needs the be compiled especially. :-( So I'll figure something out. It's not as urgent now, though.

bleargh 10-14-2006 01:42 PM

The instructions have been updated with the answer to my question!

Quote:

Find out size of ‘$Bad’ attribute in $Badclus using ntfsinfo with ntfsinfo -i 8 <partition>. It will be the “Allocated size” value in the “Dumping attribute $DATA (0×80)” (there will be two 0×80 attributes. Only one has an “Allocated size” line).

mlitwinowich 03-11-2009 02:56 PM

Quote:

Originally Posted by bleargh (Post 2462766)
The instructions have been updated with the answer to my question!

I was wondering if you were able to get GParted to work. I followed your notes after cloning an NTFS partition via the Linux dd command and everything went smoothly. MS's chkdsk with the /R option showed no errors and zero bytes in bad sectors. GParted still complains about bad sectors. Any thoughts on this?

bleargh 03-13-2009 12:28 PM

Quote:

Originally Posted by mlitwinowich (Post 3472292)
I was wondering if you were able to get GParted to work. I followed your notes after cloning an NTFS partition via the Linux dd command and everything went smoothly. MS's chkdsk with the /R option showed no errors and zero bytes in bad sectors. GParted still complains about bad sectors. Any thoughts on this?

There are a number of reasons why GParted won't see it. Try running parted from the command line and see if it produces error messages. Also try cfdisk, fdisk, etc. Also remember you have to reboot back into Windows at least once after doing the chkdsk before it will mark the disk as clean.

the_icebear 12-24-2011 06:16 AM

Merry Chrismas and THX alot for your Howto

Sure this is only needed in rare cases, but I cloned a notebook hdd which had bad sectors
on to a new hdd (whith ntfsclone) and so parted thought the new drive also has bad sectors
and refused to resize my partition. After those steps I could successfully resize the partition.

KelleyCook 02-12-2013 09:09 AM

Windows will reset bad clusters for you
 
I realize this is a Linux forum, but I ran into the same problem while using ntfsclone to replace a questionable WD Green EADS drive.

A new feature happened to be added to chkdsk in Windows Vista and later.

From windows run "chkdsk /b" which resets the ntfs bad cluster list and then runs a full rescan on the next boot (or right away if you are not checking the boot drive).


All times are GMT -5. The time now is 04:57 AM.