Sunday 1 July 2012

Pi Time

I've had my Pi a couple of weeks, but there's not been enough time to really get it going.  Last night I decided I was going to set it up once and for all.  Here's what I had in mind:

Hardware
  1. Wireless network connection
    • Asus N13 Realtek Dongle (£16)
  2. Wireless keyboard and mouse
    • Logitech mk260  (£17)
  3. Single power source for USB hub & Pi
Software
  1. Debian Image (debian6-19-04-2012)
  2. Passwordless SSH on boot
  3. VNC server on boot
The previous week I'd had a 10 min go at getting the pi up and running, and was impressed at the capabilities of something so cheap.  But it was apparent that some effort would be needed to get the device achieving anything close to useful.  Mores the point, I'd had no success with the N10 and had fallen back to wired ethernet.


The Plan
There's nothing quite like research when it comes to setting up new hardware, especially kit as experimental as the Pi.  Here are the websites to whom I'm truly thankful for advice and instruction.
I found it necessary to mix in steps from each of the above and brew a bespoke install guide.   I'll explain more at the end, but suffice is to say - pay particular attention to code revision numbers and publication dates.  It really matters.

Setting up tutorial
Part A: pre switch on
You need a host machine to preconfigure your SD card.  If you've not got one, don't bother reading further.  Sell your Pi on ebay, and go for a pint instead. If on the other hand, you are up for the challenge read on. The first section deals with getting the pi to boot with wifi enabled. It borrows heavily from the pi startup guide and Tomasz Miklas posting on ctrl-alt-del.cc.
  1. Download debian6-19-04-2012 image. Get your image here http://www.raspberrypi.org/downloads
  2. Copy the image to an SD card.  In linux we dd, on Windows you'll do something else.  My SD card is /dev/sdc, and I'd changed directory to be in the same place as the image input file
  3. sudo dd if=debian6-19-04-2012.img of=/dev/sdc
    
    Being executed from the command line, it may appear as if nothing happens. Mine took around 4 min to complete.
  4. Sync the SD card before removing it to ensure data writing completes without error
  5. sudo sync
    
  6. Remove SD card, then reinsert in to the host machine. There's much more preparation to be done before getting anywhere near the Pi.
  7. On inserting the card into a Linux host, two new volumes will appear. One is the 79 Mb DOS boot disc, the other is the 2 Gb root volume. I have a 4 Gb SD card, so I need to resize the partitions on the new volumes to reclaim lost space. I did this in graphical parted (Gparted)· Note that the volumes must be unmounted before Parted can work on them. My linux automounts SD cards under /media using volume UUIDs as names for mount points.
    sudo umount /media/18c27e44-ad29-4264-9506-c93bb7083f47/
    sudo umount /media/95F5-0D7A/
    
    I fired up Gparted, selected /dev/sdc as the target volume and did two things
    1. Move swap to end of volume on right
    2. Resized Root to use maximum free space
    3. Finally remove & reinsert the SD card to remount mount it on the host machine for further file copying
  8. Download and copy over firmware updates and kernel modules. GitHub hosts the necessary files, so you'll need github core tools installed to carry out the next steps. Git Help at https://github.com/raspberrypi
  9. cd
    mkdir git_pi
    cd git_pi
    git clone git://github.com/raspberrypi/firmware.git
    cd firmware
    git checkout a8f8d24
    
    Key in these steps are ensuring that we use firmware previously shown to work - the checkout command specifies the code revision we will use. Big thumbs up to Tomasz Miklas.
  10. Copy all files from /firmware/boot and firmware/opt/vc to their respective places on the SD card. Note that on Linux if you copy in a file with the same name, the original file is replaced without warning.
    cd /media/95F5-0D7A/boot
    cp -r ~/git_pi/firmware/boot/* .
    rm -rf /media/18c27e44-ad29-4264-9506-c93bb7083f47/opt/vc
    cp -r ~/git_pi/firmware/opt/vc /media/18c27e44-ad29-4264-9506-c93bb7083f47/opt/
    rm -r /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/3.1.9+ 
    cp -r ~/git_pi/firmware/lib/modules/3.1.9+ /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/
    
  11. Now git clone firmware tools, as below, and copy over libstdc++.so.6.0.14
    cd ~/git_pi
    git clone git://github.com/raspberrypi/tools.git
    cd tools
    git checkout 3aba47b
    cp arm-bcm2708/linux-x86/arm-bcm2708-linux-gnueabi/sys-root/lib/libstdc++.so.6.0.14 \
    /media/18c27e44-ad29-4264-9506-c93bb7083f47/usr/lib/.
    
  12. Finally, copy over the wireless driver module
    cd ~/pi_git/
    wget http://www.electrictea.co.uk/rpi/8192cu.tar.gz
    gunzip -c 8192cu.tar.gz |tar -xf -
    cp 8192cu.ko /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/3.1.9+/kernel/net/wireless/.
  13. Now we do a bit of configuration before firing up the pi. Set configuration for WPA2 (or whatever you need), load wireless module every time and make active at boot.
    nano /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/wpa_supplicant.conf
    
    Enter text as shown (replacing your SSID and passphrase)
    ctrl_interface=/var/run/wpa_supplicant
    network={
        ssid="_your_SSID_"
        scan_ssid=1
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP TKIP
        group=CCMP TKIP
        # to get encoded PSK run: wpa_passphrase 
        psk=YOUR KEY
    }
    
    Two things to note: 1) double quotes around SSID, 2) PSK is the output of wpa_passphrase _your_SSID
  14. Configure network interfaces
  15. nano /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/network/interfaces
    
    This is what I have ...
    auto lo
    
    iface lo inet loopback
    iface eth0 inet dhcp
    
    auto wlan0
    iface wlan0 inet dhcp
    pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant.conf -B
    
  16. Disable loading of native wifi driver, ensure our wifi driver loads, even when dongle isn't present.
    echo '8192cu' >>  /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/modules
    echo 'blacklist rtl8192cu' >> /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/modprobe.d/blacklist.conf
    
  17. Enable ssh at boot
    cd /media/95F5-0D7A
    mv boot_enable_ssh.rc boot.rc 
That's it for pre-configuration. You can now remove your SD card from the host PC, insert it in to th Pi and power on.

Headless Pi powered from USB hub (white kindle cable), wireless dongle at back (under power lead) keyboard / mouse receiver disconnected for boot




Part B: Switch on 
Power on wasn't so straight forward. I found out by trial and error that the USB receiver for the keyboard / mouse conflicted with the WiFi Dongle, and needed to be disconnected at boot. Other than that, I was able to SSH in to the Pi within 2 min of turning on. In the next post I'll describe the elementary set up to get VNC at boot, create local accounts and set up passwordless SSH.

No comments:

Post a Comment