Sunday, June 28, 2009

How to copy Windows from a bad hard drive

If a hard drive starts going bad, and read errors and bad sectors start appearing, what do you do? It's best to have a recent backup, and if you don't, it's best to recover your files and settings and reinstall Windows on a new hard drive. However, if there aren't too many bad sectors, it's possible to copy Windows from an a bad hard drive to a good one. Here's what I did.

First, I considered the requirements. I did not want to run chkdsk or otherwise attempt to fix things on the bad drive, because that could make things worse. I wanted to transfer the entire filesystem, not copy individual files. I wanted to know which files have read errors, so I could see the extent of damage and then either replace individual files or conclude that the situation is hopeless and reinstall. Finally, I wanted the process to be reasonably fast and automated.

Disk cloning software seems like the obvious choice. Unfortunately error recovery and logging features are lacking. After some research it seemed that no disk cloning program will create a log of files with errors. The only promising program was DiyDataRecovery Diskpatch, but it was ridiculously slow.

I decided on another approach: ddrescue. I downloaded the Ubuntu Rescue Remix, booted it and ran ddrescue, putting the log on a USB flash drive. The initial copy was fast and simple. Then, retries quickly read about half the bad sectors. I was left with 26 sectors which seemed totally unreadable. The ddrescue log gave offsets, which I divided by 512 in an automated way to give sector numbers.

Now I put the write protect jumper on the old hard drive and swapped the SCSI IDs. I wanted to be sure that the sector numbers I had remained valid. This was probably unnecessary and it complicated things. Windows started booting off the new drive, but then it mounted the partition from the old drive as C:, and I got a blue screen of death because of write protection. (Make sure you set up Windows to not automatically reboot after a BSOD. It's much easier to set that option in Windows than to edit the registry when Windows can't boot.) To fix the problem I used a disk editor to change the disk signature in the MBR of the new disk, and then I used Partition Saving to update which partition is mounted as C:.

Finally, I was able to boot Windows on the new drive. I used nfi.exe (from OEM Support Tools Phase 3 Service Release 2) to find which files those bad sectors corresponded to. The results were encouraging. Only one bad sector was in a real file, and Windows File Protection took care of that. The others were already marked as bad sectors or in unallocated space.

Since the filesystem on the new drive was directly copied from the old drive, it had sectors which were marked as bad. I needed to remove these. Again, I used Partition Saving. This was probably a mistake.

Now it was time to increase the size of the partition because the new drive is larger. Unfortunately, partition resizing programs refused to work. This wasted by far the most time of the whole operation. Eventually I tried ntfsresize, which told me I had hopelessly many bad sectors. (This is the sort of unprofessionalism found in open source software; it shouldn't be making an emotional comment. Commercial software handles the problem in a more professional way, such as cryptic error codes, generic error messages telling you to run chkdsk, or lockups.) Eventually I concluded that the bad sector file was corrupted in a way that chkdsk was unable to detect or fix. I suspect the problem was caused by Partition Saving, because Partition Magic started once before I reset the bad sector list and it always locked up after that.

Fixing the bad sector list was a problem. The /b option in Vista chkdsk didn't help. I read about a method using ntfstruncate, but a LiveCD with ntfstruncate was hard to find and ntfstruncate refused to work. Finally I recompiled ntfsresize, commenting out that check for hopelessly many bad sectors. (I used System Rescue CD. Besides rescue tools, it also has basic networking tools and gcc.) After a resize, chkdsk found some problems with the bad sector file, and after that everything was fine. Mission accomplished.

One interesting pattern here is that open source tools were far more useful than commercial software. For example, I used to think of Ghost and Partition Magic as important tools, but their poor error recovery and reporting made them useless here.

Thursday, June 25, 2009

A better way to play FLV files in Windows

I used to play FLV files using FLV Player. That worked fine, but I've now found a better way: FLV Splitter from Guliverkli2 and ffdshow tryouts. With these, I can play FLV files in practically any video player which supports DirectShow.

Monday, June 15, 2009

Tulip trees are interesting

Tulip trees are interesting. The flowers really are tulip-like from the outside, but they are greenish so, so they're not as spectacular and noticeable as the name implies. The inside of the flower is especially interesting. Here are some photos I took today:


Sunday, June 14, 2009

Friday, June 05, 2009

What I did about my Reddit addiction

Reddit is an endless source of information and discussion on practically any subject. I find it endlessly entertaining, highly addictive and almost entirely unproductive. I finally found the perfect solution: I blocked the Reddit cookie, and I don't log in anymore. Sure, I still go there, but I don't linger, and so I spend very little time there.

It's interesting that this worked but blocking Reddit via LeechBlock didn't. If I try to extrapolate from these experiences I come up with two relevant ideas or hypotheses:
  • Directly fighting myself over what I want or don't want to do is stupid.
  • Psychological addiction is not a craving for something, but a tendency toward a particular pattern of activity.

Friday, May 22, 2009

I think JMicron finally fixed their JMB36X drivers

After I upgraded from XP to Vista, I started having problems with my Memorex 3202 3292 16x dual layer DVD writer after resuming from sleep (S3, Standby to RAM). Sometimes my computer just hung for a bit when resuming. Other times my computer kept hanging for a fraction of a second every few seconds and it was impossible to access the drive. My workaround was simply to disable the JMB36X (GIGABYTE SATA2 RAID) device on my GA-P35-DS3R (rev. 1.0) motherboard, and only enable it when needed. I needed the drive rarely so, this wasn't too bad.

I just upgraded to R1.17.48.12 drivers direct from JMicron (I used R1.17.48.12.zip), and it seems the problems are gone.

By the way: earlier while trying to solve this problem I flashed my drive with the NEC ND-3520 3.07 firmware, and I got PIE/PIF scanning support.

An old genuine 2GB SanDisk Ultra II SD card

Yesterday I picked up a 2 GB SanDisk Ultra II SD card, mainly for my small and cheap RCA RC3000A boombox. (Earlier, RCA support told me 2 GB is the maximum size supported.) I got the card from FactoryDirect. Here's what it looks like:




That's not like any of the images I found via Google, and according to online information, there are many counterfeit SanDisk Ultra II SD cards. I was starting to think it is counterfeit, but when I called SanDisk, I was told that the card is old but genuine.

Tuesday, May 19, 2009

Beware of Vista firewall environment variable substitution in paths

If I attempt to create a Vista firewall rule for an executable which is in my personal directory (under \Users\<username>\), the browse dialog substitutes environment variables like %APPDATA% or %USERPROFILE%. However, the firewall itself runs as a different user, so those variable substitutions are invalid. A full path must be used in these cases (eg. starting with C:\Users\<username>\).

BTW. The Blogger composer can't handle < and >. Instead I had to use &lt; and &gt;