Читать книгу Raspberry Pi Projects For Dummies - Evans Jonathan - Страница 11

Part I
Getting Started with Raspberry Pi Projects
Chapter 1
Getting to Know the Raspberry Pi
Flashing Your SD Card

Оглавление

Your operating system is made up of a bunch of files that are run from the SD card itself. However, when you write the operating system’s files to the SD card, they’re written in a special format that Linux can read. You can’t just copy them over as you would with other kinds of files. The Linux distribution you downloaded is in a special format called a disk image. And you flash the disk image to the SD card using a special little program. The program you need depends on whether you’re using Windows, Mac, or Linux.

Flashing an SD card in Windows

To create the image file in Windows, you use a special program called Image Writer for Windows. It’s free and pretty easy to use. Just follow these steps:

1. Insert your SD card into your computer’s SD card slot or, if you don’t have one, into your SD card reader.

Take note of which drive letter is assigned to your SD card.

2. Download the files at www.sourceforge.net/projects/win32diskimager/files/latest/download.

If you want more information about Image Writer for Windows, go to www.launchpad.net/win32-image-writer.

3. Double-click the file to extract it, click Extract All Files to unzip the archive into a folder, and then open the folder.

Note: If the filename of the file you downloaded ends with .exe, when you double-click the file, an installation wizard may run.

You should see the list of extracted files. Make sure that you aren’t looking at the zipped files.

4. Click the file Win32DiskImager.exe to open it.

5. Click the folder icon to the right of the long white box and navigate to the Linux .img file you just unzipped; double-click to select it.

This will put the file path into the long white box for you.

6. From the Device menu, select the drive letter that your SD card has been assigned.

Be absolutely sure you’ve got the correct drive selected – the one that contains your SD card. Whatever drive you’ve chosen in the device menu will be completely erased!

7. After you’ve double-checked that you’ve selected the right drive, click the Write button to create the image file on your SD card.

Flashing an SD card on a Mac

On a Mac, you can use a simple script called RasPiWrite to do the work of flashing your image file to your SD card. First, you create a folder that RasPiWrite can use while it’s flashing your SD card. Then you use the script to create your image file. You do some of this by typing commands on the command line, using the Terminal program, which is found in your Applications/Utilities folder.

You need your system password to be able to flash the SD card. Just follow these steps:

1. In your Documents folder, create a folder called SD Card Prep; in the SD Card Prep folder, create a folder called RasPiWrite.

2. Go to https://github.com/exaviorn/RasPiWrite to download the zip file of RasPiWrite.

3. Double-click the file you downloaded and open the resulting folder.

4. Drag the files in this folder to the RasPiWrite folder you created in Step 1.

5. Drag the zip file of your Linux distribution into your RasPiWrite folder.

6. Open the Terminal application, located in Applications/Utilities, and type cd and then a space.

7. Use the Finder to locate the SD Card Prep folder you created in Step 1; make sure you can see both the Finder window and the Terminal window, and then drag the RasPiWrite folder into the Terminal window.

This places that path name of that folder into the command line for you. (It’s easier than typing it all out.)

8. Press Return.

This switches you to the folder containing RasPiWrite.

9. Type ls and press Return.

The list command produces a list of files in the RasPiWrite folder. You use it later to tell RasPiWrite where to get the source files for your disk image.

1. Remove any external memory cards, USB sticks, or other pluggable storage device from your system so that you don’t accidentally erase them.

2. Type sudo python raspiwrite.py to run RasPiWrite.

3. Enter your system password.

You see a progress report as your script creates the disk image. If all goes well, you should see a raspberry made of text characters.

1. Insert your SD card into your Mac’s SD card slot or to an external SD card writer and press Return.

2. Follow the prompts to select the disk that corresponds to your SD card.

You can double-check to make sure you’ve selected the correct one by ensuring that the disk’s size (listed in the size column) corresponds to the size of your SD card. You don’t want to erase all the data on your main hard drive!

1. You’ll be asked if you want to download a distribution; because you already did that, type N.

The program asks you to locate the disk image file.

1. Scroll back up to where you used the ls command and copy the filename of the distribution; then scroll back down and paste this filename at the prompt and press Return.

The program extracts the image file and prepares it to upload onto your SD card. It then asks you to confirm that you’re about to erase your SD card. Be sure you’ve got the right SD card.

1. Type accept to continue installing the image, and press Return.

The flash process can take a long time. You’ll see some dots on your screen as the process continues. Depending on your system, it can take 30 minutes or even up to an hour. You can use your computer for other things during this process, but if you lose power or restart, you’ll have to start all over again.

If you’re presented with a message immediately after typing accept, there’s a problem. Even though the message may say Transfer Complete, the immediate response means that the transfer hasn’t been accomplished. This sometimes happens if the image file isn’t located where you indicated it was or if the distribution contains just an image file rather than an image file within a folder of the same name. If it happens, create a folder with the same name as the image file, drag the image file into it, and try again.

Flashing an SD card in Linux

If you’re using Linux, the process of flashing an SD card for your Raspberry Pi is pretty straightforward. We assume you’re using Ubuntu, one of the most popular Linux distributions. If you’re using another distribution, the following steps will be very similar.

When you download the Raspbian Wheezy distribution, make sure you save it where you can find it, such as in the Documents directory. Then follow these steps to flash your SD card:

1. Remove any external drives, USB keys, or other SD cards from your system and insert the SD card you would like to flash for your Raspberry Pi.

2. Open a Terminal window.

This is located in the Applications menu under Accessories.

3. Type sudo fdisk –l (the last character of this command is the letter l, not the number 1).

This starts the fixed disk program, a tool you can use to manage, erase, and separate disk drives into different logical partitions. It also shows you which drives are available on your system.

4. Locate your SD card in the device list.

The list gives details about each of the drives on your system, including the size of each device in bytes and other details such as the number of heads, sectors, cylinders, and so on. Find the device that most closely matches the size of your SD card in bytes. For example, an 8GB SD card will be listed as about 8,068MB. Take note of the name of that disk’s directory. For example, on our system, the SD card is located in the directory: /dev/sdg.

5. Use the cd command (“change directory”) to navigate to the directory where you saved your Raspbian Wheezy distribution.

For example, if it’s in the Documents directory, type cd Documents and press Enter.

6. Display the name of your Raspbian Wheezy image file by typing ls *.img.

7. To write the Raspbian Wheezy image to the SD card, use the dd command.

Here’s what we would type on our system:

sudo dd if=mydistribution.img of=/dev/sdc bs=2M

You need to substitute the name of your distribution file where it says mydistribution.img. Substitute the directory where your SD card is located where it says /dev/sdc.

The sudo command stands for “super user do” and tells Linux that you’re issuing the dd command as the administrator of the system. The operating system assumes you know exactly what you’re doing, and there are no protections for making any grave mistakes. The dd command is short for “data description,” but some people have joked that it stands for “destroy disk” or “delete data,” because if you aren’t careful, it can erase your system’s hard drive. When these two commands are combined, you can imagine the consequences of making a mistake. So, be sure you’ve typed everything precisely!

8. Press Enter to start flashing the image file your SD card.

It should take about two or three minutes to do this operation. You won’t see a progress update, but you may see the light next to your SD card slot flickering. When it’s finished, you’ll be advised how much data was copied and how long the operation took to complete. Pat yourself on the back. You’re ready to fire up your Raspberry Pi!

Raspberry Pi Projects For Dummies

Подняться наверх