Raspbian Stretch Setup
## Enable SSH after first boot
Mount first partion of SD card (boot) on a PC and create file "ssh" before first raspberry pi boot.
*touch ssh*
## Change password
*passwd*
## Update and Upgrade
*apt-get update && apt-get upgrade*
## Install VIM
*apt-get install vim*
## Static IP
*ifconfig* (check name of ethernet device)
add following to /etc/dhcpcd.conf:
```
interface eth0
static ip_address=192.168.0.20/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.20
```
*reboot*
## Hostname change
```
raspi-config
```
network -> hostname
## Minimum graphic memory
```
gpu_mem=16
```
To give maximum amount of memory to the processor.
## WLAN
First change the Wifi country using raspi-config.
(Adding "country=DE" to wpa_supplicant.conf; see path below)
Then add WLAN credentials (just add the block below multiple time) to /etc/wpa_supplicant/wpa_supplicant.conf
```
network={
ssid="WLANname"
psk="WLANpass"
scan_ssid=1 # add this line to connect to hidden Wifis
}
```
*reboot* or "ifdown wlan0 && ifup wlan0"
## Nginx + MariaDB + PHP7 + Nextcloud
[HowTo](https://goneuland.de/wordpress/debian-9-stretch-nextcloud-mit-nginx-mariadb-und-php7-installieren/)
Additions [see](https://docs.nextcloud.com/server/13/admin_manual/installation/system_requirements.html#database-requirements-for-mysql-mariadb):
```
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
Follow the installation and configuration manual of nextcloud for latest recommendations.
### Fix downloading of big files fails after \~30 minutes
* Enlarge socket timeout in php config */etc/php/7.0/fpm/php.ini*:
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 6000
* Disable request timeout in php config (just to be sure) */etc/php/7.0/fpm/pool.d/www.conf*:
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 0
## Create backup
```
cd /media/username/disk_to_backup
tar --selinux --acls --xattrs --exclude='./dev' --exclude='./proc' --exclude='./sys' --exclude='./tmp' --exclude='./run' --exclude='./mnt' --exclude='./media' --exclude='./lost+found' -czvf /home/username/backup.tar.gz .
```
list only top level of tar archive
```
tar --exclude "*/*" -tf /home/efelon/backup_root-webraspi_jessie.tar.gz
```
## Boot from HD
* Partition HD (e.g. Part1 - / , Part2 - /var, Part3 - swap) with ext4 (except swap)
* Test-plugin HD to raspi and find out PARTUUID with *blkid*
* *poweroff* raspi and plug SD card and HardDisk to PC
* *rsync* files:
sudo rsync -avxHAX --numeric-ids --info=progress2 --exclude={"dev","proc","sys","tmp","run","mnt","media","lost+found","var"} /media/efelon/rootfs/ /media/efelon/df59203d-f0ee-43fd-a09e-0fe2fe2a29a1/
sudo rsync -avHAX --numeric-ids --info=progress2 /media/efelon/rootfs/var/ /media/efelon/628fcf91-b5d3-407e-a31d-51faa5ac8881/
cd /media/efelon/df59203d-f0ee-43fd-a09e-0fe2fe2a29a1
sudo mkdir dev proc sys tmp run mnt media
Eventually add **--ignore-errors** if you copy from corrupted SD card, and hope that no important files are affected.
* modify /etc/fstab e.g.:
proc /proc proc defaults 0 0
PARTUUID=9eb52498-01 /boot vfat defaults 0 2
PARTUUID=0006f6f4-01 / ext4 defaults,noatime 0 1
PARTUUID=0006f6f4-02 /var ext4 defaults,noatime 0 3
PARTUUID=9eb52498-02 /backup ext4 defaults,ro,noatime 0 4
PARTUUID=0006f6f4-03 none swap sw 0 0
a swapfile is not a swap partition, no line here use dphys-swapfile swap\[on\|off\] for that
* modify /boot/cmdline.txt e.g.:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=0006f6f4-01 rootfstype=ext4 noatime quiet rootwait elevator=deadline fsck.repair=yes
* boot rapsi
### Raspberrypi 4 boot from USB3
[https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/](https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/)
## disable swapfile:
```
sudo swapoff -a
sudo systemctl disable dphys-swapfile
sudo reboot
```
## publish status via snmpd
```
apt-get update
apt-get install snmpd
```
/etc/snmp/snmpd.conf:
```
agentAddress udp:161,udp6:[::1]:161
[...]
createUser username SHA "password" DES
[...]
rouser username priv
[...]
extend raspberry /etc/snmp/raspberry.sh
```
/etc/snmp/raspberry.sh:
```
#!/bin/bash
#######################################
# please read DOCS to succesfully get #
# raspberry sensors into your host #
#######################################
picmd='/usr/bin/vcgencmd'
pised='/bin/sed'
getTemp='measure_temp'
getVoltsCore='measure_volts core'
getVoltsRamC='measure_volts sdram_c'
getVoltsRamI='measure_volts sdram_i'
getVoltsRamP='measure_volts sdram_p'
getFreqArm='measure_clock arm'
getFreqCore='measure_clock core'
getStatusH264='codec_enabled H264'
getStatusMPG2='codec_enabled MPG2'
getStatusWVC1='codec_enabled WVC1'
getStatusMPG4='codec_enabled MPG4'
getStatusMJPG='codec_enabled MJPG'
getStatusWMV9='codec_enabled WMV9'
sudo $picmd $getTemp | $pised 's|[^0-9.]||g'
sudo $picmd $getVoltsCore | $pised 's|[^0-9.]||g'
sudo $picmd $getVoltsRamC | $pised 's|[^0-9.]||g'
sudo $picmd $getVoltsRamI | $pised 's|[^0-9.]||g'
sudo $picmd $getVoltsRamP | $pised 's|[^0-9.]||g'
sudo $picmd $getFreqArm | $pised 's/frequency(45)=//g'
sudo $picmd $getFreqCore | $pised 's/frequency(1)=//g'
sudo $picmd $getStatusH264 | $pised 's/H264=//g'
sudo $picmd $getStatusMPG2 | $pised 's/MPG2=//g'
sudo $picmd $getStatusWVC1 | $pised 's/WVC1=//g'
sudo $picmd $getStatusMPG4 | $pised 's/MPG4=//g'
sudo $picmd $getStatusMJPG | $pised 's/MJPG=//g'
sudo $picmd $getStatusWMV9 | $pised 's/WMV9=//g'
sudo $picmd $getStatusH264 | $pised 's/enabled/2/g'
sudo $picmd $getStatusMPG2 | $pised 's/enabled/2/g'
sudo $picmd $getStatusWVC1 | $pised 's/enabled/2/g'
sudo $picmd $getStatusMPG4 | $pised 's/enabled/2/g'
sudo $picmd $getStatusMJPG | $pised 's/enabled/2/g'
sudo $picmd $getStatusWMV9 | $pised 's/enabled/2/g'
sudo $picmd $getStatusWMV9 | $pised 's/enabled/2/g'
sudo $picmd $getStatusH264 | $pised 's/disabled/1/g'
sudo $picmd $getStatusMPG2 | $pised 's/disabled/1/g'
sudo $picmd $getStatusWVC1 | $pised 's/disabled/1/g'
sudo $picmd $getStatusMPG4 | $pised 's/disabled/1/g'
sudo $picmd $getStatusMJPG | $pised 's/disabled/1/g'
sudo $picmd $getStatusWMV9 | $pised 's/disabled/1/g'
```
visudo (check actual username of snmp):
```
Debian-snmp ALL=(ALL) NOPASSWD: /etc/snmp/raspberry.sh, /usr/bin/vcgencmd*
```
## send syslogs to remote server
/etc/rsyslog.d/90-remote.conf
```
# for UDP
*.* @192.168.0.20:514
# for tcp
#*.* @@192.168.0.20:514
```
## stop cron from writing to syslog
/etc/rsyslog.conf
change
```
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
```
to
```
*.*;cron,auth,authpriv.none -/var/log/syslog
cron.* /var/log/cron.log
```
In Debian stretch the log rotate mechanism is already active in
/etc/logrotate.d/rsyslog
## turn of power LED
### Raspi 2 model 2 B, B+ and A+
Luckily, with the Pi 2 model B, B+, A+, and Zero, you can control the LEDs in software, in a few different ways. The simplest way to change the way these LEDs work is to modify the trigger for each LED by setting it in /sys/class/leds/led\[LED_ID\]/trigger, where you replace \[LED_ID\] with 0 for the green ACT LED, and 1 for the red PWR LED.
For example:
```
# Set the PWR LED to GPIO mode (set 'off' by default).
echo gpio | sudo tee /sys/class/leds/led1/trigger
# (Optional) Turn on (1) or off (0) the PWR LED.
echo 1 | sudo tee /sys/class/leds/led1/brightness
echo 0 | sudo tee /sys/class/leds/led1/brightness
# Revert the PWR LED back to 'under-voltage detect' mode.
echo input | sudo tee /sys/class/leds/led1/trigger
# Set the ACT LED to trigger on cpu0 instead of mmc0 (SD card access).
echo cpu0 | sudo tee /sys/class/leds/led0/trigger
```
If you want to disable both LEDs permanently, add the following to /boot/config.txt:
```
# Disable the ACT LED.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
# Disable the PWR LED.
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off
```
### Raspi 3
To disable permamently the following lines could be placed at the end of */etc/rc.local*:
```
#turn off the power LED
sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'
#turn off the action LED
sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'
```