Write a .img to a Compact Flash with Physdiskwrite

For this tutorial I am going to write a 2GB pfSense image to a 4GB Compact Flash card using Physdiskwrite a command line utility for Windows. Sometimes the images may be compressed, extract the contents before attempting to write them to a card.

It would be wise to place both physdiskwrite.exe and the .img file in the same directory.

Let’s Start…

Open a command prompt in Windows with Administrator rights(necessary) and move to the directory where Physdiskwrite and the image are located.

C:\Users\Luis\Desktop>cd tools

C:\Users\Luis\Desktop\tools

To find all available disk use the following command.

physdiskwrite.exe -a
physdiskwrite v0.5.2 by Manuel Kasper 

Searching for physical drives...

Information for \\.\PhysicalDrive0:
   Windows:       cyl: 77825
                  tpc: 255
                  spt: 63
   C/H/S:         16383/16/63
   Model:         WDC WD6401AALS-00J7B1
   Serial number:      WD-WMATV3658664
   Firmware rev.: 05.00K05

Information for \\.\PhysicalDrive1:
   Windows:       cyl: 60801
                  tpc: 255
                  spt: 63
   C/H/S:         16383/16/63
   Model:         WDC WD5001AALS-00L3B2
   Serial number:      WD-WMASZ0056513
   Firmware rev.: 01.03B01

Information for \\.\PhysicalDrive2:
   Windows:       cyl: 924
                  tpc: 128
                  spt: 63
   C/H/S:         7395/16/63
   Model:         ELITE PRO CF CARD 4GB
   Serial number:     5B021A040
   Firmware rev.: Ver3.05K

Information for \\.\PhysicalDrive3:
   Windows:       cyl: 30401
                  tpc: 255
                  spt: 63

Which disk do you want to write? (0..3) Which disk do you want to write? (0..3)

The output above tells us that PhysicalDrive2 is the name of our 4GB Compact Flash. With that in mind we are going to tell Physdiskwrite to write our image file pfSense-1.2.3-2g-20091207-1914-
nanobsd.img
to the second drive.

Note: You need to use the -u parameter on cards bigger than 2GB, this is due to a safety precaution.

physdiskwrite.exe -u pfSense-1.2.3-2g-20091207-1914-nanobsd.img
physdiskwrite v0.5.2 by Manuel Kasper 

Searching for physical drives...

Information for \\.\PhysicalDrive0:
   Windows:       cyl: 77825
                  tpc: 255
                  spt: 63
   C/H/S:         16383/16/63
   Model:         WDC WD6401AALS-00J7B1
   Serial number:      WD-WMATV3658664
   Firmware rev.: 05.00K05

Information for \\.\PhysicalDrive1:
   Windows:       cyl: 60801
                  tpc: 255
                  spt: 63
   C/H/S:         16383/16/63
   Model:         WDC WD5001AALS-00L3B2
   Serial number:      WD-WMASZ0056513
   Firmware rev.: 01.03B01

Information for \\.\PhysicalDrive2:
   Windows:       cyl: 924
                  tpc: 128
                  spt: 63
   C/H/S:         7395/16/63
   Model:         ELITE PRO CF CARD 4GB
   Serial number:     5B021A040
   Firmware rev.: Ver3.05K

Information for \\.\PhysicalDrive3:
   Windows:       cyl: 30401
                  tpc: 255
                  spt: 63

Specify the number of the disk you wish to write to, in this case the disk is number 2.

Which disk do you want to write? (0..3) 2

WARNING: that disk is larger than 2 GB! Make sure you're not accidentally
overwriting your primary hard disk! Proceeding on your own risk...

Make this is the disk you want to overwrite, if so type y and press Enter to start.

About to overwrite the contents of disk 2 with new data. Proceed? (y/n) y
2001194496/2001194496 bytes written in total

Depending on the quality of the card and amount of data the process may take from 5 minutes to 10 minutes(may vary).

Conslusion

Compact Flash cards offer some benefits like no movable parts and quiet operation, if you intend to install FreeNAS, pfSense, or any other operating system in a compact flash then this tutorial will be useful.

  • Hesham

    Hi, well i tried it on 5 of my USBs and it got damaged, doesn’t work anymore tried to format it but with no luck
    thank you so much for nothing!

  • http://linhost.info Luis Ventura

    First of all this tutorial was done on Compact Flash card, second its highly unlikely the USB drives are damaged.

    I’ve seen this behaviour where Windows is unable to format a drive. In this cases you should use a Live CD like Parted Magic to format the drives.

    Last but not least, where are your manners!.

  • Bobby

    Is it necessary to use a smaller image on a larger card? I’m trying to write the 4 gig image to a 4 gig card and it won’t seem to let me, even with the 2 gig limit turned off.

  • http://www.thinwires.com William

    Hi Bobby,
    If you haven’t resolved your issue yet, I offer this advice. Remove the FD card ad reinsert it. Windows will offer to format it – decline this offer. Now follow the steps described by Luis. It should work for larger or same sized image using this method. It works for me.

  • http://www.thinwires.com William

    Luis,
    Your instructions have worked perfectly for me on CF cards of 2 and 4 GB. 2 GB cards are becoming more scarce everyday. I’ve had difficulty with the latest version of pfsense, though. It installs on the CF card, but does not boot in my Alix (no VGA, embedded platform) computer. Any thoughts?

  • http://linhost.info Luis Ventura

    Have you tried checking the integrity of the image, might be corrupted.