Headless Raspberry Pi Setup (2013)

I came across a Raspberry Pi by chance (bought it off a friend at work that had an extra one).  It is a whole lot of nerdy fun for $35.  However, there was a lot of Googling involved to get it to sit up and play nice. So, I documented my setup process, in the hope that it helps someone else who can't wait to get up and running with it doing something fancy.

Disclaimer: The tutorials are your best bet.  I'm a beginner and please tell me if these steps can be improved!

Supplies

I didn't have the suggested minimum: no USB keyboard, and no 5V Micro USB power supply.  However, I didn't need them!  I plugged the Pi into a USB hub that I have hanging off the back of the Airport router, and the power was enough.  I also did the entire setup in "headless" mode, so got away without needing a keyboard or HDMI cable.
  • Raspberry Pi "B" (the one with an ethernet port)
  • Spare 8GB SD card
  • Spare Micro-USB cable and somewhere to plug it into that has "enough" power (my laptop didn't do it.  The hub did.)
  • Old Ethernet cable
  • Minijack male-to-male mini audio cable - pi to radio speaker "aux in" port

Steps

Pick and choose which steps you want to follow based on what you want to do with the pi.

Setup

  1. Download and install the "regular" wheezy disk image.   With Java 1.8 in beta for the pi, you don't need the "soft-float" version.
  2. Plug in the pi: power and ethernet.
  3. Keep your fingers crossed.
  4. Log into the router and see what IP address the pi grabbed in case you can't use "raspberrypi.local".

Updating

No one wants old crufty stuff, right?
  • ssh -l pi  raspberrypi.local (default password: raspberry) 
  • sudo raspi-config

And then in order from the little GUI
  1. update (do this first, the script has improved!)
  2. expand_rootfs
  3. change password (please something good!)
  4. change_locale (spacebar to select/unselect, english/UTF-8)
  5. change_timezone
  6. memory_split: 32 for GPU unless you are doing fun graphics things.
This is to avoid hacking and bad things, because now your rPI is unique.  Your computer SHOULD complain next time you SSH into the pi.  That is good.  Follow the directions to be able to ssh in.
  • sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server
Update everything.  Who knows what bugs have been fixed.  Best to go with latest, right?
  • wget http://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -
Now to update everything.  It is almost always safe for you to run all of the below commands, unless you rely on specific versions.
  • sudo apt-get update 
  • sudo apt-get dist-upgrade 
  • sudo apt-get autoclean 
  • sudo apt-get clean 
  • sudo apt-get autoremove

Update the Firmware

This worried me at first, but it looks like "Hexxeh" is legit and not hacking your machine.
  • sudo apt-get install ca-certificates git-core binutils
  • sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update
  • sudo cp rpi-update /usr/local/bin/rpi-update
  • sudo chmod +x /usr/local/bin/rpi-update
  • sudo rpi-update

In the future to check for updates, just execute this last step!

Basic Improvements

Make the time be the right time 
  • sudo apt-get install ntpdate
Insert time update in script - before it exits 0
  • sudo nano /etc/rc.local
  • add in: ntpdate nist1-sj.ustiming.org
Be nicer to your SD card and not log last read times.  Change the cell in the file to add ",nodiratime"
  • sudo nano /etc/fstab 
  • change it to "nodirtime" like: rw,noatime,nodiratime
See how much memory you have left with SMEM
  • hg clone http://selenic.com/repo/smem 
  • sudo ./smem -t -p -s rss -r

VNC to see the desktop without a TV attached to the HTML port

  • sudo apt-get install tightvncserver
Launch once manually to set password:
  • startx & vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565
If you are on a mac, bookmark in Safari: vnc://10.0.1.10:5901

Make VNC run every time (I don't want to do this, because rarely going to use UI)

  • sudo nano /etc/init.d/bootup
  • #! /bin/sh
  • # runs because it's called at the end of /etc/init.d/rc.local
  • # use /etc/profile instead for commands that should execute every shell creation (putty) like "startx"
  • sudo echo bootup started at $(date)>/home/pi/bootlog.txtsudo vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565
  • return 0
  • sudo chmod 755 /etc/init.d/bootup

Full Development Environment

Lions tigers and bears, as well as pythons and compilers and git and mercurial and...
  • sudo apt-get install ca-certificates git-core binutilssudo apt-get install build-essential python-yaml cmake subversion wget python-setuptools mercurial git-core libapr1-dev libaprutil1-dev libbz2-dev python-dev libgtest-dev python-paramiko libboost-all-dev liblog4cxx10-dev pkg-config python-empy swig python-nose lsb-release python-pip python-gtk2 diveintopython3

Do you want PHP?  Sure!
  • sudo apt-get install php5-common php5-cgi php5 php5-mysql php5-cli

Do you want a full PHP server?  I don't, but you may!
  • sudo lighty-enable-mod fastcgi-php

Apple Airplay

Let's throw some audio at it and see if it works.  Thank you "shairport"!

# amixer cset numid=3 1 (I didn't need this step, perhaps because I dont have HTMI plugged in?)
  • sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl
  • git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp
  • cd perl-net-sdp
  • perl Build.PL
  • sudo ./Build
  • sudo ./Build test
  • sudo ./Build install
  • cd ..
  • git clone https://github.com/hendrikw82/shairport.git shairport
  • cd shairport 
  • make
  • ./shairport.pl -a AirPi
  • sudo make install
  • sudo cp shairport.init.sample /etc/init.d/shairport
  • cd /etc/init.d/shairport
  • sudo chmod a+x shairport
  • sudo update-rc.d shairport defaults

And then to get it to show up nice on your iPhone:
  • sudo nano shairport
  • edit the: DAEMON_ARGS="-w $PIDFILE -a AirPi"
Then go for it!
  • cd /etc/init.d 
  • ./shairport start
  • sudo nano /etc/dhcp/dhclient.conf
  • send host-name "rpi";

Pandora Radio

More music!
  • sudo apt-get install alsa-utils mpg321 lame

You may need to tell the pi to use the audio jack instead of the HDMI out.
  • sudo nano /usr/share/alsa/alsa.conf
  • change the line "pcm.front cards.pcm.front" to "pcm.front cards.pcm.default" 
  • sudo apt-get install pianobar
  • nano ~/.config/pianobar/config
tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0
fifo = /var/www/fifo
user = (your pandora user email)
password = (your own password)             
You can now run pianobar and control it through the terminal.  Which is mostly cool.  More on this later.

Access files from OSX Finder

  • sudo apt-get install netatalk
  • /etc/init.d/netatalk start
Booya!  access to the files via the mac OS finder


Not yet Working

  1. Dynamic DNS so I can reach the pi from away from home.

Comments

Popular posts from this blog

Visualizing the user post migration paths across Reddit to extract linked communities

Why people don't like Product Managers

Inability to visualize the scale of our national debt