Setting up the r.Pi

Introduction

The Raspberry Pi has garnered a strong following since it’s release and has been used in many applications, meaning support should be promptly available for amateurs like myself.

Between the two available versions, the Model A is the smaller less powerful board having only 256 MB of RAM, one USB port and does not have an Ethernet port. However this makes for a smaller form factor (roughly half the height of the Model B) and lower power requirements (roughly a third of the Model B’s idle state). The low power consumption means a standard 1A power bank can be used to power the Model A (500mA), Camera Board (250mA) and the WiFi Dongle.

The Model A has 256MB of RAM, however the GPU requires a dedicated 128 MB for the Camera Board buffer, in order to fully utilize the remaining memory we look to LinuxSystems’ Raspberry Pi minimal image.

LinuxSystems’ Raspberry Pi minimal image is a minimal Raspbian-based Linux image for Raspberry Pi which installs on just a 1GB SD Card, has a nifty boot time and uses a fraction of the Model A’s 256MB RAM (or 128MB in this case).

The customized image is available for download here, otherwise if you would like to have a go then here are the steps I took.

Installation

An internet connection will be required to install additional packages, to do so either attach a USB Ethernet Dongle or run the setup in a Model B.

sudo dd bs=1M if=/home/rcptr/Downloads/raspbian_wheezy_20130923.img of=/dev/sdb

  • Expand the swap to 512MB and the remaining space to ext4 using GParted.
  • Insert the SD Card into the Pi and power up.
  • Connect to the Pi directly or via SSH. (root/raspberry)
  • Configure the Pi’s settings.

dpkg-reconfigure tzdata

dpkg-reconfigure locales

dpkg-reconfigure console-data

  • Change root password

passwd root

  • Set depository links

nano /etc/apt/sources.list

Change the two lines so they look like this

deb http://archive.raspbian.org/raspbian stable main contrib non-free
deb-src http://archive.raspbian.org/raspbian stable main contrib non-free

  • Change hostname

nano /etc/hostname

  • Reboot

Optimization

Next we squeeze as much juice as possible from the Pi by removing/replacing unnecessary processes as shown from this guide.

  • Upgrading to latest version of Raspbian

apt-get -y update && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean

  • Updating the Firmware & Install additional packages

wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update

apt-get install git-core binutils lua5.2 -y

rpi-update

  • Install Dropbear SSH

apt-get install dropbear openssh-client

/etc/init.d/ssh stop

sed -i ‘s/NO_START=1/NO_START=0/g’ /etc/default/dropbear

/etc/init.d/dropbear start

updaterc.d ssh disable

apt-get purge openssh-server

  • Removing extra tty’s

sed -i ‘/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g’ /etc/inittab

  • Replace Bash shell with Dash shell

dpkg-reconfigure dash

  • Optimize /mount

sed -i ‘s/defaults,noatime/defaults,noatime,nodiratime/g’ /etc/fstab

  • Disable IPv6

echo “net.ipv6.conf.all.disable_ipv6=1” > /etc/sysctl.d/disableipv6.conf

echo ‘blacklist ipv6’ >> /etc/modprobe.d/blacklist

sed -i ‘/::/s%^%#%g’ /etc/hosts

  • Replace Deadline Scheduler with NOOP Scheduler

sed -i ‘s/deadline/noop/g’ /boot/cmdline.txt

  • Replace rsyslogd with inetutils-syslogd and remove useless logs

apt-get -y remove –purge rsyslog

apt-get -y install inetutils-syslogd

service inetutils-syslogd stop

