Cloning a Dell Hard Disk (HPA Problem)

May 30th, 2010 John No comments

My (far) better half’s old notebook hard disk was becoming slower and slower with bad sectors; it was 4 years old and was taking quite a long time to both boot and come out of hibernation. The Hitachi tool reported a large number of bad sectors, and it was getting worse, so we decided to change it out.

We bought a new 160 GB Western Digital Scorpio Blue and a 2.5″ SATA -> USB enclosure. I put Norton Ghost on her machine and set off the image, expanding both the C and D drives which were on the disk from their original 40 and 20 GB sizes to 120 and 40 GB respectively.

This took a good few hours as the imager had to re-read all the bad sectors multiple times. After it completed, I swapped out the disks and rebooted. Windows started to boot but NTLDR immediately blue-screened with UNMOUNTABLE BOOT VOLUME.

I re-imaged the disk with Partition Magic, thinking Ghost had messed up, but had the same result.

Now having a disk I was sure had imaged correctly, I booted with Kubuntu Live and ran fdisk. This showed that the disk was showing as 58 GB big, with an invalid partition table.

After using HDAT2 to get low-level info on the disk, it turns out that HPA was active on the disk. HPA – Host Protected Area – is a way of changing the apparent size of a hard disk in order to ‘hide’ a partition at the end of the disk.

I used HDAT2 to remove the HPA flag, and the disk returned to its full size of 160GB.

On the next boot, the problem returned.  Before I explain what happened, the layout of the disk is as follows:

  • Partition 0 is a small Dell utility partition
  • Partition 1 is Windows XP, NTFS,  C:
  • Partition 2 is NTFS D:
  • Partition 3 is beyond the HPA, i.e. hidden (normally), containing Dell MediaDirect.

Dell MediaDirect is triggered off a hardware button which we have never pressed, and we assume boots something used to play CDs, MP3s etc.

So the boot sequence for a normal (non MediaDirect) boot on a Dell notebook seems to be:

  1. Power on via Power button.
  2. MBR/Partition table designates partition 0 (P0) as the boot partition.
  3. P0 boots.
  4. MediaDirect button is not pressed.
  5. Dell loader hides P3 – i.e. sets HPA  active and set to 58 BG to hide it.
  6. Dell loader chain boots P1 (Windows XP).

With MediaDirect active:

  1. Power on via MediaDirect button.
  2. MBR/Partition table designates P0 as the boot partition.
  3. P0 boots.
  4. MediaDirect is pressed (or has been pressed and flagged in the BIOS).
  5. Dell loader unhides P3 by removing HPA (and copies a valid partition table containing P3 in), making the apparent size of the disk the full size (60 GB).
  6. Dell loader chain boots P3 (MediaDirect).

When we transplanted the disk, step 5 from the Normal sequence above re-set the disk size to 58 GB, which was in the middle of the new C:, causing the UNMOUNTABLE BOOT VOLUME from Windows – which was correct:  the partition was far too short — it should have been 120 GB.  The truncated partition was (naturally) not a valid NTFS filesystem.

We don’t need MediaDirect at all, so here’s how I solved it:

  1. Use HDAT2 to remove the HPA, making the disk appear 160 GB on the next boot.
  2. Boot Kubuntu Live from CD immediately.  This is important because if you allow the hard disk boot sequence to commence, it will reset HPA to 58 GB (step 5 from the normal sequence).  If you don’t catch the boot menu in time, and start a boot from disk, reboot and go back to step 1.
  3. Use fdisk in linux to delete P0 (Dell utility) and P3 (Dell MediaDirect),  then nominate P1 as the boot partition. Rewrite the partition table.  You can enlarge partitions later using Partition Magic.
  4. Boot Windows Repair Mode and run bootcfg /scan to ensure Windows knows about all the Windows installations and fixboot to fix up NTLDR.  I can’t remember if I had to run fixmbr or not – try it without first.
  5. Reboot, and Windows should boot from P1.

The problem is, if you don’t know HPA is active (or like me, you didn’t know HPA even existed) you’ll never come up with google search terms to even start to solve the problems.

  • Share/Bookmark
Categories: Hardware Tags: , ,

