天天看點

How to Flash an SD Card for Raspberry Pi

http://computers.tutsplus.com/articles/how-to-flash-an-sd-card-for-raspberry-pi--mac-53600

The Raspberry Pi is an incredible little computer made up of a components and connectors on an unfeasibly small printed circuit board that is approximately the dimensions of a credit card. Depending upon your intended use, your Rasberry Pi may have a keyboard, monitor and mouse added. Regardless of your intended use, you are going to need an SD (Secure Digital) card on which to install an operating system.

This tutorial describes how to install an operating system onto an SD card for use in your Raspberry Pi.

What You Need to Do and Why

In order to get up and running with your Raspberry Pi, you will first need to flash an SD card. Whilst your Mac, or PC, uses a magnetic hard disc drive (HDD) or a Solid State Drive (SSD), your Raspberry Pi has no internal storage of its own.

Instead, the Raspberry Pi uses a Secure Digital (SD) card, such as is common as storage in many digital cameras.

This means that the Raspberry Pi will run from whatever operating system you install on an SD card. You can do from your main computer regardless of whether you are using Apple OS X, Linux or Microsoft Windows.

The Importance of SD Cards

Not all SD cards are created equal, it seems, and some SD cards are known to work better than others. Some SD cards will refuse to work at all with your Raspberry Pi. It is worth checking the compatibility of any given SD card before you purchase. This has the potential to save much frustration further down the line.

How to Flash an SD Card for Raspberry Pi

Choose the right SD card for RPi

It is recommended that you purchase an SD card with a minimum capacity of 2GB. Depending on which operating system you intend to use, it may be better to go for 4GB. Prices are coming down all the time to make these very affordable.

It’s not just the importance of SD cards, it’s the flexibility that they afford, too. Since changing the operating system in your RPi is as easy has swapping the SD card, it is possible to experiment with many different OSes simply by having a number of SD cards with a different system installed on each.

Tip: Before purchasing SD cards, it is worth checking their compatibility on this list of SD cards known to work with Raspberry Pi.

Before You Flash an SD Card

Download an Operating System

For the purposes of this tutorial I will be downloading Raspian, for Raspberry Pi.

The download will be compressed as a .zip file. You will need to extract the .img file before proceeding.

Tip: You can download a number of different operating systems, including RISC OS, Raspian, Raspbmc, Openelec and pidora, from the Raspberry Pi downloads site or you can download the NOOBS, New Out Of Box Software

Flash an SD Card Using OS X

Format the SD Card

Formatting an SD card is quite straight forward with Mac OS X. Start by pressingCMD SPACE to reveal the Spotlight search bar at the top right hand side of the screen. In this search bar, type disk utility and press return to launch the Disk Utilityapplication.

Select the SD card, in the left hand pane, and then select Erase ensuring that the format is MS-DOS (FAT).

Identify the SD Card

Flashing an SD card is quite straight forward with Mac OS X. Start by pressing CMD SPACE to reveal the Spotlight search bar at the top right hand side of the screen. In this search bar, type terminal and press return to launch the Terminal application.

Insert the SD card into your Mac’s SD card drive.

To find the connected SD card, in the terminal window type:

diskutil list      
How to Flash an SD Card for Raspberry Pi

Listing the volumes in OS X's Terminal.

Make a note of the identity of yours. In my example it is 

/dev/disk2

 but yours may be different.

If the SD card was automatically mounted, as mine way, you will need to unmount it with the following command in Terminal. Remember to correctly identify your SD card if it is a different number to my example.

diskutil unmountdisk /dev/disk2      
How to Flash an SD Card for Raspberry Pi

Unmounting the SD card is OS X

Navigate to the location that you downloaded and extracted the .img file from the .zip download. In my case it is the Downloads directory.

cd Downloads/      
How to Flash an SD Card for Raspberry Pi

Navigate to the folder for the downloaded image

TIP: The 

dd

 command is very powerful and you risk serious corruption to your Mac if you use it incorrectly. Triple check your command before executing it, or use a different method (described below) to flash your SD Card if in doubt.

Flash the SD Card

Ensuring that you replace the .img and destination, in my example, with the correct .img name destination disc for yours, enter the following command:

dd if=2013-07-26-wheezy-raspbian.img of=/dev/disk2 bs=2m      
How to Flash an SD Card for Raspberry Pi

Flashing the SD card

In my example, Terminal responded with 

Permission denied

 so, instead, I entered the following command, followed by my administrator password:

