Difference between revisions of "RPi Easy SD Card Setup"

From eLinux.org
Jump to: navigation, search
(Copying an image to the SD Card in Mac OS X: Fixing bolding on two command prompt lines, by changing ‘’’ -> ''')
(Updating bs=1M to bs=4M in the linux instructions as it will work in most cases and is way faster.)
(5 intermediate revisions by 3 users not shown)
Line 10: Line 10:
  
 
=Safest/Laziest way=
 
=Safest/Laziest way=
Buy a preloaded card from RS Components, element14 or [http://thepihut.com/ The Pi Hut]
+
Buy a preloaded card from RS Components, element14 or [http://thepihut.com/ The Pi Hut's Raspberry Pi Store]
  
 
=Easiest way=
 
=Easiest way=
Line 117: Line 117:
 
#* http://www.raspberrypi.org/downloads
 
#* http://www.raspberrypi.org/downloads
 
# Verify if the the hash key of the zip file is the same as shown on the downloads page (optional). Assuming that you put the zip file in your home directory (~/), in the terminal run:  
 
# Verify if the the hash key of the zip file is the same as shown on the downloads page (optional). Assuming that you put the zip file in your home directory (~/), in the terminal run:  
#* '''sha1sum ~/debian6-19-04-2012.zip'''
+
#* '''sha1sum ~/2012-09-18-wheezy-raspbian.zip'''
 
#* This will print out a long hex number which should match the "SHA-1" line for the SD image you have downloaded
 
#* This will print out a long hex number which should match the "SHA-1" line for the SD image you have downloaded
 
# Extract the image, with
 
# Extract the image, with
#* '''unzip ~/debian6-19-04-2012.zip'''
+
#* '''unzip ~/2012-09-18-wheezy-raspbian.zip'''
 
# Run '''df -h''' to see what devices are currently mounted
 
# Run '''df -h''' to see what devices are currently mounted
 
# If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer.
 
# If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer.
Line 128: Line 128:
 
#* If your SD card shows up more than once in the output of df due to having multiple partitions on the SD card, you should unmount all of these partitions.
 
#* If your SD card shows up more than once in the output of df due to having multiple partitions on the SD card, you should unmount all of these partitions.
 
# In the terminal write the image to the card with this command, making sure you replace the input file '''if=''' argument with the path to your .img file, and the "/dev/sdd" in the output file '''of=''' argument with the right device name ('''this is very important:''' you '''will''' lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1)
 
# In the terminal write the image to the card with this command, making sure you replace the input file '''if=''' argument with the path to your .img file, and the "/dev/sdd" in the output file '''of=''' argument with the right device name ('''this is very important:''' you '''will''' lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1)
#* '''dd bs=1M if=~/debian6-19-04-2012/debian6-19-04-2012.img of=/dev/sdd'''
+
#* '''dd bs=4M if=~/2012-09-18-wheezy-raspbian.img of=/dev/sdd'''
 +
#** Please note that block size set to 4M will work most of the time, if not, please try 1M, although 1M will take considerably longer.
 
#* Note that if you are not logged in as root you will need to prefix this with '''sudo '''
 
#* Note that if you are not logged in as root you will need to prefix this with '''sudo '''
 
#* The dd command does not give any information of its progress and so may appear to have frozen. It could take more than five minutes to finish writing to the card. If your card reader has an LED it may blink during the write process, or you can run '''pkill -USR1 -n -x dd''' in another terminal (prefixed with '''sudo''' if you are not logged in as root).
 
#* The dd command does not give any information of its progress and so may appear to have frozen. It could take more than five minutes to finish writing to the card. If your card reader has an LED it may blink during the write process, or you can run '''pkill -USR1 -n -x dd''' in another terminal (prefixed with '''sudo''' if you are not logged in as root).
 +
# Instead of dd you can use dcfldd; it will give a progress report about how much has been written.
 +
# You can check what's written to the SD card by dd-ing from the card back to your harddisk to another image, and then running diff (or md5sum) on those two images. There should be no difference.
 
# As root run the command '''sync''' or if a normal user run '''sudo sync''' (this will ensure the write cache is flushed and that it is safe to unmount your SD card)
 
# As root run the command '''sync''' or if a normal user run '''sudo sync''' (this will ensure the write cache is flushed and that it is safe to unmount your SD card)
 
# Remove SD card from card reader, insert it in the Raspberry Pi, and have fun
 
# Remove SD card from card reader, insert it in the Raspberry Pi, and have fun

Revision as of 04:30, 25 September 2012


RaspPi.png Back to the Hub


Getting Started:

Buying Guide - for advice on buying the Raspberry Pi.

SD Card Setup - for information on how to prepare the SD Card used to boot your Raspberry Pi.

Basic Setup - for help with buying / selecting other hardware and setting it up.

Beginners Guide - you are up and running, now what can you do?

Latest RPi 4 Topics - Recent topics on Raspberry Pi 4 and the Pi OS

Advanced Setup - for more extensive information on setting up.

Trouble Shooting - some things to check if things don't work as expected.

SD Card setup

To boot the Raspberry Pi, you need an SD card installed with a bootloader and a suitable Operating System. Some Raspberry Pi kits will come with a ready-to-go card, but if you didn't receive one you will need to prepare your own:

Official images are available from http://www.raspberrypi.org/downloads and there is an overview of available distributions here.

Warning! When you write the Raspberry Pi image to your SD card you will lose all data that was on the card.

Safest/Laziest way

Buy a preloaded card from RS Components, element14 or The Pi Hut's Raspberry Pi Store

Easiest way

  • Use an installer program. The Fedora ARM Installer will download and install Raspberry Pi Fedora Remix images, but it will also install other images if they are already downloaded and in uncompressed or .gz format.
  • (Mac) The RasPiWrite utility is a python script which will walk you through the process of installing to SD card, it works with any Raspberry Pi compatible disk image, and can download one of the currently available distros if you don't have one.
  • If your Pi is connected to the Internet, you can use the BerryBoot installer to let it download and install the operating system. This requires that you first use a normal Windows/Mac/Linux computer to download a small .zip file with the Berryboot system files and extract it to an empty SD card. Then you put the SD card in your Pi, and follow the on-screen prompts to complete the installation. An additional advantage is that Berryboot allows you to install more than one operating system on a single SD card.

Easy way

To write your SD card you start by downloading the SD image (the data you will write to the card). The best way to do this is using BitTorrent. This generally results in a faster download as it is a highly distributed system (you will be downloading the data from users who have previously downloaded it).

This guide assumes you have downloaded the Debian "squeeze" image, with name debian6-13-04-2012. Obviously, if you are downloading a different or newer version, use the name of the version you have downloaded.

Copying the image to an SD Card on Windows

  1. Download the image from a mirror or torrent. The remainder of this assumes you are using the Raspbian “wheezy” download 2012-07-15-wheezy-raspbian.zip
  2. Extract the image file 2012-07-15-wheezy-raspbian.img from the downloaded .zip file.
  3. Insert the SD card into your SD card reader and check what drive letter it was assigned. You can easily see the drive letter (for example G:) by looking in the left column of Windows Explorer. If the card is not new, you should format it; otherwise Win32DiskImager may hang.
  4. Download the Win32DiskImager utility. The download links are on the right hand side of the page, you want the binary zip.
  5. Extract the executable from the zip file and run the Win32DiskImager utility. You may need to run the utility as Administrator.
  6. Select the 2012-07-15-wheezy-raspbian.img image file you extracted earlier
  7. Select the drive letter of the SD card in the device box. Be careful to select the correct drive; if you get the wrong one you can destroy your computer's hard disk!
  8. Click Write and wait for the write to complete.
  9. Exit the imager and eject the SD card.
  10. Insert the card in the Raspberry Pi, power it on, and it should boot up. There is an option in the configure script that comes up to expand the partitions to use all of the SD card if you have used one larger than 4 GB

In Windows the SD card will appear only to have a fairly small size - about 75 Mbytes. This is because most of the card has a partition that is formatted for the Linux operating system that the RPi uses and is not visible in Windows.

Copying the image to an SD Card on Windows if first option isn't successful

I wasn't able to choose device in Win32DiskImager on my notebook so I found a different way to achieve the same thing on windows machine..

  1. Download the image from a mirror or torrent
  2. Extract the image file debian6-19-04-2012.img from the debian6-19-04-2012 directory in the debian6-19-04-2012.zip
  3. Insert the SD card into your SD card reader and check what drive letter it was assigned. You can easily see the drive letter (for example H:) by looking in the left column of Windows Explorer.
  4. Download flashnul software from http://shounen.ru/soft/flashnul/ here is Translated version
    • Download the latest version at the time of writing it was flashnul-1rc1.
    • Download and Extract the application from archive.
    • Click Start button > All Programs > Accessories > Command Prompt, right click on it and Run as Administrator.
    • Run the flashnul with argument:
C:/flashnul/flashnul.exe -p
    • Flashnul will tell you something like:
Avaible physical drives:
0       size = 250059350016 (232 Gb)
1       size = 1990197248 (1898 Mb)

Avaible logical disks:
C:\
D:\
F:\
G:\
H:\

Press ENTER to exit.

SDCARD number is on left! In my case it is number 1

    • Now we will use Load argument:
C:/flashnul/flashnul.exe 1 -L C:/debian6/debian6-19-04-2012.img

where <Path to flashnul directory>flashnul.exe <device number> -L <img file path>

    • Flashnul will give you a device summary and proceed caution, have a quick scan through the information to make sure you have selected the correct device, then type yes and press enter.
    • If you get a access denied error, try re-plugging the SD card. Also make sure to close all explorer windows or folders open for the device.
    • If you still get a access denied error, try substitute the device number with the drive letter followed by a colon. Eg:
C:/flashnul/flashnul.exe H: -L C:/debian6/debian6-19-04-2012.img
  • If the device summary does not match Your card (the size is smaller, e.g. 75MB), but you are sure, that the letter is correct - please continue and then try again with the device number.

Copying an image to the SD Card in Mac OS X

Note: Some users have reported issues with using OSX to create SD Cards.

  1. These commands and actions need to be performed from an account that has administrator privileges.
  2. Download the image from a mirror or torrent
  3. Verify if the the hash key is the same (optional), in the terminal run:
    • shasum ~/Downloads/debian6-19-04-2012.zip
  4. Extract the image:
    • unzip ~/Downloads/debian6-19-04-2012.zip
    • (or: just double click the zip, it will extract automatically)
  5. From the terminal run df -h
  6. Connect the sdcard reader with the sdcard inside
  7. Run df -h again and look for the new device that wasn't listed last time. Record the device name of the filesystem's partition, e.g. /dev/disk3s1
  8. Unmount the partition so that you will be allowed to overwrite the disk:
    • sudo diskutil unmount /dev/disk3s1
    • (or: open Disk Utility and unmount the partition of the sdcard (do not eject it, or you have to reconnect it)
  9. Using the device name of the partition work out the raw device name for the entire disk, by omitting the final "s1" and replacing "disk" with "rdisk" (this is very important: you will lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, rdisk3, not rdisk3s1. Similarly you might have another SD drive name/number like rdisk2 or rdisk4, etc. -- recheck by using the df -h command both before & after you insert your SD card reader into your Mac if you have any doubts!):
    • e.g. /dev/disk3s1 => /dev/rdisk3
  10. In the terminal write the image to the card with this command, using the raw disk device name from above (read carefully the above step, to be sure you use the correct rdisk# here!):
    • sudo dd bs=1m if=~/Downloads/debian6-19-04-2012/debian6-19-04-2012.img of=/dev/rdisk3
    • if the above command report an error(dd: bs: illegal numeric value), please change bs=1M to bs=1m
    • (note that dd will not feedback any information until there is an error or it is finished, information will show and disk will re-mount when complete. However if you are curious as to the progresss - ctrl-T (SIGINFO, the status argument of your tty) will display some en-route statistics).
  11. After the dd command finishes, eject the card:
    • sudo diskutil eject /dev/rdisk3
    • (or: open Disk Utility and eject the sdcard)
  12. Insert it in the raspberry pi, and have fun

Copying an image to the SD Card in Linux (command line)

Please note that the use of the "dd" tool can overwrite any partition of your machine. If you specify the wrong device in the instructions below you could delete your primary Linux partition. Please be careful.

  1. Download the zip file containing the image from a mirror or torrent
  2. Verify if the the hash key of the zip file is the same as shown on the downloads page (optional). Assuming that you put the zip file in your home directory (~/), in the terminal run:
    • sha1sum ~/2012-09-18-wheezy-raspbian.zip
    • This will print out a long hex number which should match the "SHA-1" line for the SD image you have downloaded
  3. Extract the image, with
    • unzip ~/2012-09-18-wheezy-raspbian.zip
  4. Run df -h to see what devices are currently mounted
  5. If your computer has a slot for SD cards, insert the card. If not, insert the card into an SD card reader, then connect the reader to your computer.
  6. Run df -h again. The device that wasn't there last time is your SD card. The left column gives the device name of your SD card. It will be listed as something like "/dev/mmcblk0p1" or "/dev/sdd1". The last part ("p1" or "1" respectively) is the partition number, but you want to write to the whole SD card, not just one partition, so you need to remove that part from the name (getting for example "/dev/mmcblk0" or "/dev/sdd") as the device for the whole SD card. Note that the SD card can show up more than once in the output of df: in fact it will if you have previously written a Raspberry Pi image to this SD card, because the RPi SD images have more than one partition.
  7. Now that you've noted what the device name is, you need to unmount it so that files can't be read or written to the SD card while you are copying over the SD image. So run the command below, replacing "/dev/sdd1" with whatever your SD card's device name is (including the partition number)
    • umount /dev/sdd1
    • If your SD card shows up more than once in the output of df due to having multiple partitions on the SD card, you should unmount all of these partitions.
  8. In the terminal write the image to the card with this command, making sure you replace the input file if= argument with the path to your .img file, and the "/dev/sdd" in the output file of= argument with the right device name (this is very important: you will lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1)
    • dd bs=4M if=~/2012-09-18-wheezy-raspbian.img of=/dev/sdd
      • Please note that block size set to 4M will work most of the time, if not, please try 1M, although 1M will take considerably longer.
    • Note that if you are not logged in as root you will need to prefix this with sudo
    • The dd command does not give any information of its progress and so may appear to have frozen. It could take more than five minutes to finish writing to the card. If your card reader has an LED it may blink during the write process, or you can run pkill -USR1 -n -x dd in another terminal (prefixed with sudo if you are not logged in as root).
  9. Instead of dd you can use dcfldd; it will give a progress report about how much has been written.
  10. You can check what's written to the SD card by dd-ing from the card back to your harddisk to another image, and then running diff (or md5sum) on those two images. There should be no difference.
  11. As root run the command sync or if a normal user run sudo sync (this will ensure the write cache is flushed and that it is safe to unmount your SD card)
  12. Remove SD card from card reader, insert it in the Raspberry Pi, and have fun

Copying an image to the SD Card in Linux (graphical interface)

If you are using Ubuntu and hesitate to use the terminal, you can use the ImageWriter tool (nice graphical user interface) to write the .img file to the SD card.

  1. Download the zip file containing the image from a mirror or torrent
  2. Right click the zip file and select "Extract here"
    • ATTENTION: As of this writing (15 June 2012), there is a bug in the ImageWriter program that causes it to fail if the filename of the image file or its path (i.e. all the names of any parent folders that you extract the image file into) contain any space characters. Before going any further, ensure that neither the file name of the image you're using or the path contain any spaces (or other odd characters, for that matter). A bug has been opened for this issue: https://bugs.launchpad.net/usb-imagewriter/+bug/1013834 Once the issue is fixed, edit this page to advise people to use an updated/patched version of ImageWriter.
  3. Insert the SD card into your computer or connect the SD card reader with the SD card inside
  4. Install the ImageWriter tool from the Ubuntu Software Center
  5. Launch the ImageWriter tool (it needs your administrative password)
  6. Select the image file (example debian6-19-04-2012.img) to be written to the SD card (note: because you started ImageWriter as administrator the starting point when selecting the image file is the administrator's home folder so you need to change to your own home folder to select the image file)
  7. Select the target device to write the image to (your device will be something like "/dev/mmcblk0" or "/dev/sdc")
  8. Click the "Write to device" button
  9. Wait for the process to finish and then insert the SD card in the Raspberry Pi

Manually resizing the SD card partitions (Optional)

The SD card image is sized for a 2GB card. The Fedora Remix will automatically resize the partitions on the card during the first boot. The Debian version won't, so you'll have to do it manually. It's much easier if you do this on another machine, as the SD card can't be mounted when you do this.

Look here for instructions.

Adding a data partition (Optional)

If you would rather not resize the partition on another machine as described above, either because you do not have another working Linux machine or you wish to keep your data on another partition to your operating system, you can instead create a new data partition and have that mount automatically at boot.

  • First you need to become root and install parted (I did all of this from the boot command prompt, although if you feel safer in a GUI, you can do all of this in a terminal window):
sudo su -
apt-get install parted
  • Then you need to run parted on your SD card, mine is /dev/mmcblk0, ymmv:
parted /dev/mmcblk0
  • Once running, set the display units to something usable and then print your partition table
unit chs
print
  • You should see something like this:
Model: SD SD08G (sd/mmc)
Disk /dev/mmcblk0: 121279,3,31
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 121280,4,32.  Each cylinder is 65.5kB.
Partition Table: msdos
Number  Start      End         Type     File system     Flags
 1      16,0,0     1215,3,31   primary  fat32           lba
 2      1232,0,0   26671,3,31  primary  ext4
 3      26688,0,0  29743,3,31  primary  linux-swap(v1)
  • Now you need to create your data partition - you need to choose one more than the end of partition 3 with ,0,0 as your start and use the number from the line that starts with Disk as your end:
mkpart primary 29744,0,0 121279,3,31
print
  • That should show your new partition:
Number  Start      End          Type      File system     Flags
 1      16,0,0     1215,3,31    primary   fat32           lba
 2      1232,0,0   26671,3,31   primary   ext4
 3      26688,0,0  29743,3,31   primary   linux-swap(v1)
 4      29744,0,0  121279,3,31  primary
  • Now quit and format the partition (again, ymmv with the specific device name, try ls /dev for some clues), and then label it:
quit
mkfs.ext4 /dev/mmcblk0p4
e2label /dev/mmcblk0p4 data
  • Now we need to make sure that the partition is mounted automatically when the system boots (maybe don't use vi if you never have before, try nano):
vi /etc/fstab
  • Enter a line exactly like this at the end of the file and save and quit your text editor:
/dev/mmcblk0p4  /data           ext4    defaults        1       2
  • Create the mount point:
mkdir /data
  • Now mount the partition:
mount /data
cd /data
ls

Your new partition has been created!

References