Using DD for Windows

First, a precaution:  This will manually remove partitions from the SD Card.  Ensure you follow the steps carefully as you could end up erasing data on other drives in your computer.  This can actually delete the partition that you're currently running Windows on!  But don't worry - I've got some basic steps you can take to make sure you're making the right changes


Images
There are now 3 official images available to download from the Raspberry Pi website (and several unofficial ones that I've heard of):

Fedora 14 remix - raspberrypi-fedora-remix-14-r1.img.gz
Debian squeeze - debian6-17-02-2012.zip
Arch Linux ARM -  archlinuxarm-01-03-2012.zip
EDIT: 2nd Debian Squeeze release - debian6-13-04-2012.zip
EDIT: 3rd Debian Squeeze release - debian6-19-04-2012.zip 

EDIT: Raspbian Wheezy release - 2012-07-15-wheezy-raspbian.zip
NOTE: You'll need something like winrar to unzip the Fedora image


Environment
I'm using Windows 7 Professional, 32-bit.  I understand that Windows 7 64-bit and Windows XP might have a few issues - sorry, I can't help with those.  I would say it's worth giving this a go if you're running one of those OSes and see if it works.


DD For Windows
To apply the image to you'll need to download DD for Windows.  This is a Windows port of the Linux utility - DD.
http://www.chrysocome.net/downloads/dd-0.6beta3.zip
Once you have this, unzip it to a local folder that you can get to easily from the command prompt.  In this example I've used c:\temp.  Once unzipped you should see the following:


PLEASE NOTE: You'll also need to copy the image to the same location.


Preparing the SD Card
While in some cases you can simply format the CD card or delete the partition using Windows Computer Manager, if the SD card contains non-Windows partitions (i.e. you're wanting to wipe an existing Raspberry Pi image from the card) you won't be able to do this.  I'm therefore going to take you through identifying and removing any partitions using a utility called DiskPart.  This is part of the Windows 7 operating system, and should be in place in Windows XP (unconfirmed).
PLEASE NOTE: This is where you'll need to be careful

Step 1
Open the command prompt.  Under Windows 7, to ensure you have the required permissions, ensure you're running the command prompt as Administrator:

Type diskpart and press enter.  You'll see the diskpart utility load and be presented with a DISKPART prompt:

Step 2
Type list disk - this will list all disks that DD can see.  Below my main hard drive (Disk 0) and the SD Card (Disk 1) are listed.

NOTE: At this point make careful note of the Disks listed.  In this case, Disk 0, highlighted in red, has a total size of 298GB - this is my Windows operating system.  Disk 1, highlighted in blue, has a total size of 1886 MB - this is my 2GB SD Card.

Step 3
Next you need to select a disk.  In this case I typed select Disk 1.  I see confirmation that this disk has been selected:
NOTE: Make sure you select the SD Card, and not any other disk

 Step 4
Next you need to delete the partitions on the disk, but need to list them first to identify what needs to be deleted.  To do this type list partition.  Here two partitions are listed.  The first is a 100MB boot partition and the other is a 1.5GB ext3 partition (this happens to be a Fedora Pi image):

Step 5
Next you need to select the partition you want to delete.  In this scenario I've select partition by typing select partition 0:

Step 6
Once the partition has been selected, you can delete it. PLEASE NOTE: This will delete whatever partition is selected!!  To delete the selected partition simply type delete partition:

Step 7
Repeat Step 5 and 6 to delete  the second partition

Step 8
Once you've deleted both partitions type list partition again to ensure both partitions have been removed:
To exit, type exit.

Applying the Debian Image
I'll start with the Debian Image first.  To do this, go to the command prompt (ensuring you run this as administrator) and navigate to the directory you extracted the dd utility and the Debian image to.

Step 1
To determine the parameters to use with the dd utility you need to identify two things - the drive letter of the SD card and the path of the image.  In this example my SD Card drive letter is E: and the image is in c:\temp.  The command I've used is therefore:
dd bs=1M if=c:\temp\debian6-17-02-2012.img od=e.

 NOTE: BS refers to the Block Size that should be used - in this case 1MB


The utility will apply the image to the device, providing a running total of the amount of data written so far:


Step 2
To verify the image has been written correctly view the drive in Computer Manager.  While you will be able to see all partitions here, you will only be able to see the 75MB partition in Windows Explorer.

When looking at the partition you will see the following:


Applying the Fedora Image
I've run through the same process to apply the Fedora image and it's exactly the same, except for the command used.  For the Fedora image I used the following:
dd bs=1M if=c:\temp\raspberrypi-fedora-remix-14-r1.img od=e:

The Disk will look like this in Computer Manager.  You'll notice that there's no swap partition on this image:

And the 100MB partition will look like this in Windows Explorer:


Applying the Arch Linux Image
I've run through the same process to apply the Arch Linux image and it's exactly the same, except for the command used.  For the Arch Linux image I used the following:
dd bs=1M if=c:\temp\archlinuxarm-01-03-2012.img od=e:

The Disk will look like this in Computer Manager.  You'll notice that there's no swap partition on this image:


And the 95MB partition will look like this in Windows Explorer:


Applying the 2nd Debian Release (13th April)
Following the release of the 2nd Debian image, here are the details of applying the image to an SD card. As with the other distros, the process is exactly the same, with the only difference being the command (note: change of destination drive letter compared to previous examples):
dd bs=1M if=c:\temp\debian6-13-04-2012.img od=f:

The Disk will look like this in Computer Manager, identical to the original Debian image:

And thbe 75MB partition in Windows Explorer will look like this.  Similar to the original Debian image, but with one extra file - onetime-config:

25 comments:

  1. Thanks, when receive my Raspberry, I will be use this guide! ;)

    ReplyDelete
  2. Nice guide.. was getting device already in use when using DD and realized that i need to remove the partitions as this guide suggests

    ReplyDelete
  3. I have managed to corrupt two SD Cards trying to get this Pi working what do I do from scratch?

    ReplyDelete
    Replies
    1. What do you mean by corrupt? I've found that no matter what state I've managed to get the card in, using diskpart has cleared the card, allowing windows to format it. If you really get stuck you could always put the SD card in a camera if you have one available - they tend to format the card no matter what state they're in.

      As for getting it working, the above process seems pretty reliable to me - there are a few key things you need to make sure you do:
      1. remove all partitions using diskpart
      2. run the command prompt as administrator (for Win 7)

      Hope this helps.

      Delete
  4. Great idea about the camera

    I will go through the process again
    Thanks

    ReplyDelete
  5. Hi Tass,
    I had to use 'clean' instead of 'delete partition' in diskpart - Vista would not allow me to delete partitions on removeable media.
    When I try the DD program to write the img i get 'Invalid block size' - it is 1M as mentioned and same version of DD - I am using internal card reader and 8G Apacer class 10 SDHC in an ASUS laptop.
    Any ideas much appreciated - rapidly loosing hair!
    Thanks

    ReplyDelete
    Replies
    1. I must admit, I haven't tried this using Vista as I don't have anything running that. I've hit a few issues from time to time, but found a combination of running the command prompt as administrator (very important) and using clean would be a fail-safe for applying the image. I have read that people have found Vista problematic. Sorry I can't be more help...

      Delete
  6. Hi Tass,
    Thanks for the reply - I ended up buying a new external card reader and the win32 imager worked first go with this - for some reason the internal card reader could not be seen as a device by win32 imager.
    Thanks again for the wealth of information in your blogs - Hats off 2 u

    ReplyDelete
  7. Thanks for the guide, dd.exe worked great for me (the latest beta that you linked to) on Windows 7 64bit with no issues. Wrote RiscOS Alpha to an SD card with no trouble after deleting the partitions on it with diskpart.

    ReplyDelete
  8. Hello, I had a problem: it was impossible to me to go further because when I typed DISKPART the only disk that appeared was my computer's although my SD card was there, so I couldn't choose my SD Card. How can I go on from this point?

    ReplyDelete
    Replies
    1. I'm afraid I can't help you too much. I haven't even had this happen. So - just to check, your SD card is showing up under My Computer and is accessible? If it is I can't really think of any reason my it wouldn't be accessible from DISKPART - from what I understand that's a very powerful utility that should have access to pretty much anything. Other thing's you could possibly try - formatting the SD with a digital camera; another SD card; another computer ;-)

      Delete
  9. This works but is a little difficult. I had trouble in Windows 7. Using "e:" crashed dd!!

    So. Two hints to help others. First. Use "detail" in diskpart to double check what you are doing:

    DISKPART> select disk 1
    DISKPART> detail disk

    Ok! This shows me that the SD card on mine is disk1. Remember this...

    Second. Rename dd.exe to dd-removable.exe. This really helps because you are less likely to do something boneheaded and vapourise your hard disk.

    dd-removable --list now shows something like this:

    NT Block Device Objects
    \\?\Device\Harddisk1\Partition0
    link to \\?\Device\Harddisk1\DR1
    Removable media other than floppy. Block size = 512
    size is 3980394496 bytes

    Right! So note that "Partition0" is the whole disk (/dev/sdb under linux).

    Er... Ok, so what does this mean? Well... Let's take your primary hard disk drive. As a whole, this drive is just raw bytes. In this mass of bytes you might have two partitions that mean something to Windows - say C: and D: and one that doesn't (say a linux install).
    All the information describing these partitions is actually at the very very start of the "raw" disk, not inside any partitions at all!

    Thus:

    Partition0 is the whole physical disk including info about the partitions.
    Partition1 is C:
    Partition2 is D:
    Partition3 is the linux partition.

    When writing a disk image, you *must* write it to the whole physical disk, NOT into a partition. The disk image is provided like this, partition information and all.

    Right, so now we have: DISK 1, PARTITION 0.

    So you do this, probably as administrator and making sure Explorer is closed just in case.

    dd-removable if=mywholediskimage.img of=\\?\Device\Harddisk1\Partition0 bs=1024k --progress

    When it's finished, start explorer again. Bam, Windows goes: "Hey I see partitions on that drive. I recognise one of those and can 'mount' it". And lo, you should see what's described above.

    Hope this helps someone understand what's going on...

    ReplyDelete
    Replies
    1. To visually answer a question I got here at work:

      Partition0 = (
      Partition Information Table
      Partition1
      Partition2
      ......
      unallocated space
      )

      Notice what this implies. What Tass is doing with diskpart is manually editing the Partition Information Table. But if you write to Partition0 you immediately blow away that table as it's the first thing on the disk. Under Linux, writing to /dev/sda will do exactly that. Bye bye partitions (sda1, sda2 etc).

      Under Windows, it's likely the same unless Windows decides to busy itself poking around partitions. Which it does, regularly - indexing and virus scanning etc. Which is why Tass is doing what he's doing - telling Windows to sod off and leave the partitions alone.

      But it is quite possible that you could just run dd-removable as above and that'll work fine. Er... I haven't actually tested that by the way!

      Delete
    2. Thanks very much for the detailed info Conor - great to have some extra input!

      Delete
  10. Using 'clean' command to remove partitions was easier

    ReplyDelete
  11. Thanks so much for this! I had used everything to format the disk and this was the only tutorial that worked. Thanks again!!

    ReplyDelete
  12. Hi,

    You can also use WinFLASHTool (http://winflashtool.sysprogs.com/) to do most of the work automatically.

    ReplyDelete
  13. Excellent article; a must for anyone running 64bit Windows 7. I couldn't get the Fedora Image Writer to work under windows 7.

    ReplyDelete
  14. Hello so i originally installed kali linux armel to my pi's sd card and when i did that it didnt run so i went to reformat it and i followed this guide using disk part and now windows can not detect the capacity of the disk. When erasing the partitions of the sd is this causing us to delete the factory partition and making it to where windows cant interface with it? Please respond i need to verfy if i have potential hard ware failure. Also disk part can verfy there is 14 gb of free space out of 14

    ReplyDelete
  15. Superb blog , it’s a really informative blog for all user who can facing windows 7 problem, Our services provide complete solution of your windows 7 realted problem.please go through this link .
    windows 7 problems
    Thank you
    Aalia lyon

    ReplyDelete
  16. how can I install raspbian with a 64 bits windows 8 computer?

    ReplyDelete

  17. I've installed windows 7 on my laptop after buying license from cheaproduct, I want to activate it to get free upgrade from windows 7 professional to windows 10 home.
    I'm now confused, How to activate and upgrade to windows 10.
    Please mention within details.


    ReplyDelete