RPi Advanced Setup

From eLinux.org
Revision as of 09:10, 4 March 2012 by Rockhawk (talk | contribs) (Finding hardware and setting up)
Jump to: navigation, search

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.


WARNING: This page is not suitable for the average user. Information in this page is for experienced hackers only. The Raspberry Pi foundation will release pre-built SD cards which are suitable for use by the average user.

Please note that the Raspberry Pi isn't released yet - this page is a community work in progress in preparation for the launch. If something doesn't work or isn't covered in these guides, please feel free to ask on the Forum. But before you ask there, make sure you read the FAQs.

This page is based on BeagleBoardBeginners and lots of this material applies to BeagleBoard and not to Raspberry Pi. Specifically, most Raspberry Pi users do not have access to a serial port (it's on the GPIOs but you need a board or cable to convert 3.3V UART signals to RS-232 or USB) so the serial port information doesn't usually apply. Also, many Raspberry Pi users will buy pre-programmed SD cards and can skip to reading RPi Hardware Basic Setup. We expect that once Raspberry Pi boards become generally available helpful volunteers will update this page to match Raspberry Pi or point to better information elsewhere.

This page in a major work in progress!

Finding hardware and setting up

Main article: see RPi Hardware Basic Setup

You'll need to copy an image to a suitable SD card (or make your own image). You'll also need a USB keyboard, TV/Monitor (with HDMI/DVI/Composite/SCART input), and power supply (USB charger or a USB port from a powered USB Hub or another computer).

You'll likely also want a USB mouse, a case, and a USB Hub (a necessity for Model A). A powered USB Hub will reduce the demand on the RPi. To connect to the Internet, you'll need either an Ethernet/LAN cable (Model B) or a USB WiFi adaptor (either model). See RPi VerifiedPeripherals for more information on supported peripherals.

When setting up, it is advisable to connect the power after everything else is ready. See RPi_Hardware_Basic_Setup#Connecting_Together.

SD card setup

To boot the Raspberry Pi, you need an SD card installed with a bootloader provided by the foundation, and a suitable Operating System.

Official images are available from http://www.raspberrypi.org/downloads. This guide assumes you have downloaded the Debian "squeeze" image.

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

Copying the image to an SD Card on Windows

  1. Extract the image file debian6-17-02-2012.img from the debian6-17-02-2012 directory in the debian6-17-02-2012.zip
  2. Insert the SD card into your SD card reader and check what drive letter it was assigned.
  3. Download the Win32DiskImager utility. The download links are on the right hand side of the page, you want the binary zip.
  4. Extract the zip file and run the Win32DiskImager utility.
  5. Select the debian6-17-02-2012.img image file you extracted earlier
  6. Select the drive letter of the SD card in the device box. Be careful to select the correct drive.
  7. Click Write and wait for the write to complete.
  8. Exit the imager and eject the SD card.
  9. Insert the card in the Raspberry Pi, power it on, and it should boot up. Have fun!

Copying an image to the SD Card in Max OS

  1. Download the image from a mirror or torrent
  2. Verify if the the hash key is the same (optional), in the terminal run:
    • shasum ~/Downloads/debian6-17-02-2012.zip
  3. Extract the image, just double click the zip, it will extract automatically
  4. From the terminal run df -h
  5. Connect the sdcard reader with the sdcard inside
  6. Run df -h again and look for the new device that wasn't listed last time. Record the filesystem name of the device, e.g. /dev/disk1s1
  7. Open disk utility and unmount the partition of the sdcard (do not eject it, or you have to reconnect it)
  8. In the terminal write the image to the card with this command, making sure you replace "/dev/disk1" with the right device name from before (missing out the final "s1".
    • dd bs=1m if=~/Downloads/debian6-17-02-2012/debian6-17-02-2012.img of=/dev/disk1
  9. After the dd comand finishes go to disk utility and eject the sdcard
  10. Insert it in the raspberry pi, and have fun

Copying an image to the SD Card in Linux

  1. Download the image from a mirror or torrent
  2. Verify if the the hash key is the same (optional), in the terminal run:
    • shasum ~/debian6-17-02-2012.zip
  3. Extract the image, with
    • unzip ~/debian6-17-02-2012.zip
  4. Connect the sdcard reader with the sdcard inside
  5. Check the name of the device that the SD card was mounted as by running: dmesg | tail, it will be something like "/dev/sdc"
  6. In the terminal write the image to the card with this command, making sure you replace "/dev/sdc" with the right device name.
    • dd bs=1M if=~/debian6-17-02-2012/debian6-17-02-2012.img of=/dev/sdc
  7. Insert it in the raspberry pi, and have fun

Serial connection

For help setting up a serial connection with the Raspberry Pi, see RPi_Serial_Connection.

Advanced SD card setup

Now we want to use an SD card to install some GNU/Linux distro in it and get more space for our stuff. You can use either an SD or SDHC card. In the latter case of course take care that your PC card reader also supports SDHC. Be aware that you are not dealing with an x86 processor, but instead a completely different architecture called ARM, so don't forget to install the ARM port for the distro you are planning to use.

(to be completed)

Formatting the SD card via the mkcard.txt script

(to be completed)

  1. Download mkcard.txt from ???.
  2. $ chmod +x mkcard.txt
  3. $ ./mkcard.txt /dev/sdx, Where x is the letter of the card. You can find this by inserting your card and then running dmesg | tail. You should see the messages about the device being mounted in the log. Mine mounts as sdc.

Once run, your card should be formatted.

Formatting the SD card via fdisk "Expert mode"

First, lets clear the partition table:

$ sudo fdisk /dev/sdb

Command (m for help): o
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 

Print card info:

Command (m for help): p

Disk /dev/sdb: 128 MB, 128450560 bytes

Note card size in bytes. Needed later below.

Then go into "Expert mode":

Command (m for help): x

Now we want to set the geometry to 255 heads, 63 sectors and calculate the number of cylinders required for the particular SD/MMC card:

Expert command (m for help): h
Number of heads (1-256, default 4): 255

Expert command (m for help): s
Number of sectors (1-63, default 62): 63
Warning: setting sector offset for DOS compatiblity

NOTE: Be especially careful in the next step. First calculate the number of cylinders as follows:

  • B = Card size in bytes (you got it before, in the second step when you printed the info out)
  • C = Number of cylinders

When you get the number, you round it DOWN. Thus, if you got 108.8 you'll be using 108 cylinders.

Expert command (m for help): c
Number of cylinders (1-1048576, default 1011): 15

In this case 128MB card is used (reported as 128450560 bytes by fdisk above), thus 128450560 / 255 / 63 / 512 = 15.6 rounded down to 15 cylinders. Numbers there are 255 heads, 63 sectors, 512 bytes per sector.

So far so good, now we want to create two partitions. One for the boot image, one for our distro.

Create the FAT32 partition for booting and transferring files from Windows. Mark it as bootable.

Expert command (m for help): r
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-245, default 1): (press Enter)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-245, default 245): +50

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a
Partition number (1-4): 1

