Eric Bodden Current conditions in Darmstadt: Cloud and Visibility OK, -1°C (feels like -6°C)
-1°C

Easy and efficient software verification
  • rss
  • Home
  • Research
    • Past Research
      • Efficient Runtime Verification
      • Racer: Effective Race Detection Using AspectJ
      • Continuation-equivalent states (ICSE 2010)
      • Aspect-oriented programming and design
      • Visual specification languages
      • A denial-of-service attack on the Java bytecode verifier
    • Publications
    • Presentations
  • Tools
    • Clara: Compile-time Approximation of Runtime Analyses
    • RacerAJ (for race detection)
    • An introduction to Soot 2.2.5
    • Aspect-oriented approaches targeting the .NET Framework
  • Teaching
    • Automated Software Engineering
    • Software-Engineering Project
    • COMP 520
    • COMP 621
  • Legacy
    • Bad Sector Recovery on NTFS
    • Arithmetic Coding
    • PHP Scripts
  • About me
  • Photos

Bad Sector Recovery on NTFS

ATTENTION: This information is out of date. Inspired by this article, the NTFS tools (see below) now have a built-in function to reset bad clusters.

The Problem:

I wanted to install WinXP SP1 on my harddrive. Unfortunately my partition C: was too small (of course). So I decided to resize the partition (which meant I had to lose some space on the subsequent drive D:). Unfortunately my disk had a bad sector and as one might know, partitioning without data loss is not allowed by any partitioning tool in the presence of bad sectors. So I thought: Bad sectors are really bad anyway and there’s still warranty on the drive so let’s have it changed… and I got myself a new drive.

I copied the whole content using DriveImage which worked marvelous, well even too well: It not just copied all the blocks but also the information about which blocks were defect :-( That’s not a problem of the tool but rather a problem of the file format. Anyway: Now my new hard drive had sector tagged as “bad” which actually were perfectly alright. This now really p***ed me off because that meant that I was not able to repartition without data loss again! So my task for the week was to find out how to remove this wrong entry about wrong blocks from my drive. I had to find one bit or so out of 6,400,000,000,000!

The solution

I mean normally that’s not a problem because nowadays somebody has tools, powerful tools like e.g. Partition Magic, that for FAT or FAT32 partitions respectively, can do the job for you:

    For FAT or FAT32 Partitions just install Partition Magic (Version 4.0 is enough) and perform a “bad sector retest”.

However – and that’s the part about Microsoft now – NTFS is a protected format. Microsoft provides no documentation about it and so there are no tools available on the marked which could do the same for NTFS. Some smart people gave me the hint: Well but that’s not a problem because WinXP has chkdsk and using chkdsk /R should reset such blocks. If you read the documentation about this parameter you will find that it is a bit ambiguous: Locates bad sectors and recovers readable information. One could read that as recovers actually readable blocks. But it doesn’t! It only tries to find real bad blocks and tags them as bad. So

    chkdsk /R does not work in any case for this problem!

So if there is apparently not Win32 tool support what should one do? Of course: Look for Unix tools. Unfortunately NTFS support is still very rudimentary on Unix at the moment because one has to reverse engineer the format. But however I was lucky enough to find the Linux-NTFS Project which provides the Linux Power Tools. And I was lucky enough that they were open source. That’s because I actually had to patch one line of code to make it work for my purpose (thanks to szaka at this point). So here is how it works:

    For NTFS partitions:
    (a full console log of the session is available
    here)

  1. If you have also a Unix installed you are lucky – go to 2. If not, go to e.g. Knoppix.de and get yourself a Linux that boots entirely from CD-ROM. (Though it’s a German domain, the site and software are also available in English.)
  2. Download a pre-patched version of the ntfs tools here and extract it.
    - or -
    Download the original NTFS Tools source code from here.
    Extract the archive to a <source directory>, edit the file \ntfsprogs\ntfsresize.c with a text editor and add a
    return 0;
    right at the beginning of the method has_bad_sectors. This will tell the tool that there are just no bad sectors – regardless what there is written on the disk.
  3. Start Unix/Linux and copy the <source directory> to a location that is editable (e.g. /ramdisk on Knoppix).
  4. Start a terminal and change to the directory containing the <source directory> and make all the contents writable and executable:
    chmod -R 777 <source directory>
  5. Now perform the following to compile the patched version:
    cd <source directory>
    ./configure
    make
    cd ntfsprogs/
    su
  6. Now run the tool and write down the volume size (marked italic). Substitute <part> with the name of your actual partition.
    ./ntfsresize –info <part>
    ntfsresize v1.8.2
    NTFS volume version: 3.1
    Cluster size : 4096 bytes
    Current volume size: 69561159680 bytes (69562 MB)
    Current device size: 69561160704 bytes (69562 MB)
    Checking filesystem consistency …
    100.00 percent completed
    Accounting clusters …
    Space in use : 19915 MB (28,6%)
    Calculating smallest shrunken size supported …
    File feature Last used at By inode
    $MFT : 15415 MB 0
    $MFTMirr : 13794 MB 1
    Compressed : 24367 MB 75538
    Sparse : 1179 MB 25545
    Multi-Record : 24368 MB 7879
    Ordinary : 24369 MB 66633
    You could resize at 24368844800 bytes or 24369 MB (freeing 45193 MB).
  7. Unmount the partition:
    umount <part>
  8. Perform the action:
    ./ntfsresize -s <written down volume size>
    <part>
    ntfsresize v1.8.2
    NTFS volume version: 3.1
    Cluster size : 4096 bytes
    Current volume size: 69561159680 bytes (69562 MB)
    Current device size: 69561160704 bytes (69562 MB)
    New volume size : 69561159680 bytes (69562 MB)
    Checking filesystem consistency …
    100.00 percent completed
    Accounting clusters …
    Space in use : 19915 MB (28,6%)
    Needed relocations : 0 (0 MB)
    WARNING: Every sanity check passed and only the DANGEROUS operations left.
    Please make sure all your important data had been backed up in case of an
    unexpected failure!
    Are you sure you want to proceed (y/[n])? y
    Schedule chkdsk for NTFS consistency check at Windows boot time …
    Resetting $LogFile … (this might take a while)
    Updating $BadClust file …
    Updating $Bitmap file …
    Updating Boot record …
    Syncing device …
    Successfully resized NTFS on device ‘/dev/hdg5′.
    You can go on to shrink the device e.g. with ‘fdisk’.
    IMPORTANT: When recreating the partition, make sure you
    1) create it with the same starting disk cylinder
    2) create it with the same partition type (usually 7, HPFS/NTFS)
    3) do not make it smaller than the new NTFS filesystem size
    4) set the bootable flag for the partition if it existed before
    Otherwise you may lose your data or can’t boot your computer from the disk!

