Clean install a Raspberry Pi device

How to get a Pi up and running in less than 15 minutes.
Tags: Bash, Linux, Raspberry Pi, reformat

Raspbian

Headless setup

The following instructions are for macOS. Consult the official Raspberry Pi installation guide for Linux and Windows instructions.

diskutil list
diskutil unmountDisk /dev/disk2
cd ~/Downloads
sudo dd if=IMAGE.dmg of=/dev/rdisk2 bs=1m

Monitor-enabled setup

Updates

Reboot and run the necessary system updates.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade

Dynamic DNS

Get a free subdomain at FreeDNS. Copy their update key and set a cron entry to run hourly.

crontab -e
0 * * * * curl http://freedns.afraid.org/dynamic/update.php?KEY >> ~/log/freedns.log 2>&1

Pi-Hole

Load the default configuration with the setup script.

curl -L https://install.pi-hole.net | bash

Set it to update automatically, every Sunday at 4 AM.

crontab -e
0 4 * * 0 pihole -up >> ~/log/pihole.log 2>&1

PiVPN

Load the default configuration with the setup script.

curl -L https://install.pivpn.io | bash

Pi-Hole and PiVPN can be installed together. The setup process is easier if you install Pi-Hole first then PiVPN. After both are installed, edit the /etc/dnsmasq.conf file to allow DNS resolution from the VPN interface: listen-address=127.0.0.1, XXX, 10.8.0.1. Note here that 10.8.0.1 is the address for Pi-Hole.

Samba

Samba (SMB/CIFS) is a commonly used file sharing protocol compatible with macOS and Windows.

sudo apt-get install samba samba-common-bin
sudo smbpasswd -a pi
sudo service smbd restart

Java

JRE is not installed on the Raspberry Pi by default.

sudo apt-get install default-jre

System updates

Automatic updates are an essential part of Linux security. The preferred method on Debian is to use unattended-upgrades.

sudo apt-get install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades

Alternatively, you can use the root crontab method.

sudo su
crontab -e
0 0 * * 0 apt-get update && sudo apt-get dist-upgrade -y

Final tweaks