Quick headless setup for the Raspberry PI
Setup a headless image before you dd it on your SD card. Only needed step is to enable ssh, the rest is convenience, if you must use wifi for example. Works for pi zero, pi3, pi2... Perform as root.
Look at the AutoRpi automatic headless image maker if you dont want to spend time doing it by hand
Enable SSH
Add a file named ssh in the boot partition of the image :
mount -o loop,offset=$((8192 * 512)) /storage/2017-01-11-raspbian-jessie-lite.img /media/
Mount boot partition from image
echo > /media/ssh
Enable ssh
Remove automatic resize/filling of the sd card on 1st boot
Useful if you want to setup a multi boot.
nano /media/cmdline.txt
Assuming image is still mounted from previous step
Remove the stuff after quiet and it looks like that :
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet
umount /media/
Extend size of the partition
Add 1go of space to your image, you can repeat command to add more or edit count= :
dd if=/dev/zero bs=1M count=1024 > /storage/2017-01-11-raspbian-jessie-lite.img
Run parted parted /storage/2017-01-11-raspbian-jessie-lite.img
Then type resizepart 2
Enter 100%
Enter quit
Enter
Check with fdisk -lu /storage/2017-01-11-raspbian-jessie-lite.img
Change keyboard layout
mount -o loop,offset=$((137216 * 512)) /storage/2017-01-11-raspbian-jessie-lite.img /media/
nano /media/etc/default/keyboard
Edit XKBLAYOUT="gb"
to XKBLAYOUT="fr"
or anything else
Change default password
makepasswd --clearfrom=- --crypt-md5 << YOURPASSWD
Encrypt your password
nano /media/etc/shadow
Remove this line pi:$6$k0vFWRoG$bEBdFcFBWw2fLEA.5LsVKOtLWdWSkZMnEikqOG4jHCneRrWEBnEt6.ROe60ggdA7DbdU.l2ZO35WFvi3q6Ays/:17130:0:99999:7:::
Replace with pi:YOURMD5PASSWD:17130:0:99999:7:::
Enable wireless connectivity
Particularly useful on the rpi0, since it has no rj45.
nano /media/etc/network/interfaces
Then replace :
allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
With
auto wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
nano /media/etc/wpa_supplicant/wpa_supplicant.conf
Then add :
For WEP
network={ ssid="NAMEOFYOURAP" wep_key0=PASSPHRASE key_mgmt=NONE wep_tx_keyidx=0 priority=2 }
For WPA
network={ ssid="NAMEOFYOURAP" psk="PASSPHRASE" priority=1 }
For open network
network={ ssid="NAMEOFYOURAP" key_mgmt=NONE priority=0 }
You can add as much as you want and sort them with priority=