Done! That was easy, wasn’t it ? ;-) Probably somebody should write a script for that…

Comments rss
Comments rss
Trackback
Trackback

Leave a Reply

Click here to cancel reply.

Welcome

Welcome to my website. Interested in my research? Click here for details or jump directly to my publications.

Pages

  • Research
    • Past Research
      • Continuation-equivalent states (ICSE 2010)
      • Efficient Runtime Verification
      • Racer: Effective Race Detection Using AspectJ
      • Aspect-oriented programming and design
      • Visual specification languages
      • A denial-of-service attack on the Java bytecode verifier
    • Publications
    • Presentations
  • Tools
    • Clara: Compile-time Approximation of Runtime Analyses
    • RacerAJ (for race detection)
    • An introduction to Soot 2.2.5
    • Aspect-oriented approaches targeting the .NET Framework
  • Teaching
    • Automated Software Engineering
    • Software-Engineering Project
    • COMP 520
    • COMP 621
  • Legacy
    • Arithmetic Coding
    • Bad Sector Recovery on NTFS
    • PHP Scripts
  • About me

Categories & Feeds

  • Misc RSS Feed Icon (89)
  • Montreal Blog RSS Feed Icon (44)
  • Research Blog RSS Feed Icon (67)
  • Comments (RSS) RSS Feed Icon

Kitchensink

  • Conferences
  • My first patent: Method and system for performance profiling of software (pending)
  • Photos

Research projects

  • AspectBench Compiler (abc)
  • J-LO
  • Soot
  • Stratified aspects

Service

  • AOSD 2006
  • AOSD 2007
  • AOSD 2010
  • AOSD 2011
  • Association of Alumni, Friends, and Supporters of the RWTH Aachen University in North America
  • ATVA 2008
  • ECOOP 2008 Doctoral Symposium
  • ECOOP 2010
  • FOAL 2010
  • IEEE Transactions on Software Engineering (TSE)
  • International Journal of Image and Graphics
  • ISSTA 2011
  • OOPSLA 2008
  • PEPM 2008
  • PLDI 2006
  • PLDI 2008
  • RV 2007
  • RV 2009
  • RV 2010
  • SEFM 2005
  • SEFM 2008
  • Transactions on Software Engineering and Methodology (TOSEM)
  • VMIL 2008
  • VMIL 2009

Some of my colleagues

  • Gregory Prokopski
  • Laurie Hendren
  • Nomair Naeem
  • Ondrej Lhotak
  • Patrick Lam
  • Programming Tools Group
  • Sable lab

Some other people I know

  • Adrian Colyer
  • Bruno Dufour
  • Dan North
  • Daniel Klink
  • Dave Thomas
  • Dean Wampler
  • Friedrich Steimann
  • Joachim Kneis
  • Klaus Havelund
  • Liz Keogh
  • Malte Clasen
  • Markus Schorn
  • Pascal Costanza
  • Patricia Jablonski
  • Philip Mayer
  • Ron Bodkin
  • Sven Wittig
  • Wiebke Berg

Some people not to confuse me with

  • Eric B. the terrorist
  • Eric Bodden the basketball player
  • Eric Bodden the chef who sunk
  • Eric Christopher Bodden
  • Noel R. Lopez alias Eric Bodden

Previous posts

March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Tags

Alumni AspectJ Atlanta Blizzard Bug finding Clara COMP 621 Eclipse Flight FSE Google ISSTA Java LinkedIn Mac McGill Microsoft Montreal Blog OOPSLA Oxford Photos Politics Programming Quebec City Race detection Racer Random ranting Runtime verification RWTH Seattle Ski trip Snow Snow storm Soot Soot Tutorial Static Analysis Strike TA strike Thesis tracematches Typestate Vacation Website Winter carnival Wordpress


rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox