[go: up one dir, main page]

0% found this document useful (0 votes)
233 views8 pages

Raspberry Pi Zero Headless Setup

The document provides instructions for setting up a Raspberry Pi Zero to connect to WiFi without a monitor or keyboard by editing configuration files on the SD card using another Linux system. It describes installing an OS image, mounting the SD card, configuring the network and WiFi settings, then remotely accessing the Zero over SSH once it boots.

Uploaded by

Juan González
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
233 views8 pages

Raspberry Pi Zero Headless Setup

The document provides instructions for setting up a Raspberry Pi Zero to connect to WiFi without a monitor or keyboard by editing configuration files on the SD card using another Linux system. It describes installing an OS image, mounting the SD card, configuring the network and WiFi settings, then remotely accessing the Zero over SSH once it boots.

Uploaded by

Juan González
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Raspberry Pi Zero Headless Setup https://davidmaitland.

me/2015/12/raspberry-pi-zero-headless-setup/

(https://davidmaitland.me)

Photography, Code & Linux

Raspberry Pi Zero Headless Setup ()


01 Dec 2015

1 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

So last Thursday (26th Nov 2015) the Raspberry Pi Zero (https://www.raspberrypi.org


/blog/raspberry-pi-zero/) was announced and made available that very day. Basically the
Zero is a small and ultra cheap (£4 (https://shop.pimoroni.com/products/raspberry-
pi-zero)) fully functioning Raspberry Pi, but it doesn't have any native networking and has
only one USB port (which you need an OTG adapter to use).

In the UK I was lucky enough to be able to order two Pi Zero's and have them delivered the
next day. The only problem was I didn't have an HDMI monitor or a USB hub to connect a
keyboard and a WiFi adapter at the same time. My intended use for the Zero's is for them
to be little headless Linux boxes that I can put into various electronic projects and program
them over WiFi (Think IoT (https://en.wikipedia.org/wiki/Internet_of_Things)), so I didn't
want to mess around with HDMI and GUI interfaces.

So here is a little guide showing you how to setup a Raspberry Pi Zero without an HDMI
monitor or a keyboard / mouse. We will just use a USB WiFi adapter (connected to the OTG
USB port) and a Linux machine to do the setup. If you don't have a Linux machine
available, you could even use another Rasberry Pi with a card reader to set this up.

This should be possible to do on other platforms as well but you will need to be able to
mount an Ext4 partition natively.

Step One - Install the Linux image

2 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

Blog
First you(/)will need
Aboutto(/about
install)a copy of Raspbian Jessie onto your micro SD card. You can
find the downloads here (https://www.raspberrypi.org/downloads/raspbian/) and the
GitHub (https://github.com/davidmaitland
installation guides are on the same page as)well. For Linux I will be using this
(https://www.raspberrypi.org/documentation/installation/installing-images/linux.md)
Twitter (https://twitter.com/DavidMaitland )
guide.

Instagram (https://instagram.com/davidmaitland )
Step Two - Mounting it locally
500px (https://500px.com/DavidMaitland )
After you have copied the Raspbian image onto the SD card you will need to mount it to
your system. The easiest way to do this is just unplug your card reader and plug it back in.

Once the drive has mounted to your system you will need to find where it has mounted. An
easy way to do this is using the command df -h . For example for me it returns:

Filesystem Size Used Avail Use% Mounted on


/dev/mapper/fedora_dhcppc8-root 25G 9.8G 14G 43% /
/dev/sda1 477M 258M 190M 58% /boot
/dev/mapper/fedora_dhcppc8-home 85G 24G 58G 29% /home
/dev/sdc1 60M 20M 41M 34% /run/media/davidmaitland/bo
ot
/dev/sdc2 59G 3.4G 53G 6% /run/media/davidmaitland/ad
6203a1-ec50-4f44-a1c0-e6c3dd4c9202

I can see from this my 64GB SD card is the device /dev/sdc and the boot and main
partition are mounted under /run/media/davidmaitland/ . Change directory into the main
partition as root ready to edit the files. This is likely to be the same drive that was
referenced during the image installation earlier.

[user@linux ~]# sudo su


[root@linux ~]# cd /run/media/davidmaitland/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202
[root@linux ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202]# ls
bin boot boot.bak dev etc home lib lost+found media mnt opt proc root
run sbin srv sys tmp usr var

Step Three - Configure your WiFi

Next we're going to configure the network interface. Edit the interfaces file
etc/network/interfaces . Pay attention to the path in the files I reference, there is no
leading slash as you want to edit the files on your SD card and not the ones on your host
system!

3 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

Blog (/)not sure


If you're About (/about
how to edit) files on Linux, try nano etc/network/interfaces then
Ctrl + x to save when done.
GitHub (https://github.com/davidmaitland )
Find this block in the file:
Twitter (https://twitter.com/DavidMaitland )
allow-hotplug wlan0
iface wlan0 inet manual
Instagram (https://instagram.com/davidmaitland )
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

500px (https://500px.com/DavidMaitland )
Then change it to this:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

If you want to have a static IP instead of using DHCP (easier to find once the Pi has come
up on your network) then change it to this instead:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.20 # IP for the Zero
netmask 255.255.255.0
gateway 192.168.1.1 # Your router IP
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

As pointed out by someone on Reddit, if you're using static networking you will want to
setup your DNS servers as well. Edit etc/resolv.conf and add the following:

# Google's public DNS servers


nameserver 8.8.8.8
nameserver 8.8.4.4

Now let's setup the WiFi connection and passkey. Edit the file
etc/wpa_supplicant/wpa_supplicant.conf .

Add this to the end:

4 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

network={
Blog (/) About (/about )
ssid="my network name"
psk="my network password"
GitHub
proto=RSN (https://github.com/davidmaitland )
key_mgmt=WPA-PSK
pairwise=CCMP
Twitter (https://twitter.com/DavidMaitland
auth_alg=OPEN
)
}
Instagram (https://instagram.com/davidmaitland )
Finally remove the SD card from your computer (you may wish to unmount it first) and
500px
place (https://500px.com/DavidMaitland
into your Zero. )

Step Four - Boot the Pi Zero!

Now it's time to boot the Raspberry Pi Zero. Make sure you have your WiFi adapter
plugged into the Zero and give it some power. For me it takes about 45 seconds to boot
and connect to my WiFi network.

Now you can SSH directly into your Raspberry Pi Zero!

If you configured your Zero to use DHCP you will need to find it's IP address. There are a
few ways you can do this:

Most routers will tell you somewhere in their web interfaces what IP allocations they have
assigned to devices.
You could use nmap (https://nmap.org) to scan the local network for devices running with port 22
open sudo nmap -p22 -sV 192.168.0.0/24 .
From the comments Coder-256 pointed out the default hostname for a Raspberry Pi is
raspberrypi and on most networks you can SSH directly to this instead of the IP address
ssh pi@raspberrypi.local .

The default password is raspberry .

[user@linux ~]# ssh pi@192.168.1.20


pi@raspberrypi:~ $

Extras

After a new install there are a few things you're probably going to want to do.

First I would update the software running on your Zero:

5 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

sudo apt-get update -y


Blog (/) About (/about
sudo apt-get upgrade -y
)

GitHub (https://github.com/davidmaitland )
If you're going to be using your Zero completely headlessly like me there are various things
you can do to save energy and speed up the device.
Twitter (https://twitter.com/DavidMaitland )

Boot up into multi-user


Instagram mode (disable GUI on boot) )
(https://instagram.com/davidmaitland
sudo systemctl set-default multi-user.target .

500px (https://500px.com/DavidMaitland )
To disable HDMI edit /etc/rc.local and add the following line at the bottom above
exit 0 line:

/usr/bin/tvservice -o

You may want to run sudo raspi-config to change other common Raspberry Pi settings
as well.

Let me know below if this guide was useful or if you have any suggestions!

Coffee delivered for £1 (https://pactcoffee.com/sign-up?voucher=ONEPOUNDCOFFEE)

Love coffee and live in the UK? Have some freshly ground coffee delivered to your door for
only one pound. Give Pact (http://pactcoffee.com/?voucher=ONEPOUNDCOFFEE) coffee
a try using the promo code "ONEPOUNDCOFFEE (https://pactcoffee.com/sign-
up?voucher=ONEPOUNDCOFFEE)".

6 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

81Blog
Comments
(/) DavidMaitland.me
About (/about ) 
1 Login

 Recommend 5 ⤤ Share
GitHub (https://github.com/davidmaitland )
Sort by Best

Join the discussion…


Twitter (https://twitter.com/DavidMaitland )

ben • a(https://instagram.com/davidmaitland
Instagram year ago )
does disabling the hdmi increase the potenital speed for other services on the Pi?
3 • • Reply Share ›
500px (https://500px.com/DavidMaitland )
Stijn > ben • a year ago
Yes.
Disabling unused services will limit the needed resources and power.
So you'll have more spare computing power for other stuff, and use less electricity at the
same time.
3 • Reply • Share ›

Jakub Kramarz > ben • a year ago


Yes and no in the same time: it won't affect CPU performance in any matter, but if you're
using VideoCore IV for computation (very unlikely), you may have more resources
available.
• Reply • Share ›

Joel Auterson • a year ago


Thanks for this - not having a USB keyboard to hand was the reason I'd held back on buying one
of these!
3 • Reply • Share ›

Roman • a year ago


FWIW: this didn't work for me right away, so I went on to debug wpa_supplicant and found that
it didn't like the spaces in the line "network={". Now working great!
2 • Reply • Share ›

David Maitland Mod > Roman • a year ago


Whoops, thanks for spotting this. Not sure why example shows it like that :/
• Reply • Share ›

Michael Dillon • 10 months ago


Thanks worked perfectly!
1 • Reply • Share ›

Brian • a year ago


Great guide! Thank you for posting.
1 • Reply • Share ›

Erwin • a year ago

7 de 8 31/01/2017 14:24
Raspberry Pi Zero Headless Setup https://davidmaitland.me/2015/12/raspberry-pi-zero-headless-setup/

Blog (/) About (/about )

GitHub (https://github.com/davidmaitland )

Twitter (https://twitter.com/DavidMaitland )

Instagram (https://instagram.com/davidmaitland )

500px (https://500px.com/DavidMaitland )

Copyright David Maitland 2016

8 de 8 31/01/2017 14:24

You might also like