How to prepare SD card for Raspbian OS and write the image to the SD card.

This post is a quick overview of how to make a copy of the Raspbian image, extract it, and write the  Stretch OS image to a newly formatted SD card.  You can visit the official detailed RPi Easy SD Card Setup for extra support.

1. Download Raspbian Stretch OS image .

The total image size is (4GB) .

Get the image here: Raspbian Stretch OS image.

( You can later purge unwanted apps to free up disk-space after you get the OS (operating system) installed and setup. )
For example, if you wanted to remove  ‘libreoffice’ you would enter at the terminal prompt:
$ sudo apt-get remove --purge  libreoffice   
Then run:
$ sudo apt-get autoremove  --purge              // removes any orphans

  1. $sudo apt-get autoclean” and “sudo apt-get clean” only deletes the apt cache where recently downloaded packages are stored.
  2.  “autoremove” deletes packages that no one depends on any more.
  3. "apt" is meant to replace several commands like “apt-get” and “apt-cache“.

Or, you could just download this script and run  it. ( I read the code: it’s safe)

Okay!  Sorry about that.  The cart before the horse. Let me get back on track.

2. Select and Format your microSD card. 

Selection of the SD card.

A. The Raspberry Pi Org SD card recommendation
     (Not all cards are the same! Check the compatibility.)
    1.  SD cards larger than 32GB are usually of the SDXC  type and come in the exFAT (Extended
         File Allocation Table) format which is not recognized by the Raspberry Pi. 
* Read this article if using a card larger than 32G.
*  There is a work-around for the exFAT if you really need to use it.  See this article by Gus at PiMyLifeUp .
B.  Jeff Geerling has a great blog post on microSD cards performances used on the Pi.
       1.  His top recommendation is the Samsung microSD cards.

Formatting the SD card. 

BEST CHOICE for all users => Etcher.
A.  Etcher! – for all users (cross-platform).  Formats and flashes the OS onto the SD card all at once.  ( It also helps to keep from overwriting the system disk of your computer. )

B.  SD Card Formatter – for all operating system users.

C.  Disk Utility – for Mac Os users.
Use the ‘erase‘ in the disk utility tool to format the card. Be sure to select the correct disk format.
      1. Using Mac Terminal.  And another good example.
      2. The Mac way from Raspberrypi.org

D. GParted – for Linux users. (For the more advanced user. Great tool.)

3. Unzip or ‘extract’ the compressed Raspbian image.

 A.  All Users:  Etcher is my first choice!  Awesome and simplifies.  (open source)

 B.  Mac Os users: can just double-click the downloaded zip file to extract it and save it to a   location of the user’s choice.

C.   Window users:    7-Zip

 

4. Flash/Write the image to the microSD Card  

A. Window Users Win32 Disk Imager .  The image below shows an ‘Image File’  text box containing the absolute path of to the directory I saved my  2018-11-13-raspbian-stretch-full.img.  This is basically the “from” directory.  In the example below, I saved the Raspbian OS image to my ‘/Desktop/’.  The ‘Device’ text box shows the device ‘letter’ [G:\] of my SD device mount point.  To check to see if it is the correct device letter just open the “File Manger” and right-click and eject the device letter. Then reinsert it and watch the device letter reappear in the file manager.  NEXT,  select the “write” button to ‘write to’ the SD card.

Win32 Disk Imager
Snap-shot of the Win32 Disk Imager tool.

 

B.  For Mac users:

Lets say you’ve already downloaded the latest version of the Raspbian Image as explained above
and saved it to your Desktop.
Next, insert the now formatted SD card into an SD card reader or directly into your MacBook.
Open up a Terminal window and enter on the command line $ df   -h

[Sidenote: When using Terminal you’ll need to be the super-user-do.
Enter this command line statement   $ sudo su
You’ll have to enter your password.]

This will show mounted devices. On the Mac OS the mounted device for the SD card will be something very similar to:  /dev/disk2s1 ….  /Volumes/SD Card
(You need to remember this part =>  /disk2s1 ) [especially the number after the word, “disk”]

Next, using the /dev/desk2s1 you previously discovered, enter this command to unmount the card: $ sudo diskutil umount /dev/disk2s1 

Next, now from the command line $ cd into the directory where you saved the Raspbian image.
In this tutorial, as I explained above, I saved mine to my ‘Desktop’ directory.  So, I enter; $ cd  /Desktop

Then run the command: $ pwd 
This command ‘print working directory’ shows you the directory your currently working in.
So, for our purposes of this tutorial we want it to return something similar to : $/MacBook/Username/Desktop/
We want the ‘Desktop‘ at the end of our returned values. If you don’t see the ‘Desktop’ at the end your not in the Desktop directory. Check your spelling at the command-line .

Look for the downloaded Stretch image file on your Desktop. Arrow over to it, right-click it, go down to the bottom at Properties, right-click it open, and copy the full filename and paste it into the command-line at the terminal. and run the ‘unzip’ command;
$ unzip  2018-11-13-raspbian-stretch-full.img.zip (or similar)

 

Then, in the  Terminal write the Raspbian OS image to the  SD card
$ sudo dd bs=4m  if=/Users/<your-username-here>/Desktop/2018-10-09-raspbian-stretch.img    of=/dev/rdisk2

  • The if means input file. of means output file.
  • Place a character ‘r’ in front of the /disk2 like so,  /rdisk2
  • The ‘s1’ from the  /dev/disk2s1  should be removed!
  • The integer ‘2’ on the ‘disk2s1’ will be different (maybe) on your computer. It could be a 3, 4, or higher numerical value.
  • The ‘m’ in 4m is a lowercase character. (relates to how fast the image is written)
    (if having error issues: change the value ‘4’ to a lower numerical value(like a 2), and or change the lowercase character ‘m’ to an ‘uppercase ‘M’, or vice-versa)
  • Once more to be sure: The disk2 is found in the Disk Utility. Once you insert the card reader device into the USB port on the Mac, it mounts it under /dev/.  The ‘disk2sl’ will show in the bottom right corner of the external Device information under=> ‘Device’.  Here mine is disk2sl. You need to remove the ‘sl’ as it’s not needed. Ergo the ‘disk2’ only. Now, more importantly, when you plug your USB device in the ‘2’ in the disk2sl could be a ‘3’ a ‘4’. You get the idea.
    To be sure you have the correct disk selected have the disk utility open and under the “external” section watch it disappear as you eject the card.
  • You can also go to the Apple icon > About this Mac> System Report> look under the ‘hardware’ list on the left for ‘USB’ and click it open. Find the USB card device.

 

When done eject the card by entering the following command;
$ sudo diskutil eject   /dev/rdisk2

Go plug it into the Pi, configure it, and set it up.