Monday, 28 September 2015 13:05

Write a Raspberry Pi SD Card In Linux Command Line CLI

Written by 
Rate this item
(1 Vote)

5 easy steps to write a Raspberry Pi 2 (or 1) image to an SD card using the linux command line

A step-by-step detailed illustrated instruction guide

 - Download your image for the Raspberry Pi

Download the image you want to use, make note of the location you are saving your image to (ie: ~/Downloads).  I usually use the Raspbian Jessie image for most of my projects.


- Raspberry Pi 2 will require a micro SD card adapter, for most computers

Raspberry Pi Linux SD Card 04

- Find the SD card

Unplug your SD card from you computer and run this in the command line

watch 'dmesg | tail -20'

While that command is still running, plug the SD card back in, your looking to find what device it is showing up as (ie: sdb, sdc, sdd, etc)

Raspberry Pi Linux SD Card 01

In our example, you can see that the SD card is showing up as sdc, In these examples, we will now refer to our card as sdc (although yours may be sdb, sdd, etc)

Once you see something similar to this screen press Ctrl+c to exit the last command.


- Unmount the SD card partitions

See what partitions are mounted

df -h

If there were any partitions mounted for our drive, in our example we are looking for /dev/sdc[<number>], you would see /dev/sdc1 pointed to a directory

Raspberry Pi Linux SD Card 02


This will un-mount all partitions associated with sdc, in the command below, substitute sdc, with your drive (sdb,sdd, etc)

for n in /dev/sdc* ; do umount -l $n ; done 


Run the df -h command again to show all partitions with our card are no longer showing up

df -h


- Image the SD card with the Raspberry Pi image you downloaded in the previous step

Uncompress the downloaded raspberry pi image, substituting the directory path and image name to match your image

unzip ~/Downloads/ -d ~/Downloads


The next command will write to the SD card, anything that may have been on the SD card previously will now be overwritten permanently


Using the command dd, we will write the image you previously had downloaded, directly to your SD card

*Important, be sure to substitute the full path of your Raspberry Pi image and your SD letter (sd[x]) shown in the example below

sudo dd bs=4M if=<-full-path-of raspberry-pi-image> of=/dev/<sd-card-location>


sudo dd bs=4M if=~/Downloads/2015-11-21-raspbian-jessie.img of=/dev/sdc

You will not see any progress as the card is being written, It should take around 5 minutes or so.


Raspberry Pi Linux SD Card 03

Once you're back to the command prompt, it's complete, remove the SD card and insert it into your raspberry pi and have some fun!

*The above image shows me using the raspbian-wheezy image, but now I typically use the raspbian-jessie image.




Read 8103 times Last modified on Thursday, 04 February 2016 20:46
Algis Salys

Creator and owner of  Linux enthusiast, electronics tinkerer, and likes to spend time in the workshop building and creating new projects.