Creating Testfiles of Given Length

April 26th, 2010 John No comments

Use the Unix /dev/zero device (which produces an infinite stream of bytes with value zero) together with the dd block copier to create files of any length, useful for testing.

dd if=/dev/zero of=test.bin bs=1024\*1024 count=4

… creates a file called test.bin (output file) by copying from /dev/zero (input file). Blocksize is 1 MB (1024*1024 bytes), and the count is 4, giving a 4 MB file. Substitute your own values for blocksize and count, and create test files of any length.

  • Share/Bookmark
Categories: Software Engineering Tags:

Eclipse: Bootstrapping A New Install

November 16th, 2009 John No comments

For those of us who upgrade Eclipse regularly, it’s sometimes necessary to start ‘from scratch’ with a new installation. I’ve had cases in the past where P2 (Eclipse’s software update mechanism) couldn’t find updates, or couldn’t resolve dependencies.

There are many different causes of software update issues and it’s often quicker to abandon the update and reinstall. Sometimes I’m chasing milestone revisions, which I prefer to install fresh to avoid any preference store problems.

This procedure below is how I generally bootstrap a new Eclipse install on an existing workspace.

  1. Backup your workspace. Make a zip or a 7z file of everything that’s in there, .svn folders and all.  Put this somewhere safe.
  2. Backup your Eclipse settings:
    1. File -> Export, then General -> Preferences.
      …to a file on your desktop called eclipse.xml
    2. Check “Export All
  3. Make a note of all the plugins and addons you have installed.
  4. Shut down the old Eclipse.
  5. Download and unzip the new version of Eclipse to a new folder somewhere.
  6. Start up the new Eclipse
    • Do not allow the new eclipse to use your production workspace. Pick a new, empty one.
  7. In the new Eclipse, install all the plugins and addons you need. Do a Help -> Check For Updates and let it install any updates.
    • You’ve doing Check For Updates on a weekly basis anyway, right?
  8. When you’ve got everything installed, do File -> Import, then General -> Preferences, giving it the eclipse.xml file created in step 2.2.
  9. Now restart Eclipse, allowing it to start on your production workspace.
  10. You may need to re-apply preferences but generally it should be ok.

This procedure might seem rather long, but in reality it’s very quick and you can usually get back to a productive state in half an hour or less (depending on how many plugins and addons you have installed).

  • Share/Bookmark
Categories: Software Engineering Tags:

OSX/Cocoa UI Event Spy

October 11th, 2009 John No comments

I recently had to profile an application, and one of the metrics I wanted to obtain was the performance of the GUI, without (if possible) resorting to GUI testing frameworks. This metric would be the duration of time from when the user commanded a redraw/update, until the render of that redraw actually completed (effectively a complete client-server-client round-trip time).

To cut a long story short, there doesn’t seem to be a developer tool in OS X or XCode to spy on these UI events, but you can enable them on individual applications by supplying the -NSTraceEvents YES flag to the binary, which you must start from Terminal.

For example, here’s how you’d start TextEdit and spy on its events.

/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSTraceEvents YES

In my case, I actually only wanted to have the mouse-up events which would trigger the refresh. Here’s how I did it:

/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSTraceEvents YES 2>&1 | grep "Received event.*LMouseUp"

NSTraceEvents outputs the trace to the stderr stream, which is ignored by grep, so the 2>&1 is there to redirect stderr to stdout. The “Received event.*LMouseUp” regular expression selects the mouse-up events from the complete stream.

Result:

2009-10-11 16:56:13.291 TextEdit[29990:903]
Received event: LMouseUp at: 320.0,243.0 time: 199375872740000 flags: 0x100 win: 1832 ctxt: f0df data: 2531,1

  • Share/Bookmark
Categories: Software Engineering Tags: ,

Mac OS X Snow Leopard Has No Java 5 – Warning!

September 24th, 2009 John No comments

Here’s one I spent a day learning: OS X 10.6 “Snow Leopard” has no Java 5 installed, despite appearances to the contrary.

The Java 1.5 installation is actually a symbolic link to the Java 1.6 installation. There is a fix available, which essentially entails copying the Java 1.5 installation from a Leopard install, and fixing up the symlinks. It’s available here.

