Pi Eyed


Continued from here.

Your Pi is now sitting in the corner of the room, blinking its lights at you and presumably working.  Shall we see if we can do something with it?

3.  Setting up the interweb

Your Pi is working and sitting on the network, waiting for you.  But where is it?  You need to know its address on your network in order to log in, but it will have booted using DHCP, so its address is known only to the Pi and the router.  You need to set up your Pi with a permanent, static IP address of your choosing, as well as a gateway address (the address of the router on the LAN side) and subnet mask.  If you are a bit unsure how to select these, Appendix A might help.

We need to edit a configuration file on the SD card in order to change the settings.  Put your SD card back into your card reader.  What you do next depends on what sort of computer you are using.

If you use Linux on your PC then it’s easy enough – go into the “/etc/network” directory  in the larger partition and edit a file called “interfaces”, as shown below, with a text editor like gedit.  Do not use a word processor such as OpenOffice or LibreOffice.

The /etc/network/interfaces file looks like this:

# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto lo

iface lo inet loopback
iface eth0 inet dhcp

Leave the lines up to “iface eth0…” alone, change that line and add 3 new ones like this:

iface eth0 inet static
address 192.168.1.5
gateway 192.168.1.254
netmask 255.255.255.0

With “address” being the IP address you want to assign your Pi,  “gateway” your gateway and the “netmask” for your home network.  Once you have changed the text and saved the file over the top of the original, safely remove the card, put it in your Pi and reboot.

Unfortunately it’s not that easy for Windows users.  Windows can’t read the Ext3 partition the “interfaces” config file resides in.  This means we have to temporarily force the Pi to use a static IP and then edit the config file on the Pi itself.  Look in the list of files on the card (the 59MB partition) for a file called “cmdline.txt”  Open it up with a text editor – Wordpad is best, do NOT use Word or any sort of word processor.  You will see this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