for file in /var/log/*.log /var/log/mail.* /var/log/debug /var/log/syslog; do [ -f “$file” ] && rm -f “$file”; done

for dir in fsck news; do [ -d “/var/log/$dir” ] && rm -rf “/var/log/$dir”; done

echo -e “*.*;mail.none;cron.none\t -/var/log/messages\ncron.*\t -/var/log/cron\nmail.*\t -/var/log/mail” > /etc/syslog.conf

mkdir -p /etc/logrotate.d

echo -e “/var/log/cron\n/var/log/mail\n/var/log/messages {\n\trotate 4\n\tweekly\n\tmissingok\n\tnotifempty\n\tcompress\n\tsharedscripts\n\tpostrotate\n\t/etc/init.d/inetutils-syslogd reload >/dev/null\n\tendscript\n}” > /etc/logrotate.d/inetutils-syslogd

service inetutils-syslogd start

  • Edit settings in /boot/config.txt

nano /boot/config.txt

Add the following at the bottom:

force_turbo=0

gpu_mem=128

start_x=1

disable_camera_led=1

Save the file by hitting CTRL+X then Y then ENTER.

  • Reboot

Enable WiFi

Now its time to set up wireless capabilities which will allow us to connect to and control the Pi in the future with steps from this guide.

  • Install required packages, the drivers for this particular adapter is found in the package firmware-ralink omit this package and install the relevant drivers if you are using another adapter.

apt-get install wireless-tools wpasupplicant firmware-ralink hostapd isc-dhcp-server

  • Set up DHCP server.

nano /etc/dhcp/dhcpd.conf

Find the lines that say:

option domain-name “example.org”;
option domain-name-servers ns1.example.org, ns2.example.org;

and add a # in the beginning so they say:

#option domain-name “example.org”;
#option domain-name-servers ns1.example.org, ns2.example.org;

Find the lines that say:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

and remove the # so it says:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Add the following at the bottom:

subnet 192.168.254.0 netmask 255.255.255.0 {
range 192.168.254.100 192.168.254.110;
option broadcast-address 192.168.254.255;
option routers 192.168.254.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name “RCPTR”;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Save the file (CTRL+X then Y then ENTER).

nano /etc/default/isc-dhcp-server

Make sure the line “DHCPD_CONF=/etc/dhcp/dhcpd.conf” is there, if not add it.

Scroll down to INTERFACES=”” and update it to say INTERFACES=”wlan0″ .

Save the file (CTRL+X then Y then ENTER).

  • Static IP for wlan0.

nano /etc/network/interfaces

Find the line auto wlan0 and replace everything after it with:

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.254.1
netmask 255.255.255.0

Save the file (CTRL+X then Y then ENTER).

  • Configure Access Point.

nano /etc/hostapd/hostapd.conf

The file should be empty, just insert the following:

interface=wlan0
#driver=rt2800usb
ssid=r.CPTR
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

And tell the Pi where to find this file:

nano /etc/default/hostapd

Find the line #DAEMON_CONF=”” and edit it so it says DAEMON_CONF=”/etc/hostapd/hostapd.conf”.

  • Starting services at boot.

update-rc.d hostapd enable
update-rc.d isc-dhcp-server enable

  • Reboot and test WiFi connection

Enable Camera

Finally we enable the camera board on the Pi by copying this information into a script.

nano enable_camera.sh

Add the contents from the link:

#!/bin/bash

set_config_var() {
lua – “$1” “$2” “$3” <<EOF > “$3.bak”
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
if line:match(“^#?%s*”..key..”=.*$”) then
line=key..”=”..value
made_change=true
end
print(line)
end

if not made_change then
print(key..”=”..value)
end
EOF
mv “$3.bak” “$3”
}
[ -e /boot/config.txt ] || touch /boot/config.txt

set_config_var start_x 1 /boot/config.txt
set_config_var gpu_mem 128 /boot/config.txt
sed /boot/config.txt -i -e “s/^startx/#startx/”
sed /boot/config.txt -i -e “s/^fixup_file/#fixup_file/”

Set permissions and run the script:

chmod +x enable_camera.sh

./enable_camera.sh

echo ‘export PATH=$PATH:/opt/vc/bin’ >> ~/.bashrc

  • Reboot and take a test picture

raspistill -o image.jpg

Clean Up

A little housekeeping to make things easier when we work on this in the future.

  • Create directories for scripts and settings

mkdir bin

mkdir settings

mkdir settings/wifi

mv enable_camera.sh bin/enable_camera.sh

ln -s /etc/dhcp/dhcpd.conf settings/wifi/dhcpd.conf

ln -s /etc/hostapd/hostapd.conf settings/wifi/hostapd.conf

  • Create update script

nano bin/update_server.sh

Add this and save:

apt-get -y update && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean

Make it executable

chmod +x bin/update_server.sh

Now its available for use every time we need to update.

And there you have it, the r.Pi image has now been set up for the minimal needs of this project. In the future we shall explore methods of streaming the video feed as well as adding extra functionality.

3 thoughts on “Setting up the r.Pi

Leave a comment