sudo dd if=2013-07-26-wheezy-raspbian.img of=/dev/disk2 bs=2m      
How to Flash an SD Card for Raspberry Pi

If you get "Permission denied", use sudo dd

It will then take a few minutes to flash the SD card during which time no progress information will be shown. Be patient. On completion, you will get a confirmation with some information displayed in terminal.

How to Flash an SD Card for Raspberry Pi

Confirmation of completion in OS X Terminal

You are now free to unmount the SD card for use in your Raspberry Pi.

Flash an SD Card With an App in OS X

If you are not comfortable, in flashing an SD card, using the command line interface (CLI) then you can instead download an app to do this for you.

I use RPi-SD card builder x1.2 which is a little friendlier. Download, extract and launch this app to avoid the CLI.

On launching RPi-SD card builder x1.2, you are presented with a Finder window in order to navigate and select your chosen .img file. The app, itself, will be running as a Raspberry Pi icon in the dock.

Locate and select the image and ensure that your SD card is plugged in and mounted.

How to Flash an SD Card for Raspberry Pi

Locating the OS image file

You will be presented with a window asking you to select your SD card. Be extremely careful. All drives are selected by default and you could easily corrupt your Mac if you select the wrong disc. The clue is to look at the disc capacities and, in my example, you will see that the capacity of the SD card is only 8GB compared to 1TB for my Mac’s hard drive.

How to Flash an SD Card for Raspberry Pi

Pay attention to which volume you are selecting - they are all selected by default and this could be catastrophic

Only when you are sure that you have selected only the correct SD card, enter your administrator’s password when prompted.

How to Flash an SD Card for Raspberry Pi

Enter your admin password to continue

You are then given a warning not to remove the SD card whilst the app flashes the SD card. Click Continue.

How to Flash an SD Card for Raspberry Pi

Do not remove the SD card whilst flashing

You can monitor the progress of the operation by clicking on the rotating cog icon in the menu bar. The process to flash the SD card takes a few minutes, so be patient.

How to Flash an SD Card for Raspberry Pi

How to monitor the progress

A dialogue box will advise you on the completion of the SD card being flashed. The SD card has already been unmounted, so you are safe to remove the SD card from your Mac for use in your Raspberry Pi.

How to Flash an SD Card for Raspberry Pi

Confirmation of completion

Flash an SD Card Using Linux

The Linux distributions provided, for Raspberry Pi, are done so as a compressed image file. You will need to download, uncompress and then install onto your SD card.

For the purposes of this tutorial I am using Ubuntu, one of the most popular Linux distributions.

Format the SD Card

It may be necessary to format the SD card so that it can be read by your Raspberry Pi. If this is the case, you can use the Disk Utility application in Ubuntu.

How to Flash an SD Card for Raspberry Pi

Use Ubuntu Disk Utility to format the SD card

Select your SD card and format as FAT.

How to Flash an SD Card for Raspberry Pi

Formatting the SD card using Ubuntu Linux

Identify the SD Card

Plug the SD card into the SD card drive on your Linux machine.

Open a terminal window and, to list the attached discs, type:

sudo fdisk -l      
How to Flash an SD Card for Raspberry Pi

Listing the attached volumes in Ubuntu Linux

Identify the SD card and make a note of the device address, such as 

/dev/sdX

where X denotes the storage device. Note, you can easily identify your SD card by looking at the capacities of the discs listed.

Flash the SD Card

Once you have identified and formatted your SD card, you need to flash the SD card. This is done with the unix command 

dd

.

Before proceeding, navigate to the directory that contains the downloaded and extracted .img file.

cd Downloads      

In a terminal window, enter the following, ensuring that the distribution name (in this example: 

if=2013-07-26-wheezy-raspbian.img

) is correct and that the destination (in this example: 

/dev/sdb1

) as they may be different to the ones used in this example:

sudo dd if=2013-07-26-wheezy-raspbian.img of/dev/sdb1 bs=2M      
How to Flash an SD Card for Raspberry Pi

Locating the downloaded image file

TIP: You will need to exercise care using the 

dd

 command. Careless use may result in the corruption of your computer’s main hard drive if you incorrectly identify the drive required.

The process of flashing the SD card will take around two or three minutes during which time you are given no indication that anything is happening, unless your SD drive has a flashing LED.

Once the SD card has been flashed, you will see a further message in the terminal window.

Unmount the SD card and it is now ready for use in your Raspberry Pi.

How to Flash an SD Card for Raspberry Pi

Terminal confirmation of completion

Flash an SD Card Using Windows

Format the SD Card

