Writing a Raspberry PiMemory Card

Table of Contents

Introduction

This page details how to write a Raspberry Pi operating system image file to a memory card.

Instructions are given for both Windows and Linux.

Mac users will find the instructions for Linux work also on a Mac, at the command-line using dd.

Note that early versions of the Raspberry Pi used a full-sized SD card. Later versions, up to the current date, now use a micro-SD card.

Any reference on this page to ‘SD card’ or ‘micro-SD card’ should be taken to mean the size of card you are using for your Raspberry Pi.

Windows

The application that the Raspberry Pi Foundation recommends using on Windows to write an operating system image file to an SD card is not very accessible. At least not with the free and Open Source NVDA screen reader.

Instead we will use a tool called WinFlashTool.

I have found WinFlashTool to be very accessible usinthe [free and Open Source NVDA screen reader/[nvda/. I have no experience of using the Jaws screen reader, but that should work also.

I do not know about any other Windows screen reader.

First you will need to download WinFlashTool and install it.

You will also need some way of mounting the SD card on your Windows machine. USB SD card readers are good for this if your computer does not have either an SD or micro-SD card slot.

You will need to use a full size SD card for the older type of Raspberry Pi, or a micro-SD card for the Model B+ or version 2 Model B+ and later.

Dealers who sell micro-SD cards often include a micro-SD to SD adaptor with the purchase of a micro-SD card. These are useful if your card-reader only takes full-size SD cards.

It is important to note that just copying, or using drag-and-drop to put a .img file onto an SD card will not work. The file needs to be written to the card byte-for-byte.

Also note that if a .img file has previously been written to the card, only one of the 2 or more disk partitions on the card will be recognised by Windows. This is because the boot partition is FAT32, which Windows can read, and the other partitions on the card are Linux partitions which Windows is not capable of reading.

Once you have installed WinFlashTool on your Windows machine, follow these steps:

  1. Open WinFlashTool using the start menu or however you usually launch programs.
  2. You will hear something like source image grouping and the text field that has focus is for the name of the .img file to write to the card.
  3. If you press the TAB key at this point you will hear something like … button. This is the browse button which will open the file-finder dialog for you to locate your file. Or you can just type the full path and file-name into the first text box.
  4. The next control is a list of the devices on your computer. It will give you a list you can navigate up and down with the up and down arrow keys. But see the next item on this list for a way to hide your hard-disk and avoid the nasty accidental over-writing of your system.
  5. The next control to gain focus when you press the TAB key is a checkbox which allows you to hide devices that are not replaceable media. Checking this box is a good idea as it will prevent you from accidentally writing the .img file to your hard disk. And you don’t want that to happen.
  6. Next control is the write button. Which will begin the write.

Windows Notes

When you begin the write, Windows will pop-up after a couple of minutes and tell you that you need to reformat the drive. Just cancel out of this as the write will not continue until you do.

When the write is complete you might get another pop-up of the open folder to view files variety. Again, ignore this nonsense.

At this point you can close WinFlashTool, remove the card from it’s slot or holder, insert it into your Raspberry Pi and boot it.

If the file was a valid operating system that is bootable, and if the write has worked correctly, the Pi should boot.

Linux and Mac

Writing an OS image to an SD card on a Linux or Mac is simple. It can even be done on a running Raspberry Pi.

You will need the image file, an SD or micro-SD card depending on which type of Raspberry Pi you are writing it for, and some way of mounting the card into the Linux machine on which you are going to do this process.

This may be a dedicated SD or micro-SD card reader slot built into the machine, or a USB card reader which plugs into one of the USB ports on the working machine.

When you plug an SD card into a Linux or Mac computer, if there are any partitions already on the card, they may be auto-mounted somewhere. You will need to unmount these before you proceed.

You need to know what device name has been assigned to the card once it has been plugged into the machine.

With some flavours of Linux, it may be necessary to do this once the card has been plugged in and before you can start:

$ sudo partprobe

This is certainly true on my Debian machine.

Next you can find out what the device name is by doing something like this:

$ sudo fdisk -l | grep -i "disk /"

You can redirect the output to a file and then view it if that helps.

You need to pay very close attention to the device names and the sizes of the volume to which each relates.

I cannot stress strongly enough that it is very important to correctly identify the device which is the SD card. It is not without good reason that the dd command is sometimes said to stand for ‘data destroyer’. You will not get a second chance if you accidentally give the wrong device name and wipe out your hard-disk.

The dd command does not do any of the friendly ‘Are you sure?’ kind of stuff.

Now, suppose the name of the .img file is filename.img and the device which has been assigned to the SD card is /dev/sdx. This command will write the file, byte-for-byte, to the SD card:

$ sudo dd bs=512 if=filename.img of=/dev/sdx status=progress

The status=progress part is only available on later versions of dd. I think current (new years day, 2021) versions of both Debian and Ubuntu are up to date with this option.

Check the output at the completion to see if the messages printed to the screen include no space left on device. If it does, you have not used an SD card that is big enough.

Now it is a good idea to give the sync command, for which sudo is not needed:

$ sync

If the image file you have written to the card, and it has worked correctly, plugging the card into a Raspberry Pi and powering it up should boot.

Note that images from the Raspberry Pi Foundation more recently contain code to expand the file-system to the full size of the SD card on first boot.

This means the first boot may take longer than subsequent boots.

Disclaimer

I emphasised earlier in this page that it is very important to be sure you are pointing at the right device, the one which is the SD card to which you intend to write. But it is worth saying again.

All details on this page are correct to my present knowledge.

However no guarantee of fitness for purpose is given or implied.

Using both WinFlashTool on Windows and dd on either Linux or Mac have the potential to overwrite the boot partition of your primary disk, or render the data on other drives completely unreadable and probably unrecoverable.

Be very careful in all use of these tools that you select the correct device.

The device which represents the SD card to which you wish to write the data.

You have been warned.

t