Getting Started with Python for the Internet of Things
上QQ阅读APP看书,第一时间看更新

Preparing an SD card manually

An alternative to using NOOBS is to manually write the operating system image to the SD card. While this was originally the only way to install the operating system, some users still prefer it. It allows the SD cards to be prepared before they are used in Raspberry Pi. It can also provide easier access to startup and configuration files, and it leaves more space available for the user (unlike NOOBS, a RECOVERY partition isn't included).

The default Raspbian image actually consists of two partitions, BOOT and SYSTEM, which will fit into a 2 GB SD card (4 GB or more is recommended).

You need a computer running Windows/Mac OS X/Linux (although it is possible to use another Raspberry Pi to write your card; be prepared for a very long wait).

Download the latest version of the operating system you wish to use. For the purpose of this book, it is assumed you are using the latest version of Raspbian available at http://www.raspberrypi.org/downloads.

Perform the following steps depending on the type of computer you plan to use to write to the SD card (the .img file you need is sometimes compressed, so before you start, you will need to extract the file).

The following steps are for Windows:

  1. Ensure that you have downloaded the Raspbian image, as previously detailed, and extracted it to a convenient folder to obtain an .img file.
  2. Obtain the Win32DiskImager.exe file available at http://www.sourceforge.net/projects/win32diskimager.
  3. Run Win32DiskImager.exe from your downloaded location.
  4. Click on the folder icon and navigate to the location of the .img file and click on Save.
  5. If you haven't already done so, insert your SD card into your card reader and plug it into your computer.
  6. Select the Device drive letter that corresponds to your SD card from the small drop-down box. Double-check that this is the correct device (as the program will overwrite whatever is on the device when you write the image).
The drive letter may not be listed until you select a source image file.
  1. Finally, click on the Write button and wait for the program to write the image to the SD card, as shown in the following screenshot:
Manually writing operating system images to the SD card, using Disk Imager
  1. Once completed, you can exit the program. Your SD card is ready.

The following steps should work for the most common Linux distributions, such as Ubuntu and Debian:

  1. Using your preferred web browser, download the Raspbian image and save it in a suitable place.
  2. Extract the file from the file manager or locate the folder in the terminal and unzip the .img file with the following command:
unzip filename.zip  
  1. If you haven't already done so, insert your SD card into your card reader and plug it into your computer.
  2. Use the df -h command and identify the sdX identifier for the SD card. Each partition will be displayed as sdX1, sdX2, and so on, where X will be a, b, c, d, and so on for the device ID.
  3. Ensure that all the partitions on the SD card are unmounted using the
    umount /dev/sdXn command for each partition, where sdXn is the partition being unmounted.
  4. Write the image file to the SD card, with the following command:
sudo dd if=filename.img of=/dev/sdX bs=4M  
  1. The process will take some time to write to the SD card, returning to the Terminal prompt when complete.
  2. Unmount the SD card before removing it from the computer, using the following command:
umount /dev/sdX1  

The following steps should work for most of the versions of OS X:

  1. Using your preferred web browser, download the Raspbian image and save it somewhere suitable.
  2. Extract the file from the file manager or locate the folder in the terminal and unzip the .img file, with the following command:
unzip filename.zip  
  1. If you haven't already done so, insert your SD card into your card reader and plug it into your computer.

 

  1. Use the diskutil list command and identify the disk# identifier for the SD card. Each partition will be displayed as disk#s1, disk#s2, and so on, where # will be 1, 2, 3, 4, and so on, for the device ID.
If rdisk# is listed, use this for faster writing (this uses a raw path and skips data buffering).
  1. Ensure that the SD card is unmounted using the unmountdisk /dev/diskX command, where diskX is the device being unmounted.
  2. Write the image file to the SD card, with the following command:
sudo dd if=filename.img of=/dev/diskX bs=1M  
  1. The process will take some time to write to the SD card, returning to the Terminal prompt when complete.
  2. Unmount the SD card before removing it from the computer, using the
    following command:
unmountdisk /dev/diskX  

Refer to the following diagram:

The boot process of a manually installed OS image