I found this because we have a product which must be linked against Java 1.5, or rather, the JDBC version 3 specification. We don’t yet support all the extended functionality of JDBC 4.

In Eclipse, I had selected Java 5 (= JDBC 3) as the JRE, but was still getting lots of “method unimplemented” errors for JDBC 4 (= Java 6) signatures. These aren’t present in Java 5, so they should not have appeared.

After unfolding the JRE Library node in the Eclipse Package Explorer, it was clear that, although the JRE was reporting itself as Java 5, the jars within were clearly coming from Java 6.

I applied the fix and the compiler errors disappeared – Java 5/JDBC 3 was in use again.

For (my) future reference, here are the JDK / JDBC versions:

  • JDK 1.1 → JDBC 1.2
  • JDK 1.2 → JDBC 2.1
  • JDK 1.4 → JDBC 3
  • JDK 1.5 → JDBC 3
  • JDK 1.6 → JDBC 4
  • Share/Bookmark
Categories: Software Engineering Tags: , ,

Using Eclipse on Small Screens

August 25th, 2009 John No comments

Two awesome plugins for those of us using Eclipse on screens with low resolutions:

Also to consider:

  • Is your editor font too big? Can you make it smaller and still be comfortable working with it?
  • Look at your window layout – do you have a view docked to the right of the editor – probably Outline? Do you really ever use outline?  Get rid of it if not, or make it a tab in the dock on the left.
  • Share/Bookmark
Categories: Software Engineering Tags: ,

Misleading Java Generic Errors in Eclipse

August 19th, 2009 John No comments

An incompatibility between Java source versions in Eclipse made a generics error show up as:

Type mismatch: cannot convert from Object to ILocationService.

when it should really have read something like:

Type mismatch: return type of TypeLoader is generic – this project is not.

Read more…

  • Share/Bookmark
Categories: Software Engineering Tags: ,

Reducing Tooltip Time in Eclipse 3.5 (Galileo) on Mac OS X

June 25th, 2009 John No comments

Tooltips in Mac OS X display, by default, after 2 seconds. I find this is ample time in the general operating system, but in Eclipse it’s an eternity. Eclipse uses Tooltips in the Java tooling to display all kinds of useful information, not the least of which is the javadoc for the element and the source.  Waiting for these is frustrating.

The general workaround of using OS X defaulting to change that didn’t work with previous versions of Eclipse because the SWT (IBM’s excellent widget set) was built on Carbon, OS X’s “UI Compatibility Library”, which ignored the default.  Eclipse is now available for Mac in a native Cocoa version, which does take the defaulting into account.

Here’s how to change the global OS X tooltip delay (in Terminal):

defaults write -g NSInitialToolTipDelay -int 100

I personally want to keep the 2-second delay for everything except Eclipse, so I applied the default just to Eclipse using the Eclipse bundle name:

defaults write org.eclipse.eclipse NSInitialToolTipDelay -int 100

The delay time is in milliseconds. You might have to log out and back in again to make the default take, but usually restarting Eclipse does the trick.

Nice work IBM!

  • Share/Bookmark
Categories: Software Engineering Tags: , ,

Overloading the Eclipse Job Management System

April 30th, 2009 John 2 comments

We’ve had an issue with our Eclipse-based application which would cause it to slow down exponentially under stress test.  The problem lie in the job management system:  new fast code could essentially cause it to bog down under the weight of update jobs.

Read more…

  • Share/Bookmark

Exporting “Non-Exportable” Private Keys from Vista

March 6th, 2009 John No comments

Going through the Thawte sign-up process to get a code signing certificate, I noticed that the certificate signing request (CSR) generated by Vista has the “Yes, export the private key” option grayed out.  I’m surmising that Vista marks all keys (at least those for code signing certificates) as not exportable.

This is obviously bad when you have more than a single developer who must sign code.  After beginning the process I found an article at Thawte which says ‘don’t do this on Vista!’, but I also found the Jailbreak util from iSec.  This was able to export the private key with the CSR into a PFX file.  As a test I also re-imported it from the export file and that worked fine.

  • Share/Bookmark
Categories: Software Engineering Tags: