Home‎ > ‎Dabbles‎ > ‎RaspberryPi‎ > ‎

RaspberryPi 101 - Writing the Image to the Memory Card (Linux)

posted Oct 6, 2015, 6:55 PM by Joshua S   [ updated Dec 12, 2015, 8:59 AM ]
This tutorial will explore completing this task using Debian Jessie Linux with the KDE environment.  I chose Debian as the operating system for my laptop because the RaspberryPi's Raspbian operating system is also based on Debian.

This post focuses on writing an image from Linux to the RaspberryPi memory card.  We'll do this using the dc3dd utility in Linux.  It can also be completed using the native dd platform, but dc3dd offers enhanced functionality and status reporting so we know how close the process is to completion.

This is useful both for initially writing the image of the downloaded Operating System onto the memory card (installing the OS), but also for restoring a backup image in the event this is necessary.

Note -- the latest version of Raspbian (Jessie), as of the writing of this tutorial, requires a minimum memory card of at least 4 GB.

With any of the Dabbles on this site, if you have questions, suggestions, or thoughts, please feel free to send me an eMail (I'm still working to figure out how to enable comments on Google Sites -- suggestions would be appreciated)!



Supply List:
  • SDHC Card or MicroSD Card  A digital memory card, initially designed for media (think a camera) but which will serve as the hard drive for the RaspberryPi.  The older RaspberryPi models leveraged the SDHC form factor while the newer versions leverage the MicroSD form factor.
  • RaspberryPi  The actual RaspberryPi hardware this will all be built around.  
  • Raspbian  The Debian Linux based Operating System (OS) designed for the RaspberryPi.  Download the latest version from the website.  Note, other OS's are also on this page, including a version of Fedora and a port of XBMC, but my projects all work with the Raspbian distro.
  • dc3dd  An updated, patched, version of the GNU dd utility, developed by the DoD Cyber Crimes Center, to read and write image (.IMG) files to various flash card media (SDHC, MicroSD, etc.).  Download the software using apt-get on Debian if you do not already have it in your environment.

Project:
  • I know I said this guide was going to be comprehensive and not skip any steps, so what better way to start this off than by skipping steps.  I am not writing out instructions for the following (and illustrating from XKCD):
    • Buying a MicroSD Card
    • Buying a RaspberryPi
    • Downloading & Extracting Raspbian
    • Installing dc3dd on Debian
https://xkcd.com/1343/
  • Open a shell as root or with a user who has sudo authority.  For purposes of this tutorial, we will use an account with sudo authority, but, if run as root, simply remove the sudo command from the below steps.  For a refresher on sudo, see the below illustration from XKCD.
  • Insert the memory card into your computer's reader (or adapter if you do not have a reader built in).  We need to see if Debian auto-mounted the memory card by issuing the sudo df -h command to see what is currently mounted.  Note, memory cards should show up on the file system under the /dev directory, and are most easily identified by referring to the size column to find one closely matching the memory card inserted.  Cards should show up as either /dev/sdX (where X is an alphabetical letter) or /dev/mmcblkX (where X is numerical).  If Debian mounted partitions (such as in the below example) they will be noted with the letter "p".  In our example, the card would be identified as /dev/mmcblk0, but partition 1 an 2 are mounted as /dev/mmcblk0p1 and /dev/mmcblk0p2.
sudo df -h


  • In our example with two partitions mounted, we'll need to unmount each prior to proceeding using the umount command as shown below.  When this is complete, re-issue the df -h command to validate the partitions have been unmounted.
sudo umount /dev/mmcblk0p1
sudo umount /dev/mmcblk0p2
sudo df -h


  • With this completed, let's partition our memory card to ensure it is clean and ready to receive the image, using the mkdosfs -I -F32 command.  Note, this references the /dev/mmcblk0 device without referencing either partition.
sudo mkdosfs -I -F32 /dev/mmcblk0

  • With the disk prepared, it is now time to issue the dc3dd command to write the image file (downloaded and extracted previously) to the memory card.  Note, the if= argument specifies the input file while the of= argument specifies the output file (or device in this case).  In the example we use the following command:
sudo dc3dd of=/dev/mmcblk0 if=/home/user/Desktop/RPi/2015-09-24-raspbian-jessie.img



  • Remove the freshly written card from your computer's reader and insert it into the RaspberryPi.  
  • Mission accomplished!  You wrote the operating system image to your RaspberryPi!
Comments