Table of Contents

Information

Prerequisites

Download

Web

wget

Full

wget 'https://downloads.raspberrypi.org/raspbian_latest' -O ~/'Downloads/raspbian.zip'

Lite

wget 'https://downloads.raspberrypi.org/raspbian_lite_latest' -O ~/'Downloads/raspbian-lite.zip'

Expand Filesystem

sudo raspi-config

Software

Update

sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean && sync

General

sudo apt install htop -y && sync

Settings

raspi-config

sudo raspi-config

GNU nano

echo -e "set nowrap\nset nonewlines" | tee ~/'.nanorc' > '/dev/null' && cat ~/'.nanorc'

Kernel Options

echo -e "kernel.dmesg_restrict = 1\nkernel.kptr_restrict = 1\nkernel.sysrq = 1\nvm.swappiness = 10\nvm.vfs_cache_pressure = 50" | sudo tee '/etc/sysctl.d/99-custom.conf' > '/dev/null' && cat '/etc/sysctl.d/99-custom.conf'

Static IP

sudo -e '/etc/dhcpcd.conf'
interface eth0
static ip_address=192.168.1.158/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1 1.0.0.1

systemd Journal

sudo mkdir -p '/etc/systemd/journald.conf.d' && echo -e "[Journal]\nSystemMaxUse=50M\nRuntimeMaxUse=50M" | sudo tee '/etc/systemd/journald.conf.d/logging.conf' > '/dev/null' && cat '/etc/systemd/journald.conf.d/logging.conf'

TRIM

Service

sudo -e '/etc/systemd/system/fstrim.service'
[Unit]
Description=Discard unused blocks

[Service]
Type=oneshot
ExecStartPre=/bin/sync
ExecStart=/sbin/fstrim -a
ExecStartPost=/bin/sync

Timer

sudo -e '/etc/systemd/system/fstrim.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'fstrim.timer' && sudo systemctl start 'fstrim.timer' 'fstrim' && sudo systemctl status 'fstrim' -l
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim

[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

Secure Shell

sudo systemctl disable 'ssh' && sudo systemctl enable 'ssh.socket'

Environment Variables

Timezone

echo 'export TZ=:/etc/localtime' | sudo tee '/etc/profile.d/tz.sh' > '/dev/null' && cat '/etc/profile.d/tz.sh' | grep -e 'export TZ=:/etc/localtime'

Automatic Updates

Service

sudo -e '/etc/systemd/system/raspbian-up.service'
[Service]
Type=oneshot
ExecStartPre='/usr/bin/apt' clean
ExecStart='/usr/bin/apt' update
ExecStart='/usr/bin/apt' full-upgrade -y
ExecStart='/usr/bin/apt' autoremove -y
ExecStartPost='/bin/sync'
ExecStartPost='/bin/systemctl' reboot

Timer

sudo -e '/etc/systemd/system/raspbian-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'raspbian-up.timer' --now
[Unit]
Description=Software Package Maintenance and Updater
After=network-online.target
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 05:40:00
Persistent=true

[Install]
WantedBy=timers.target

https://dakboard.com/app/screenPredefined?p=c14c5944d8ed6a1433ae43c9e96b07d5