Make sure that line wrapping is turned off (View->Word wrap->No wrap for Wordpad) and add the text in bold at the end of the line after “rootwait” (with a space between “rootwait” and “ip=192…”:

... rootwait ip=192.168.1.5::192.168.1.254:255.255.255.0::eth0:none

That’s your desired IP for your Pi, two colons, the gateway address, one colon, the netmask, two colons, “eth0″, colon, “none”.  Make sure that the text is all on one line with a newline at the end, and save the file over the original.  Safely remove the card, put it in your Pi and start it up.  Keep following the tutorial for now.  We’ll sort your Pi out permanently once you’ve logged on and used the text editor a bit.

4.  Logging in

Like any sane computer, the Pi uses SSH to provide an external terminal (or “shell”) in which to do your work.  It is secure because it is encrypted from log in onwards – no one can sniff your password, username or anything you type during your session.  If you use Linux on your home PC then you’ve already got a SSH client, but if you are unlucky enough to be using Windows, you’ll need to download PuTTY from here.  Start PuTTY up and enter the IP address you picked where it says “Host name (or IP address)” and click “Open”.  Linux users, start a shell and type ssh -l pi 192.168.1.5 (replace the 192… with your Pi’s IP address).  The username is “pi” and the password for it is “raspberry”.  You should see this:

Linux raspberrypi 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Type 'startx' to launch a graphical session

NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

pi@raspberrypi:~$

Hooray!  You are logged in and the world is your lobster.  From now on we’ll be typing commands to do things.  Whenever you see the line that says “pi@raspberrypi:~$” (or a variant of it), it means the Pi is waiting for you to type something in.

5.  Initial configuring

You see that bit where it says “NOTICE: the software on this Raspberry Pi has not been fully configured. Please run ‘sudo raspi-config'”?  That’s sound advice.  Type sudo raspi-config or copy and paste the words from the login text.

ââââââââââ⤠Raspberry Pi Software Configuration Tool (raspi-config) ââââââââââââ Setup Options                                                                â
â                                                                              â
â    1 Expand Filesystem              Ensures that all of the SD card s        â
â    2 Change User Password           Change password for the default u        â
â    3 Enable Boot to Desktop         Choose whether to boot into a des        â
â    4 Internationalisation Options   Set up language and regional sett        â
â    5 Enable Camera                  Enable this Pi to work with the R        â
â    6 Add to Rastrack                Add this Pi to the online Raspber        â
â    7 Overclock                      Configure overclocking for your P        â
â    8 Advanced Options               Configure advanced settings              â
â    9 About raspi-config             Information about this configurat        â
â                                                                              â
â                                                                              â
â                     <Select>                     <Finish>                    â
â                                                                              â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ

You will see a menu pop up with loads of options.  Move the highlighted line with the up/down arrow keys and hit return to select an option.  The options in “<>”s are selectable with the tab button, so tabbing twice would take you to the “Finish” option, where you hit return to do it.

  • If your SD card is larger than 2GB then choose option 1 – “Expand Filesystem”.  This will allow you to use all the card’s memory rather than just 2GB of it.
  • Don’t bother with 2 – “Change user password”.  We’ll be getting rid of the user in a minute anyway.
  • Don’t do 3 – “Boot to desktop” either.  We are being macho and using the command line only.
  • Select 4 – “Internationalisation Options” to go to the options page to set the timezone and “locale” (which sets various preferences like number format, date-time format) to your country.  “Timezone” is fairly straightforward, but “locale” is less so.  It offers you a list of baffling lines of text, which is comprised of  language_territory.codeset with abbreviations for “language” and “territory”.  If you are in the UK then “en_GB.UTF-8 UTF-8″ is the one you want.  When you find the one you want, hit the space bar to star it and then tab a couple of times to the “OK” button.
  • 7 – Overclock: This setting allows you to speed up your pi by tweaking the clock speed and voltage of the CPU.  Higher values mean your Pi runs faster, but too high a value could make it unstable.  Experiment a bit with it and if you find you have problems, lower the settings until it’s happy.

There are a couple of things in 8 – “Advanced options” that we need to do, so select it and choose:

  • A3 – “Memory Split”: RAM on the Pi is split between the CPU and graphics chip (GPU).  As it’s not plugged into the TV you don’t need graphics.  Choose this option and enter a number for how much memory the GPU should have.  The number to use is 16, which is the minimum memory you can assign for the GPU.
  • A4 – “SSH”: Make sure that this is set to “Enable”.  Otherwise you won’t be able to log in again.

Once you’ve finished with the config program, press Tab twice to highlight “Finish” and hit return.  You can reboot your Pi when prompted or drop back to the command line (“pi@raspberrypi ~ $”) and type sudo reboot to do it manually.  Leave it for a couple of minutes and then log in again (pi/raspberry).  As a quick check to see if your Pi is now using the whole SD card, type df -h

naich@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  3.4G   72M  98% /
/dev/root       3.6G  3.4G   72M  98% /
tmpfs            22M  208K   22M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            44M     0   44M   0% /tmp
tmpfs            10M     0   10M   0% /dev
tmpfs            44M     0   44M   0% /run/shm
/dev/mmcblk0p1   56M   34M   23M  61% /boot
naich@raspberrypi ~ $

Look at the line that starts “rootfs”.  The “Size” column should report something close to the size of your card – in this case it’s a 4GB card.  If it still says it’s under 2GB then the resizing didn’t work.  You could try resizing it with the configuration program again (sudo raspi-config) or use this tutorial.

If you are familiar with Linux on the command line you can stop reading my wibblings now.  You have, for all intents and purposes, installed Debian Wheezy on your Pi.  Go forth and do with it what you will.  The rest of you can read on while we do some basic maintenance and then add some USB storage, install a Bittorrent client to download your perfectly legal torrents and a uPNP Media Server to watch them on your TV, PS3 or whatever.

Continued here…


8 Responses to “Pi Eyed”

  1. garyaj says:

    Thanks for a really useful tutorial. I had to work around a couple of differences for my setup.

    I received my RPi today along with a 4GB SD card pre-loaded with Debian Wheezy. I attempted to follow along with the tutorial (finally found a use for the SD card slot in my MacBook Air) but when I put the SD back into the RPi and booted, neither ssh nor ping could find the IP address I had typed into ‘interfaces’ as the static address.

    So I resorted to (shock! horror!) connecting the HDMI to my TV and adding a keyboard. Somehow ‘/etc/network/interfaces’ had reverted to the ‘dhcp’ version. Not sure how. I editted the ‘interfaces’ file once again and saved it (and checked it once again to see it hadn’t reverted). Then I typed ‘ifconfig eth0′ and noted the MAC address, typed that into my DHCP server along with the static IP address I wanted and rebooted and verified via ifconfig that the pi now had the static IP address I wanted. Yes it does and I can now access the pi via ssh.

  2. garyaj says:

    I managed to stuff my SD card by pulling the power plug before running ‘sudo halt’ so I had to install the wheezy image on my SD card exactly as indicated in this tutorial.

    Curiously, I was able to log in with ssh from bootup so I am doubly happy with this tutorial. However one minor issue. When running ‘raspi-config’ check that ssh is enabled. I had to re-install the SD image twice because after rebooting the first time, I hadn’t checked ssh was enabled and somehow it was disabled (by default?) and it was less hassle to rewrite the SD card than to move my RPi into the telly room and kick the kids out etc.

  3. Naich says:

    Thanks for that. I’ve added a note to the tutorial.

  4. Naich says:

    Added some wibble about the new overclock option in raspi-config.

  5. Naich says:

    Updated the text for slight changes to raspi-config.

  6. Naich says:

    Updated rasp-config again. They keep changing it.

  7. Bharat says:

    Hi Naich, I’ve been reading your blog a lot and thought probably you’re the right person to seek help. I’ve googled this topic a million times by now but, no solution so far. I’ve been using Pi with transmission-daemon in it. Basically, I use my Pi only for downloading from torrents. Recently, since about a week or 2, I’ve been facing this issue. I get this error transmission’s web interface – “Input/Output Error”. This error stops my download and have to resume my download from beginning. NOw-a-days, I’ve been getting error every time I try to download sometime off Torrents. I basically can’t download anything using my Pi and my Pi’s is just lying in my house for nothing!
    Can you please help with something?

    • Naich says:

      You are getting that error because the system cannot write to the SD card, memory stick or whatever you are saving the file to. Check that it is not getting full and if possible do an integrity test on it (although it might just be quicker to try using a different memory stick/card).