RPi/installation

From Bjoern Hassler's website
< RPi
Jump to: navigation, search

1 Installation[edit]

Save yourself some pain by using branded additional parts, e.g. for the micro SD card, as well as a good PSU (rather than an old phone charger you have lying about).

1.1 Raspian OS installation[edit]

Installation instructions here: https://www.raspberrypi.org/learning/quick-start-guide/quickstart/, http://www.raspberrypi.org/help/noobs-setup/. Easiest is to use NOOBS image.

Some notes: I have previously used the NOOBS image successfully, but for some reason (due to the lack of a HDMI monitor) I couldn't get it work this time (with my composite monitor). Instead, you can just write the Raspian image onto an SD card. So I got the http://downloads.raspberrypi.org/raspbian_latest Wheezy Jessie image from http://www.raspberrypi.org/downloads (with Jessie there is a 'full and a 'light' version available).

  • Writing the disk image to an SD card
    • dd - use this guide http://elinux.org/RPi_Easy_SD_Card_Setup to install the image with dd. Note that you need to use "rdisk" rather than "disk", i.e./dev/rdisk... - I had previously used /dev/disk, and it didn't work.
      • "disk arbitrator" can be useful to find the disk
      • sudo dd if=image.img of=/dev/rdiskXXX bs=1M
    • etcher - GUI-based writing of image, recommended on the Raspberry Pi site [1]. While I've used dd before, the advantage of Etcher is that it verifies the image install. (Yesterday I spent a few hours trying to get a Raspberry Pi to boot headless, and only when I used Etcher I realised that out of a stack of 4 cards, I'd picked the corrupted one. Bjoern 11:51, 15 January 2017 (UTC) - Actually, the cards are unbranded, and are probably corrupt - today I experienced issues with eh 2nd card. Bjoern 19:31, 15 January 2017 (UTC))

You now should now have an SD card with a working OS installation. A few more tweaks while you're writing the SD card:

  • ssh is disabled by default in Jessie [2]. When the card is written (and you are aiming for a headless setup), place an empty file called 'ssh' onto the boot partition [3].
  • Wireless: It's possible to pre-configure wireless:
    • [4] says "If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings; this allows a Wifi configuration to be preloaded onto a card from a Windows or other machine that can only see the boot partition." Further details below.