Create the Linux partition for the root file system.

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
Partition number (1-4): 2
First cylinder (52-245, default 52): (press Enter)
Using default value 52
Last cylinder or +size or +sizeM or +sizeK (52-245, default 245):(press Enter)
Using default value 245

Print and save the new partition records.

Command (m for help): p

Disk /dev/sdc: 2021 MB, 2021654528 bytes
255 heads, 63 sectors/track, 245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1          51      409626    c  W95 FAT32 (LBA)
/dev/sdc2              52         245     1558305   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot.

WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information.
Syncing disks.

Now we've got both partitions, next step is formatting them.

NOTE: If the partitions (/dev/sdc1 and /dev/sdc2) does not exist, you should unplug the card and plug it back in. Linux will now be able to detect the new partitions.

$ sudo mkfs.msdos -F 32 /dev/sdc1 -n LABEL
mkfs.msdos 2.11 (12 Mar 2005)

$ sudo mkfs.ext3 /dev/sdc2
mke2fs 1.40-WIP (14-Nov-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
195072 inodes, 389576 blocks
19478 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=402653184
12 block groups
32768 blocks per group, 32768 fragments per group
16256 inodes per group
Superblock backups stored on blocks: 
       32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: 

All done!

NOTE: For convenience, you can add the -L option to the mkfs.ext3 command to assign a volume label to the new ext3 filesystem. If you do that, the new (automatic) mount point under /media when you insert that SD card into some Linux hosts will be based on that label. If there's no label, the new mount point will most likely be a long hex string, so assigning a label makes manual mounting on the host more convenient.

Setting up the boot partition

The boot partition must contain the following files, get them from one of the official images:

  • bootcode.bin : 2nd stage bootloader, starts with SDRAM disabled
  • loader.bin : 3rd stage bootloader, starts with SDRAM enabled
  • start.elf: The GPU binary firmware image, provided by the foundation.
  • kernel.img: The OS kernel to load on the ARM processor. Normally this is Linux - see instructions for compiling a kernel.
  • cmdline.txt: Parameters passed to the kernel on boot.

Optional files:

  • config.txt: A configuration file read by the GPU. Use this to override set the video mode, alter system clock speeds, voltages, etc.
  • vlls directory: Additional GPU code, e.g. extra codecs. Not present in the initial release.

Additional files supplied by the foundation

These files are also present on the SD card images supplied by the foundation.

Additional kernels. Rename over kernel.img to use them (ensure you have a backup of the original kernel.img first!):

  • kernel_emergency.img : kernel with busybox rootfs. You can use this to repair the main linux partition using e2fsck if the linux partition gets corrupted.

Additional GPU firmware images, rename over start.elf to use them:

  • arm128_start.elf : 128M ARM, 128M GPU split (use this for heavy 3D work, possibly also required for some video decoding)
  • arm192_start.elf : 192M ARM, 64M GPU split (this is the default)
  • arm224_start.elf : 224M ARM, 32M GPU split (use this for Linux only with no 3D or video processing. Its enough for the 1080p framebuffer, but not much else)

Writing the image into the SDcard and finally booting GNU/Linux

SD Card Cloning/Backup

Note: Update these instructions if required once they've been tried

From windows you can copy the full SD-Card by using Win32DiskImager (thanks to Bradburts & Gert from the forum).

Alternatively, you can use the following instructions as provided by Gert from the forum):

