Thursday, November 6, 2008

Compact flash disk image with dd and cygwin

I found a way to make an exact duplicate of a compact flash card using cygwin. I suspect this method only works with identical flash cards - i.e. both the same capacity, and possibly both from the same manufacturer.
Anyhow, based on Reimaging CompactFlash cards tutorial, I looked in Computer Management, Disk Manager, and discovered my compact flash card was 'disk 2'
Then, using 'a' for disk 0, and 'c' for disk 2, at the cygwin command prompt:
dd if=/dev/sdc of=b2.img
It reports this, for a 32Mb flash card:
62592+0 records in
62592+0 records out
32047104 bytes (32 MB) copied, 10.725 s, 3.0 MB/s
Then, 'eject' the flash card in explorer, and insert the new one (to be erased and copied over). In cygwin again, note 'if' and 'of' swap:
dd of=/dev/sdc if=b2.img
62592+0 records in
62592+0 records out
32047104 bytes (32 MB) copied, 43.448 s, 738 kB/s

And it works! It's even bootable.
I'm still puzzled by a cygwin list suggestion, which has weird syntax for mounting the drive first. I tried it, and I got 'permission denied' when trying to write the image to the card, too. I think you want to treat it as a device, not a drive.

Update: I am able to copy the disk image onto a larger CF card, and all the data is preserved, but the CF is not bootable. An exact duplicate read from a 32Mb card and copied to a 32Mb card is bootable.

To fix that, I downloaded the latest syslinux, looked in the win32 subdirectory, and then ran this command (in cygwin), since my CF is the F: drive:
syslinux.exe -m -a f:
I also discovered that simply copying all the files, and then run the syslinux command above to make the CF bootable, works just fine too.

One more thing. The older version of syslinux allows 'append=' in syslinux.cfg, but the newer version doesn't like the '=' sign. Once I changed all occurences to 'append', it booted correctly. The older syslinux likes that format, too.
Post a Comment