6/11/2012

Slicing into the Raspberry Pi

Slicing into the Raspberry Pi

NOTE: There is a new default operating system for the Raspberry Pi. The following post, assumes that you are using the original Debian image for the SD card image of your operating system. To learn more, please see my post Raspbian Optimizes Raspberry Pi.

After having my Raspberry Pi for a few days, I thought I'd write about a few steps to get up and running quickly. To avoid one problem, be sure you start with a SDcard of at least 4GB. I was able to get a 2GB card to work, but quickly ran out of space before I could get many applications installed on it.

Preparing the SDcard with the Debian Sqeeze image for the Raspberry Pi

Download the Debian Squeeze Image from the downloads section of RaspberryPi.org on to your desktop or laptop computer running Linux.
  • Access the root account of the system (or use a prefix of sudo for the following commands).
    • $ sudo su - # or su - on systems without disabled root accounts
  • Insert a SDcard and check for the device by using:
    • # fdisk -l
  • Wipe the card to remove any boot or partition information from it:
    • # dd if=/dev/zero of=/dev/sdX bs=1M count=10 #replace X with letter corresponding to the name of last device detected
  • Extract the debian image from the zip file:
    • # unzip debian6-19-04-2012.zip
  • Verify the image file against the provided SHA1 sum file:
    • # sha1sum debian6-19-04-2012/debian6-19-04-2012.img
    • # cat debian6-19-04-2012/debian6-19-04-2012.img.sha1 # make sure they match
  • Copy the image to the sdcard sdX where X is the card detected above:
    • # dd if=debian6-19-04-2012/debian6-19-04-2012.img of=/dev/sdX bs=1M
  • Verify that the image made 3 partitions on the sdcard device:
    • # fdisk -l 
The output should look something like below except the size of the disk may vary:

Disk /dev/sdX: 1967 MB, 1967128576 bytes
4 heads, 32 sectors/track, 30016 cylinders, total 3842048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ee283


   Device Boot      Start         End      Blocks   Id  System
/dev/sdX1            2048      155647       76800    c  W95 FAT32 (LBA)
/dev/sdX2          157696     3414015     1628160   83  Linux
/dev/sdX3         3416064     3807231      195584   82  Linux swap / Solaris
  • If your SDcard is larger than 2Gb, then you can expand the file system now, as described in my post A bigger slice of Raspberry Pi
  • There is enough space on the 2Gb image to be able to use the system, update it, and add a FEW applications or data files, and the file system can be expanded later.
  • Make sure all data has been written after the following command completes, and the SDcard can be removed from the computer:
    • # sync

First Time Booting

  1. Place a SDcard prepared from the above steps into the Raspberry Pi.
  2. Connect the HDMI or RCA  cable to the R Pi and the video output device
  3. Connect the Ethernet cable to a network with a DHCP server (altern
  4. Either use an USB hub which is powered (active) or use low powered keyboard and mouse to connect the keyboard and mouse to the R Pi
  5. Connect the power.
Make all your connections and the system should boot (and the first time reboot). Remember to have the SD card in the R Pi before connecting the power or it will not boot.

If there are no lights on the R Pi, then you have a power issue.

If the image on the SDcard is defective, or the R Pi is unable to read the SDcard, there will only be a red power indicator light on the R Pi and no video output.

When I made my very first attempt to boot my R Pi, there was only a red light, and no blinking green light. It was after I took the step above, "Wipe the card to remove any boot or partition information from it", that my image worked. 

During the very first boot, things look bad. Numerous failed messages appear to indicate a problem.

Once the system reports, "Welcome to Raspberry Pi - one-off initialization you have successfully booted. At this point the system will appear to be hanging. Be patient, and it will reboot.

After it reboots, there should not be any error messages and you should eventually be seeing the login prompt. If there are warnings about mmc0, then your card is having problems, but it may still work. 

  • To login on this Raspberry Pi image of Debian Squeeze use a 
    • username: pi
    • password raspberry

For security reasons, change the password, remember it, or make note of it somehow. After you change the password, you will be able to login as the pi user with the new password instead of "raspberry", and it is what you should type whenever sudo prompts you for a password.

  • Change your password to be secure:
    • pi@raspberrypi: ~$ passwd
    • (current) UNIX password: raspberry # This will be yournewpassword after your change it
    • Enter new UNIX password: yournewpassword # This should be "yournewpassword" 
    • Retype new UNIX password: yournewpasssword # Replace "yournewpassword" with your password 
These steps assume the R Pi is attached to a network with a DHCP server and an Internet connection.
  • Check for updates:
    • pi@raspberrypi: ~$ sudo apt-get update
  • Apply updates:
    • pi@raspberrypi: ~$ sudo apt-get upgrade
  • To set the correct timezone information:
    • pi@raspberrypi: ~$ sudo apt-get install tzdata
    • pi@raspberrypi: ~$ sudo dpkg-reconfigure tzdata
    • or pi@raspberrypi: ~$ sudo tzselect  
  • To configure the keyboard for the text terminal:
    • pi@raspberrypi: ~$ sudo apt-get install console-data
    • to reconfigure pi@raspberrypi: ~$ sudo dpkg-reconfigure console-data
    • to permanently configure: update the settings in /etc/default/keyboaard
Choose the correct keyboard layout by going to the full list. 
I chose PC / Querty / US american / Standard / Standard because I live in the United States of America, but you should choose the keyboard according to where you live and what type of keyboard you are using.
  • Reboot the system:
    • pi@raspberrypi: ~$ sudo reboot
  • If you want to shut down the system safely:
    • pi@raspberrypi: ~$ sudo halt
Wait until the system prints to the screen: System halted. 
Then, safely remove the power to the device.

After the first boot has been completed, and the system has been updated, you should now also be able to login to the R Pi via SSH.

First Time Using X Windows GUI

Boot up the system and login as pi with yournewpassword

If you are using a keyboard model and layout different from Great Britain (GB), then the keyboard will not be correctly configured when you start the GUI. To prevent this problem, add something like the following to the /home/pi/.bashrc file. Those settings are based upon a typical United States (US) keyboard and layout.

  • Change this user's keyboard settings for X Windows
    •  pi@raspberrypi: ~$ echo 'setxkbdmap -model pc104 -layout us' >> ~/.bashrc
  • To begin a session with the GUI type:
    • pi@raspberrypi: ~$ startx

Where next?

To expand the space on the SD card, and enable swap, read: A bigger slice of Raspberry Pi.
If you want to try out other distributions besides Debian on the Raspberry Pi, then please read: How the Raspberry Pi Spins. To get sound a video working under Debian, check out the newest post: Getting Sound and Video to Work on the Raspberry Pi. For managing your software, this cheat sheet on Debian Linux is very helpful. Don't forget about Keeping your Raspberry Pi Fresh.

If you are interested in programming on the Raspberry Pi, I highly recommend Python. I have also published a series of posts with the byline of Python on the Raspberry Pi:


Please comment with your own experiences, or questions. In real life, I actually teach both Linux and Python!

No comments:

About Me - WrightRocket

My photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.