Many built-in SD card readers do not work, so if you have problems
use an external SD-USB adapter for this.

Required Software Setup

(This excutable can to write to your harddisk so exercise caution using it!)

  • make a copy named dd-removable.exe

(That excutable refuses to write to your harddisk as it is named dd-removable As long as you use dd-removable.exe you can not lose your harddisk)

  • Connect an SD card to the computer
  • run "dd-removable –list"

Should give something like this:

rawwrite dd for windows version 0.6beta3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by terms of the GPL Version 2.

NT Block Device Objects
link to \\?\Device\Harddisk1\DR8
Removable media other than floppy. Block size = 512
size is 4075290624 bytes

This "\\?\Device\Harddisk1\Partition0" is the part you need.

Reading an image from the SD Card


Obviously, you can NOT use 'dd-removable' to read an image as that executable refuses to write to your harddisk (so extra care is required here as you use 'windd').

  • To read an SD-card image from the SD-card use:
windd bs=1M if=\\?\Device\Harddisk1\Partition0 of=THE_IMAGE_READ –size
Your disk name ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Copying an image to the SD Card


  • To copy an image named "THEIMAGE" to the SD-card do this:
dd-removable bs=1M if=THEIMAGE of=\\?\Device\Harddisk1\Partition0
                   Your disk name ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Software development/proving

A supported platform for the Raspberry is Qt , which is already being worked on. C/C++ is supported through a gcc cross-compiling toolchain. (Which one ?)

Python is pushed forward by the foundation. (Status ??)

After compiling , using QEMU and a Linux VM would be one way of testing your apps. This also works on Windows. Search the forum for the readymade ARM images.

The choice of programming languages, IDEs and other tools ON the R-Pi is only determined by :

1) The operating system compatibility ( at the moment the specific Linux distro used) 2) The status of the respective ARM package repositories and their binary compatibility

3) The possibilty to build other software + its dependencies for the R-Pi from sources ( depends on C crosscompiler ???)

What kind of software development and testing loop has been proven effective please, from someone who'se been there and done it?

For me (and others hopefully) that would be very useful.

Further reading

The main Raspberry Pi resources are:

An alternative startup guide for beginners can be found on h2g2: Introducing the Raspberry Pi

For more guides and projects involving the Raspberry Pi, see RPi Projects.

Thanks to

  • Nabax, _vlad, jkridner, ds2 and the other BeagleBoard wiki contributors on elinux.org for an excellent BeagleBoardBeginners resource, which we used as the template for this page.