Once that's all done, pop the card into he Pi, and boot.

  • For ssh, you will need to look up the IP address on my router (the hostname raspberrypi didn't work), and logged in with "ssh pi@ip_address".
    • Depending on your network setup, "ssh pi@raspberrypi" should also work.
  • Previously you would have wanted to expand the image to fit the whole sd card: sudo raspi-config
    • However, [5] says: "When flashing a new Raspbian image, the file system will automatically be expanded to use all the space on the card when it is first booted."

1.1.1 Logging in without password / disabling password-based login (more details below)[edit]

At least change the default password.

You may also want to set up password less login (with key) and then disable password login [6]:

sudo nano /etc/ssh/sshd_config

and make sure it has the line

PasswordAuthentication no

(no # in front of the line)

Then reboot or restart sshd

sudo /etc/init.d/ssh restart

1.1.2 Edit the host name[edit]

If you have several Raspberry Pi on your network, you'll want to change the hostname:

sudo nano /etc/hostname

and enter your hostname

1.2 Wireless / Wifi[edit]

1.2.1 During SD card installation via /boot[edit]

It's possible to pre-configure wireless, see [7] (c.f. above), "If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings".

Typically, the wpa_supplicant.conf file looks something like this:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
   ssid="..."
   psk="..."
}

So you just need to fill in your ssid and password, and the Raspberry Pi will automatically connect to that network.

1.2.2 Manual Wireless (when logged into Raspberry Pi)[edit]

See [8]. Run

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add

network={
   ssid="SSID"
   psk="wifi_password"
}

Helpful commands: Scan for networks:

sudo iwlist wlan0 scan 

Which network am I connected to?

iwgetid -r

1.2.3 Wireless power management[edit]

Previous notes here: RPi/installation/Wireless (includes issues with wifi dongle turning itself off). This also occurs with the official Raspberry Pi dongle, and must be to do with the power management. Possible solution here: https://www.raspberrypi.org/forums/viewtopic.php?t=46569&p=647343

Run

iwconfig

and look out for

Power Management:on

If it's "on", then

sudo emacs /etc/network/interfaces

Add

wireless-power off

Restart networking

sudo /etc/init.d/networking restart

Check

iwconfig

You should see

Power Management:off

1.3 update[edit]

apt-get update 
apt-get upgrade

Not sure whether this is needed:

sudo apt-get install raspberrypi-bootloader

It's given in some instructions, but when I ran it, it was already at the latest version.

1.4 network performance[edit]

It's always good to know what the network throughput is, so iperf is your app:

sudo apt-get install iperf

1.5 Which revision do I have?[edit]

There are different revisions of the Raspberry Pi model B about, and you can type

cat /proc/cpuinfo

to find out what revision you have, c.f. http://elinux.org/RPi_HardwareHistory (and previous pages here http://www.raspberrypi.org/archives/1929 and http://www.raspberrypi.org/archives/tag/rev2). Revisions table also available here.

1.6 file sharing with mac/afs[edit]

1.6.1 Setting up the server (on Raspberry Pi)[edit]

If you have a Mac, file sharing using AFS is really easy:

sudo apt-get install netatalk

See this article on the Raspberry Pi forums regarding e.g. sharing a USB drive mounted on "/media".

sudo /etc/init.d/netatalk stop
sudo nano /etc/netatalk/AppleVolumes.default

and amend /etc/netatalk/AppleVolumes.default as follows, e.g. to share

  • ~
  • ~/some_dir
  • and a drive / USB stick mounted in /media:
:DEFAULT: options:upriv,usedots,tm,rw
# By default all users have access to their home directories.
~/ "Home Directory"
~/some_dir "Some DIr"
/media/DRIVENAME "DRIVENAME"
# End of File

Then restart netatalk:

sudo /etc/init.d/netatalk start

(You can also use "restart".)

1.6.2 Connect (on Mac)[edit]

On Mac, the share should now appear in the finder, and you can connect (using username/password for your rpi)

1.6.3 Setting up the client (on Raspberry Pi)[edit]

You may also want to connect to the share from another Raspberry Pi (to save you setting up another file sharing protocol). Suppose you have shared a directory called MY_SHARE on HOST, with user USER and password PASSWORD. On the client, install:

 sudo apt-get install afpfs-ng
 sudo apt-get install fuse

Make a mount point

sudo mkdir /media/my_share
sudo chown pi /media/my_share
sudo chgrp fuse /media/my_share

You may have to add the user 'pi' to the group 'fuse'

sudo usermod -a -G fuse pi

(log in/log out after that, and check with 'groups' that it's works) Then

sudo nano /etc/fuse.conf

and uncomment "user_allow_other". [9] You may then have to restart. Then

mount_afp 'afp://USER:PASSWORD@HOST/MY_SHARE' /media/my_share

Overall, this works ok, except that occasionally the mount just disappears. Re-mounting works.

1.6.4 On a tangent: Attaching hfs+ drives to the pi[edit]

NOTE: When I attached hfs+ formatted drives to the pi, the fs got corrupted pretty quickly. In a couple of cases it could be repaired, in another case it couldn't. So probably not stable enough for rw access.

1.7 filesharing with another pi[edit]

I did try NFS, and encountered some problems.

sshfs worked. On the cient, you can use

sudo sshfs -o allow_other pi@<ip>:/media media

Or, if you have password-free login, then on the client you need to say

usermod -aG fuse pi

(for user 'pi'), so that you can mount shares as user 'pi', and thus use the ssh credentials.

sshfs pi@<ip>:/media media

1.8 login without password[edit]

Assuming there is no .ssh/id_rsa.pub on the first computer, then this bash script will set up password less login from the first computer into SERVER with user USER (for details, see http://www.linuxproblem.org/art_9.html):

export USER='USER'
export SERVER='SERVER'
ssh-keygen -t rsa
ssh ${USER}@${SERVER} mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh ${USER}@${SERVER} 'cat >> .ssh/authorized_keys'

Now you can login from the first computer to the SERVER as user USER without password:

ssh ${USER}@${SERVER}

1.8.1 Prohibit logging in with password[edit]

Now that you've got key-based login working, you might want to disable password-based login. See e.g. http://www.linux.org/threads/how-to-force-ssh-login-via-public-key-authentication.4253/ for instructions.

In brief:

sudo emacs /etc/ssh/sshd_config

Change this settings

PasswordAuthentication no

(commented out or 'yes' by default). Check these settings:

RSAAuthentication yes
PubkeyAuthentication yes

(to make sure you can still log in). Reload ssh

sudo /etc/init.d/ssh reload

1.9 Sending Email[edit]

See iqjar: If you just want send email from the root user, you only need to do steps 1, 2, 3a. In brief, for email just for the rootuser:

sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo emacs /etc/ssmtp/ssmtp.conf

and enter:

root=postmaster
mailhub=smtp.gmail.com:587
hostname=raspberrypi
AuthUser=your_gmail_user@gmail.com
AuthPass=your_gmail_password
UseSTARTTLS=YES

If you want to use mutt to send messages:

sudo apt-get install mutt

and

echo "test message" | mutt -s "a test" -- email_address@domain
echo "test message" | mutt -s "a test" -a file.txt -- email_address@domain

1.10 Buying components[edit]

I should write something here about buying components, like PSU, speaker, wifi dongle (see above) etc.

Connecting to a screen: HDMI to DVI: I bought this connector http://www.ebay.co.uk/itm/110709897629 for £2. It converts the HDMI output of the RPi to DVI, and will thus work with a DVI screen. Works well!

  • VGA. You may be able to connect the RPi to a VGA screen that you have. However, this will only work if the VGA screen is "relatively modern" and can take a "DVI over VGA" signal.
  • Composite. You should also be able to use composite. I've had problems with that.

Speaker. It's handy to have a speaker connected to the RPi. I got this one http://www.ebay.co.uk/itm/141083562291 for £1, but it's very quiet. So not ideal.

Wifi. See above.

PSU. Trying to find a cheap PSU for it. It's possible to get a 1A PSU for £5+, but trying to find something cheaper. Bjoern 11:38, 8 January 2014 (UTC) Get a good 2A PSU for it. I'd recommend either getting the official one, or one that's recommended for use with Raspberry Pi.

You might also want to get:

  • Kits of electronical components (like a resistor pack)
  • Breadboard / breakout cable
  • Jump wires
  • Temperature sensors

Things to experiment with:

Also see components.

1.11 Reducing wear on SD card (e.g. for 24-7 headless use)[edit]

An idea to reduce SD card wear is to place certain directories into a RAM disk. Adjust the fstab

sudo nano /etc/fstab

E.g. [10], [11] suggest:

tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
tmpfs /var/run tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0
tmpfs /var/spool/mqueue tmpfs defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0

[12] suggests:

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/log/apt tmpfs defaults,noatime 0 0
tmpfs /var/cache/apt/archives tmpfs defaults,noexec,nosuid,nodev,mode=0755 0 0

1.12 media tools: avconv, ffmpeg[edit]

Raspbian, as a derivative of Debian, doesn't come with ffmpeg. You can install avconv via

sudo apt-get install libav-tools

However, if you do need ffmpeg, you can get the binary from the motioneye repo

wget https://github.com/ccrisan/motioneye/wiki/precompiled/ffmpeg_3.1.1-1_armhf.deb
sudo dpkg -i ffmpeg_3.1.1-1_armhf.deb

Hannes ihm sein Blog also has a recipe for building from source

mkdir ffmpeg
cd ffmpeg

# build and install x264
git clone --depth 1 git://git.videolan.org/x264
cd x264
./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
make -j 4
sudo make install
cd ..
 
# build and make ffmpeg
git clone --depth=1 git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --arch=armhf --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
make -j 4
sudo make install
cd ..
cd ..

1.13 Finally[edit]

The microSD card slots in the B+ and 2B are 'push to lock', and unfortunately they don't feel that securely stuck in. For instance, it is easily possible to 'brush out' the microSD card (i.e. run your thumb over the card, and it can come out quite easily). If your Raspberry Pi is moving around a lot, you may want of put a bit of electrical tape over the slot in your case (that lets you access the SD card), to prevent accidental ejection. In the 3B and Zero, the microSD card slot has been changed for a friction fit, which feels much securer [13], and the card is much harder to pull out.