Locate your SD card drive, in Windows Explorer, and secondary-click the mouse to bring up the context-senstive menu. From the menu select Format…. Ensure that the option FAT32 (Default) is selected and click Start.

How to Flash an SD Card for Raspberry Pi

Selecting an SD card to format

A few moments later you will see a confirmation that the format has been completed and you SD card is now ready for the next stage.

How to Flash an SD Card for Raspberry Pi

Formatting the SD card

Download Image Writer

In order to flash the SD card in Windows, it is necessary to first download a third-party application named Image Writer. (Here’s the direct SourceForge link for Image Writer)

Once downloaded, uncompress the .zip file by secondary-clicking it and selectingExtract all from the context-sensitive menu. This will normally place a folder of extracted files into the same folder that contains the downloaded .zip file.

Flash the SD Card

Locate and open the folder of uncompressed files that you recently downloaded. Launch the Image Writer application by double-clicking the Win32DiskImager.exeprogram that you can see in the folder of extracted files.

If your PC asks you, give permission for the program to make modifications. This will open the Image Writer program.

How to Flash an SD Card for Raspberry Pi

Grant permission for the program to run

In Image Writer click on the blue folder icon, to the right of the white box, and locate your .img file. This will be contained within a folder that you extracted from the downloaded .zip file. Select the .img file and click Open to populate the white box with the path to your image.

How to Flash an SD Card for Raspberry Pi

Selecting the image in Image Writer

In the Device box, on the right, ensure that the drive letter for your SD card is selected.

Tip: You can double-check the correct drive letter, for your SD card, by pressing CRTL E to open Windows Explorer and locating the SD card drive.

When you are satisfied that the path to the .img file and the destination drive letter are both correct, click the Write button to start the process of flashing the SD card. The process will take four or five minutes and you will be shown a green progress bar during the course of the operation.

How to Flash an SD Card for Raspberry Pi

Image Writer progress

Upon completion, a confirmation window will be displayed and you will be free to close Image Writer and eject the SD card before removing it.

How to Flash an SD Card for Raspberry Pi

Confirmation message on completion of flashing the SD card frameborder="0" src="http://tpc.googlesyndication.com/safeframe/1-0-2/html/container.html#xpc=sf-gdn-exp-1&p=http%3A//computers.tutsplus.com" id="google_ads_iframe_/11757429/hub_computer_skills_inarticle_0" title="3rd party ad content" name="1-0-2;33078; scrolling="no" frameborder=0 height=0 width=0 src="https://cm.g.doubleclick.net/push?client=ca-pub-3558870564527416" style="position:absolute">{"uid":1,"hostPeerName":"http://computers.tutsplus.com","initialGeometry":"{\"windowCoords_t\":23,\"windowCoords_r\":1179,\"windowCoords_b\":754,\"windowCoords_l\":27,\"frameCoords_t\":15131,\"frameCoords_r\":573,\"frameCoords_b\":15381,\"frameCoords_l\":273,\"styleZIndex\":\"auto\",\"allowedExpansion_t\":0,\"allowedExpansion_r\":0,\"allowedExpansion_b\":0,\"allowedExpansion_l\":0,\"xInView\":0,\"yInView\":0}","permissions":"{\"expandByOverlay\":false,\"expandByPush\":false,\"readCookie\":false,\"writeCookie\":false}","metadata":"{\"shared\":{\"sf_ver\":\"1-0-2\",\"ck_on\":1,\"flash_ver\":\"21.0.0\"}}","reportCreativeGeometry":false}" scrolling="no" marginwidth="0" marginheight="0" width="300" height="250" data-is-safeframe="true" style="box-sizing: border-box; max-width: 100%; border-width: 0px; border-style: initial; vertical-align: bottom;"> Advertisement

Booting Your Raspberry Pi

On booting your Raspberry Pi, with Raspian, after much activity on the screen, you will be asked to enter a username and password, which are:

Username: 

pi

Password: 

raspberry

Then, to start the Raspian GUI, enter:

startx      

Conclusion

On getting your Raspberry Pi out of the box, and plugging in peripherals, the task of flashing an SD card might seem quite daunting.

In this tutorial, I have shown you how to flash an SD card with Raspian using either Ubuntu Linux, Apple OS X or Microsoft Windows. With OS X, I have demonstrated flashing an SD card with both the command line and a third-party application.

This is not an exhaustive tutorial; there are many ways to flash the SD card. I have steered away from the command line as much as possible to make the process as easy as possible for beginners. Using the comments, below, let me know how you get on?