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


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


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 >> ~/log/freedns.log 2>&1


Load the default configuration with the setup script.

curl -L | bash

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

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


Load the default configuration with the setup script.

curl -L | 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=, XXX, Note here that is the address for Pi-Hole.


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


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