LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-13-2006, 11:00 AM   #1
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Rep: Reputation: 16
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?

Last edited by bleargh; 10-13-2006 at 11:04 AM.
 
Old 10-13-2006, 04:21 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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.

Last edited by stress_junkie; 10-13-2006 at 04:40 PM.
 
Old 10-13-2006, 04:49 PM   #3
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Original Poster
Rep: Reputation: 16
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.
 
Old 10-13-2006, 05:10 PM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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.

Last edited by stress_junkie; 10-13-2006 at 05:24 PM.
 
Old 10-13-2006, 06:39 PM   #5
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Original Poster
Rep: Reputation: 16
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.

Last edited by bleargh; 10-13-2006 at 06:41 PM.
 
Old 10-14-2006, 01:42 PM   #6
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Original Poster
Rep: Reputation: 16
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).
 
Old 03-11-2009, 02:56 PM   #7
mlitwinowich
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Rep: Reputation: 0
Quote:
Originally Posted by bleargh View Post
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?
 
Old 03-13-2009, 12:28 PM   #8
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by mlitwinowich View Post
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.
 
Old 12-24-2011, 06:16 AM   #9
the_icebear
LQ Newbie
 
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
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.
 
Old 02-12-2013, 09:09 AM   #10
KelleyCook
LQ Newbie
 
Registered: Feb 2013
Posts: 1

Rep: Reputation: Disabled
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).
 
  


Reply

Tags
clone, ntfs, ntfsclone, ntfsresize



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for Bad sectors rotty Linux - Hardware 2 09-28-2006 11:34 PM
Bad sectors tuxombie Linux - Hardware 3 01-29-2005 01:05 PM
bad sectors on harddrive Lindquist Linux - Hardware 1 01-28-2004 04:41 PM
searching 4 bad sectors zeky Linux - Software 1 12-12-2002 08:49 AM
Bad sectors blystovski Linux - Software 1 10-17-2001 12:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration