Clean install a Raspberry Pi device

How to get a Pi up and running in less than 15 minutes.
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.

# 2018-04-18-raspbian-stretch-lite.img

diskutil list
# Look for correct disk number
diskutil unmountDisk /dev/disk3

sudo dd \
    bs=1m \
    if=2018-04-18-raspbian-stretch-lite.img \
    of=/dev/rdisk3 \

ssh is disabled by default. To enable remote access, you must write an empty file named ssh to the boot partition.

cd /Volumes/boot
sudo touch ssh

Now we’re ready to eject the disk and boot up the Raspberry Pi device.

sudo diskutil eject /dev/rdisk3
# Now safe to remove SD card

Monitor-enabled setup


Reboot and run the necessary system updates.

sudo apt-get update && sudo apt-get upgrade -y

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 -sSL | 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 upgrade -y

Final tweaks