Raspberry PI setup guide ¶
Contents
- 1 Initial setup
- 2 Enable SSH connections
- 3 Set locale
- 4 Replace "pi" password
- 5 Expand swap partition ...
- 6 ... or remove it !
- 7 Setup SMTP
- 8 Start chromium in Kiosk mode on raspbian jessie
- 9 Pi display
- 10 Display rotation
- 11 Disable screen sleep
- 12 How to up a Static IP on Your Ethernet or Wireless Network Connection
- 13 Setting up a Raspberry Pi as an access point in a standalone network (NAT)
- 14 Connect and use Camera
- 15 Installing Python 3.7.x on Raspbian
- 16 todo
- 17 Software upgrades
1 Initial setup
- download "Raspbian Stretch with desktop" from here: https://www.raspberrypi.org/downloads/raspbian/
- prepare SD as explained here: https://www.raspberrypi.org/documentation/installation/installing-images/README.md
- boot Raspberry PI (with a display connected) and follow instructions for initial setup
Eventually expand file system if part of the SD is unused:
raspi-config --expand-rootfs
2 Enable SSH connections
Connect with a keyboard, then issue these commands from terminal:
systemctl enable ssh.service systemctl start ssh.service
3 Set locale
sudo -s export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 locale-gen en_US.UTF-8 dpkg-reconfigure locales
4 Replace "pi" password
su pi passwd
5 Expand swap partition ...
100 Mb (the default) is too small, and if you are doing memory intensive stuff (e.g., web surfing), you can easily max it out.
The recommended swap size is 2*physical RAM - in the case of the Pi (modern/current versions of), this is 2G.
You can increase the swap size by changing the CONF_SWAPSIZE or the CONF_SWAPFACTOR parameter in /etc/dphys-swapfile followed by a reboot:
cat /etc/dphys-swapfile [...] CONF_SWAPFACTOR=2 [...]
Test after reboot:
# free -h total used free shared buff/cache available Mem: 927M 259M 425M 30M 242M 585M Swap: 1.8G 0B 1.8G
6 ... or remove it !
On the other hand, you might want to turn off swap entirely in order to reduce the amount of write operations on the SD card – because SD cards have their life limited to the amount of write operations:
sudo systemctl disable dphys-swapfile
Test after reboot:
# free -h total used free shared buff/cache available Mem: 927M 257M 437M 24M 232M 593M Swap: 0B 0B 0B
Another option is to move swap to an external device (for example a USB key).
References:
7 Setup SMTP
TODO; vedere:
Installazione e Configurazione di Postfix su Raspberry usando come Smarthost GMAIL:
https://www.raffaelechiatto.com/installazione-configurazione-postfix-raspberry-usando-smarthost-gmail/NULLMAILER – IL POSTINO MINIMALISTA:
https://hamradio.fe.linux.it/nullmailer-il-postino-minimalista/
8 Start chromium in Kiosk mode on raspbian jessie
file ~/Desktop/runChromium.desktop:
[Desktop Entry] Type=Application Exec=/usr/bin/chromium-browser --noerrdialogs --disable-session-crashed-bubble --disable-infobars --kiosk http://127.0.0.1 Hidden=false X-GNOME-Autostart-enabled=true Name[en_US]=RunChromium Name=RunChromium Comment=Start Chromium in kiosk mode; copy int ~/.config/autostart to have it run automatically
References:
9 Pi display
How to hide the cursor in the kiosk mode automatically:
sudo apt-get install unclutter
then add this to file /etc/xdg/lxsession/LXDE/autostart:
@unclutter -idle 0.1 -root
10 Display rotation
file "/boot/config.txt":
# LCD Rotation lcd_rotate=2 # Display Rotate (HDMI) #display_rotate=2
11 Disable screen sleep
file "/etc/lightdm/lightdm.conf":
[Seat:*] ... # don't sleep the screen xserver-command=X -s 0 dpms
or:
sudo apt-get install xscreensaver
then configure the screensaver application under the Preferences option on the main desktop menu.
12 How to up a Static IP on Your Ethernet or Wireless Network Connection
file /etc/dhcpcd.conf:
# setup ethernet static ip interface eth0 inform 192.168.1.18 static routers=255.255.255.0 # setup wireless static ip interface wlan0 inform 192.168.1.19 static routers=255.255.255.0
or:
# setup ethernet static ip interface eth0 static ip_address=172.26.11.85/24 static routers=172.26.11.100 static domain_name_servers=8.8.8.8 8.8.4.4
then:
#sudo /etc/init.d/networking restart sudo reboot
https://projects.raspberrypi.org/en/projects/getting-started-with-picamera
13 Setting up a Raspberry Pi as an access point in a standalone network (NAT)
Brief summary:
Install required software:
sudo apt-get update sudo apt-get upgrade sudo apt-get install dnsmasq hostapd
then stop the services and reboot:
sudo systemctl stop dnsmasq sudo systemctl stop hostapd sudo reboot
Configuring a static IP for wlan0:
add this to /etc/dhcpcd.conf:
interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant
then:
sudo service dhcpcd restart
Configuring the DHCP server (dnsmasq):
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo vim /etc/dnsmasq.conf
and add:
interface=wlan0 # Use the require wireless interface - usually wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
Configuring the access point host software (hostapd):
add this to /etc/hostapd/hostapd.conf:
interface=wlan0 driver=nl80211 ssid=NETWORK_NAME hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=NETWORK_PASSPHRASE wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
where:
NETWORK_PASSPHRASE: between 8 and 64 characters
hw_mode:
- a = IEEE 802.11a (5 GHz)
- b = IEEE 802.11b (2.4 GHz)
- g = IEEE 802.11g (2.4 GHz)
- ad = IEEE 802.11ad (60 GHz)
Add this to /etc/default/hostapd:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Start the access point host software:
sudo systemctl start hostapd sudo systemctl start dnsmasq
if necessary:
sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo systemctl start hostapd
Add routing and masquerade:
Uncomment this line in /etc/sysctl.conf:
net.ipv4.ip_forward=1
Add a masquerade for outbound traffic on eth0:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Save the iptables rule:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot:
iptables-restore < /etc/iptables.ipv4.nat
Reboot and done !
References:
Setting up a Raspberry Pi as an access point in a standalone network (NAT)
15 Installing Python 3.7.x on Raspbian
sudo su cd mkdir downloads cd downloads apt-get update -y apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz tar xf Python-3.7.2.tar.xz cd Python-3.7.2 ./configure make -j 4 make altinstall cd .. rm -r Python-3.7.2 rm Python-3.7.2.tar.xz apt-get --purge remove build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y apt-get autoremove -y apt-get clean
References:
16 todo
All my Pi's (including Pi Zero's) have these two lines added to /etc/fstab:
tmpfs /tmp tmpfs defaults,noatime,nosuid 0 0 tmpfs /var/log tmpfs defaults,noatime,nosuid,size=16m 0 0
The default maximum size is half the memory, but of course tmpfs only takes as much memory as the files need.
While you are in /etc/fstab, if you want to reduce writes to the SD then the other simple change is the flush rate.
For the ext4 / mount make sure the options include "commit=600" That is, for example:
PARTUUID=e96d960e-02 / ext4 defaults,noatime,commit=600,errors=remount-ro 0 1
Obviously do not do this if your site is prone to power cuts or other unexpected outages. (dirty pages in the disk cache are written out every ten minutes instead of every five seconds which is the default). This improves performance as well.