Friday, April 20, 2012

Recovering from a hard disk failure

A few weeks back the hard disk of my laptop computer crashed, and as a hard disk had never crashed in my vicinity earlier I was a bit unsure about what to do. I could have used one of those data recovery services, however I decided to tackle the problem on my own because - no one cares for my data more than me and you cannot really trust a stranger with your data. I ended up spending a fair bit of time trying to recover my data. Here is a summary of what I did

1. Essentially my computer had stopped booting up. On powering it on, the Loading Windows screen would come and then a blue-screen-of-death. Now this could be because some OS files are corrupted, or there is a problem with master-boot-record, mother board issue or a gazillion other things. Hence, the first step is to verify that it is an hard disk issue. To do so get a bootable CD/DVD or a USB and boot using that, if the system boots then something is probably wrong with the hard disk. If you do not have a bootable CD/DVD/USB ready at hand, ask around, a bootable Linux disc is not too hard to find.

2. I could boot my system using a bootable USB drive. Once booted I tried to access the hard disk in question, however that did not work. The hard disk would not mount. I even tried using a bootable BartPE disk, and even that did not help. So something was seriously wrong with my hard disk.

3. Now I was certain that there is a serious failure and I would need some special tools to recover my data. At this point you have 2 choices in front of you
a) Boot your system using a bootable disk and use a specialized software installed on that bootable disk to recover your data
b) Take out your hard disk and connect it to another computer as a secondary drive.

Let me explain both choices and reasons behind why I went with option (b)
a) For this option, you can use BartPE to boot your computer. BartPE has a plugin for GetDataBack, however I found this option a bit cumbersome to use. There were a few steps to setup everything nicely so as to copy data on to an external drive. Hence, I thought of exploring option (b)
b) In this option, the major hurdle is to be able to connect your hard disk to another computer because you need some hardware which not everyone may not have lying around. Luckily for me a friend had replaced his CD/DVD drive with a secondary hard disk and he was kind enough to lend me the hard disk bay for a few days :-) I also had another laptop readily available, something that may not be true for everyone. Once I was able to connect my faulty hard drive to another computer as a secondary drive, I could use any number of data recovery tools like GetDataBack, Partition Table Doctor, or freeware such as PC Inspector File recovery. Some more tools can be found at

4. Now reading data from my faulty hard drive was a simple task, it was slow but simple enough. However, some sectors on the disk were clearly bad and there were quite a few I/O errors while recovering the data. Hence, I was a bit unsure about the quality of data I was getting back - maybe some files were forever lost, or maybe some files were corrupted - essentially I did not know if I could trust the data. Now I also had a few months old data backup on an external drive, hence I thought to start with that and compare with the recovered data and sort of merge the two :-) Again there are a few tools which can help with this, Microsoft SyncToy is fairly neat and is also free, Beyond Comapre is a bit better but is not free.

Now I could have avoided all this if I frequently did a data backup. In any case it was kind of interesting to do all this and I did learn a few things along the way. The most important lesson obviously being - take a data backup every week! :-)

Note: I should also mention that somewhere in between I also tried the freezing-the-hard-disk trick. I know it sounds a bit crazy, and it did not work for me, but for some folks it seems to help a bit.

Sunday, April 15, 2012

YourKit profiler APIs

YourKit provides APIs to start and stop measuring from within your application, e.g.
com.yourkit.api.Controller controller = new com.yourkit.api.Controller();
controller.startCPUProfiling (com.yourkit.api.ProfilingModes.CPU_TRACING , null);
controller.captureSnapshot (com.yourkit.api.ProfilingModes.SNAPSHOT_WITHOUT_HEAP);
To use these APIs include <Profiler Installation Directory>/lib/yjp-controller-api-redist.jar in the classpath. Read more about YourKit APIs here.

Wednesday, April 11, 2012

Permanently enable 'Open command window here' in Windows 7

By default you need to right-click a folder, while pressing the SHIFT key, in order to access 'Open command window here' context menu option. However, it can be enabled permanently with the help of following steps
  • Click Start, Run and type Regedit.exe
  • Navigate to the following location:
    • HKEY_CLASSES_ROOT\Directory\shell\cmd
  • In the right-pane, delete the REG_SZ value named Extended