RPi Zero - headless mode

I received my first RPi Zero yesterday, I was super stoked, but only had time to open it today.

This will be a multi-part tutorial on my findings and setups. This will start off with the basics on getting it up and running headless.

I will cover the USB Gadget API Framework, minimal unattended netinstaller and USB OTG connector and in a later post.

This will focus on the headless setup and configuration of a clean Zero. I will start with Raspbian Lite a I am on the road and have nothing but a MBP and my Zero.

The quick and dirty way

(No USB keyboard, mouse, HDMI monitor needed)

I will be using the following:

  • Macbook Pro (macOS Sierra 10.12.4)
  • microSD card
  • RPi Zero
  • MicroUSB to USB Cable

More details:

Lets firstly enable ssh and edit the config.txt to set the DesignWare HS OTG USB controller to use the ethernet module.

sudo touch /Volumes/boot/ssh  
sudo echo "dtoverlay=dwc2" >> /Volumes/boot/config.txt  

Now edit cmdline.txt

sudo vi /Volumes/boot/cmdline.txt  

And add this after "rootwait"

modules-load=dwc2,g_ether  

Unmount the microSD card, place it in the RPi.

Plugin the first USB cable into the PWR socket, then plug the second into the USB. Normally it takes about 60 seconds, dependent on your image.

If all went well you should ssh access to raspberrypi.local via USB.

ssh pi@raspberrypi.local  

Extras

After a new install there are a few things you're probably going to want to do, I only use headless servers, so here are some of my mods:

Package update and upgrade

sudo apt-get update  
sudo apt-get upgrade -y -o Dpkg::Options::="--force-confold"  

Other packages

sudo apt-get install -y rpi-update raspi-config lsb-release  

f2fs-tools

RPi kernel update

sudo BRANCH=next rpi-update  

Disable IPv6

sudo echo "blacklist ipv6" > /etc/modprobe.d/ipv6.conf  

Disable display manager service

sudo systemctl disable display-manager.service  

Boot up into multi-user mode

sudo systemctl set-default multi-user.target  

List all open ports

netstat -lnpt

Disable HDMI

sudo vi /etc/rc.local  

add before exit();

/usr/bin/tvservice -o

Backup / Restore SD card images

I you would like backup and compress your RPi image you can use the following:

sudo dd if=/dev/rdisk4 bs=1m | gzip > ~/RPi-backup.gz  

Restore from a compressed backup as follows:

gzip -dc ~/RPi-backup.gz | sudo dd of=/dev/rdisk4 bs=1m  

Uncompressed would be:

sudo dd if=/dev/rdisk4 of=~/RPi-backup2.img bs=1m  
sudo dd if=~/RPi-backup2.img of=/dev/rdisk4 bs=1m  

flash

diskutil list  
diskutil unmountDisk /dev/disk#  
sudo dd bs=1m if=image.img of=/dev/rdisk#