tly
Posts: 4
Joined: Wed Mar 01, 2017 2:43 pm

Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 2:46 pm

Recieved my Zero W this morning. Since the Zero W has WiFi on board, is there any way of performing a 'truly' headless, non-interactive setup?

I tried writing Raspbian Lite onto an SD card, sticking it in and powering it on, but nothing happens (the OS doesn't even 'expand', just stays as a bunch of bootable files) - presumably it's waiting for some kind of user input?

I mean, I'm going to find out in 4 hours' time when I get home from work anyway, but it would be quite cool if this was possible.
Last edited by tly on Wed Mar 01, 2017 2:49 pm, edited 1 time in total.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5343
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 2:49 pm

If you flash the latest image, there is no input required. You will probably want to drop a file named 'ssh' on the boot partition, along with you wpa_supplicant.conf in order to enable ssh and automatically connect to wifi on boot.

tly
Posts: 4
Joined: Wed Mar 01, 2017 2:43 pm

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 2:52 pm

ShiftPlusOne wrote:If you flash the latest image, there is no input required. You will probably want to drop a file named 'ssh' on the boot partition, along with you wpa_supplicant.conf in order to enable ssh and automatically connect to wifi on boot.
That's what I'd like to do, but after writing the Raspbian image to the card, this is what is on the card:
Image
I'm expecting that to somehow (magic?) turn into a proper installation of Raspbian - I thought it might install if I booted the device up and left it for 20 mins, but no such luck - it just stays as above. Should I just stick my ssh and wpa_supplicant.conf files in here?
Attachments
sd.png
sd.png (49.19 KiB) Viewed 30169 times

tly
Posts: 4
Joined: Wed Mar 01, 2017 2:43 pm

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 3:41 pm

Seems to be the same hurdle as viewtopic.php?f=91&t=175736

fruitoftheloom
Posts: 17665
Joined: Tue Mar 25, 2014 12:40 pm

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 3:58 pm

tly wrote:Seems to be the same hurdle as viewtopic.php?f=91&t=175736
Windows NT 5.x and later natively will only see the first partition of the SD Card which is either formatted FAT16 or FAT32.

Boot you Windows machine with a Linux LiveCD or LiveUSB and work in a Linux environment which will have no issues or foibles with SD Cards ;)
Adieu

tly
Posts: 4
Joined: Wed Mar 01, 2017 2:43 pm

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 4:06 pm

Ah, that makes more sense! Thanks.

Since I'm at work, that translates strongly as "just wait until you get home" :lol:

W. H. Heydt
Posts: 9099
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 4:52 pm

fruitoftheloom wrote:
tly wrote:Seems to be the same hurdle as viewtopic.php?f=91&t=175736
Windows NT 5.x and later natively will only see the first partition of the SD Card which is either formatted FAT16 or FAT32.

Boot you Windows machine with a Linux LiveCD or LiveUSB and work in a Linux environment which will have no issues or foibles with SD Cards ;)
Or use an adapter to allow another Pi to make changes to the SD card...

DirkS
Posts: 9248
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Pi Zero W: Truly headless setup?

Wed Mar 01, 2017 9:06 pm

Eh....?

The two files go in the BOOT directory, not the ROOT directory.
So you *can* add these on a Windows machine, because that's exactly what's visible / accessible on a Windows PC.
tly wrote:
ShiftPlusOne wrote:If you flash the latest image, there is no input required. You will probably want to drop a file named 'ssh' on the boot partition, along with you wpa_supplicant.conf in order to enable ssh and automatically connect to wifi on boot.
That's what I'd like to do, but after writing the Raspbian image to the card, this is what is on the card:
Image
I'm expecting that to somehow (magic?) turn into a proper installation of Raspbian - I thought it might install if I booted the device up and left it for 20 mins, but no such luck - it just stays as above. Should I just stick my ssh and wpa_supplicant.conf files in here?
Write the image on your windows machine. Then, to enable SSH and configure WIFI automagically, you need to add the files @Shiftplusone (first reply) mentions to this partition.
After that you put the card in the Pi and start it.
No additional installation is done on the Pi, it should boot in about 30 seconds or so (or even less) and then it's ready to go.

chrisgjohnson
Posts: 5
Joined: Tue Aug 20, 2013 11:06 pm

Re: Pi Zero W: Truly headless setup?

Fri Mar 10, 2017 12:04 am

I've just followed this advice and can ping the Pi Zero W over wifi. But when attempting to SSH into [email protected] (or [email protected]) I get the error "Read from socket failed: Connection reset by peer". Googling suggests that this relates to SSH key settings, but the suggested fixes I have seen all involve using a local terminal. This I cannot do, since I don't have any capability to log in to the Pi Zero W other than through ssh over wifi.

Any suggestions of what changes could be made on the SD card to configure SSH properly?

User avatar
Paul Webster
Posts: 755
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK

Re: Pi Zero W: Truly headless setup?

Fri Mar 10, 2017 4:40 am

chrisgjohnson wrote: Any suggestions of what changes could be made on the SD card to configure SSH properly?
See viewtopic.php?f=28&t=176864

chrisgjohnson
Posts: 5
Joined: Tue Aug 20, 2013 11:06 pm

Re: Pi Zero W: Truly headless setup?

Fri Mar 10, 2017 11:20 am

Thanks, but this wasn't the issue. SSH was enabled with the appropriate files on the SD card, but the keys were faulty for some reason.

As in the linked post, I ended up re-imaging the SD card, and had success. Its possible that it may have been a marginally more up-do-date rasbian distro the second time around, but one thing I did differently was to not turn on the pi prior to adding the ssh and wpa_supplicant files. (I wonder if somehow at first boot invalid keys are generated if no network is available?)

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5343
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Pi Zero W: Truly headless setup?

Fri Mar 10, 2017 12:39 pm

On first boot, how did you power it off and after how long?

lafalken
Posts: 7
Joined: Mon Feb 18, 2013 7:15 pm

Re: Pi Zero W: Truly headless setup?

Fri Aug 11, 2017 12:57 pm

Hi!
This is a strange thing. Have anyone really got the Zero W to show up in the net by only adding ssh and the wireless info file?

That did not work out here. I had to hock up a keyboard and screen to do some adjustments. The key in my case was to set Sweden in wireless in raspi-config. After that and a reboot i could read on the screen what ip it got, but unless all other computers it does not show up in Fing where I see all other computers connected to my router.

I guess it must be something with the wireless info file. But does not know how to solve that. Anyone who have the right fix?

Thanks

Leilf

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5343
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Pi Zero W: Truly headless setup?

Fri Aug 11, 2017 2:09 pm

Without posting your password, what does your wpa_supplicant.conf look like?

tony1812
Posts: 350
Joined: Sat Jul 15, 2017 12:40 pm
Location: Boston MA.

Re: Pi Zero W: Truly headless setup?

Fri Aug 11, 2017 2:36 pm

I just got two! I love it. Yes, after you install Raspbian, juat make sure you have VNC set up. I also set up afp for file transfer. No need for extra display, keyboard... :)

User avatar
HawaiianPi
Posts: 2904
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pi Zero W: Truly headless setup?

Sat Aug 12, 2017 4:35 am

Writing a Raspbian image to an SD card with Etcher will result in 2 partitions. The first partition (labelled boot) is a tiny Windows readable FAT32 partition. The second partition will expand to fill the card and is formatted with the Linux ext4 file system which Windows can't read by default (you will only see the tiny FAT32 partition in Windows).

So after writing a Raspbian image your Windows (or Mac) computer will only see a tiny SD card called boot. And when people say to put the "ssh" and "wpa_supplicant.conf" files into /boot, they are referring to the tiny FAT32 partition (not a folder named boot).

So this is how you setup a Pi for headless boot.

1. Grab the latest Raspbian image. Lite is usually preferred for headless, but either version will work (don't use NOOBS).

2. Get the Etcher application and use that to write the image to your SD card (no need to extract it from the archive, just write it).

3. Create an empty file named ssh (or ssh.txt) on the SD card (on the tiny FAT32 partition, which is all Windows can see).

4. If you want to automatically connect to your wireless router (WiFi), place another file on the SD card. That file should be called wpa_supplicant.conf and it should contain the following info.

Code: Select all

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"
}
EDIT: The minimal wpa_supplicant file above won't work with Raspbian Stretch, so use the full information in the example below.

5. That's it! Boot that card in your Pi and it will be ready for SSH connections.


Note that when you set up the wpa_supplicant.conf file using the GUI it will look like this:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"
	key_mgmt=WPA-PSK
}
But all you really need is what I included above (for Jessie, with Stretch you need all the info).

If for some reason something goes wrong and you are forced to power cycle the Pi, you may need to start over (that can mess up key generation).
lafalken wrote:
Fri Aug 11, 2017 12:57 pm
Hi!
This is a strange thing. Have anyone really got the Zero W to show up in the net by only adding ssh and the wireless info file?

Works for my PiZero with a wireless USB dongle.
Last edited by HawaiianPi on Sat Oct 07, 2017 8:57 am, edited 5 times in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Pi Zero W: Truly headless setup?

Sat Aug 12, 2017 4:56 am

HawaiianPi wrote:
Sat Aug 12, 2017 4:35 am

Lite is usually preferred for headless

Create an empty file named ssh (or SSH) on the SD card (on the tiny FAT32 partition, which is all Windows can see).

Code: Select all

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"
	key_mgmt=WPA-PSK
}
But all you really need is what I included above.
@HawaiianPi
-1- why lite for headless?
headless means possibly remote...
but operation from win7 PC via putty must not be all,
i love VNC / RASPBIAN desktop

-2- the ssh file trick
file name can be
ssh
or
ssh.txt
BUT NOT
SSH ( or can you confirm that it works too now? )

-3- your first wpa_supplicant.conf
misses a "}"

-4- the second copy of your full wpa_supplicant.conf
is the point here for the OP,
he loaded ( a unknown) wpa_supplicant.conf
and say he needed add to do the sudo raspi-config wpa country thing
( what just sets that country line in wpa_supplicant.conf )
and i understand that then WIFI login worked
( but mobile APP fing NOT SHOW IT ?)

so we need some insight what that line does ( to a router? )
Last edited by KLL on Sat Aug 12, 2017 6:30 am, edited 1 time in total.

User avatar
HawaiianPi
Posts: 2904
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pi Zero W: Truly headless setup?

Sat Aug 12, 2017 5:17 am

KLL wrote:
Sat Aug 12, 2017 4:56 am
-2- the ssh file trick
file name can be
ssh
or
ssh.txt
BUT NOT
SSH ( or can you confirm that it works too now? )

-3- your first wpa_supplicant.conf
misses a "}"
Thanks for catching my 2 typos. Fixed in my post above (actually, SSH should work, but I had forgotten about ssh.txt).

I have used both the full wpa_supplicant.conf and the minimal one with only the SSID & passphrase and it always worked either way with Raspbian Jessie. I suppose having no country code could be better than the wrong one, but I have never tested that. The minimal wpa_supplicant.conf no longer works with Raspbian Stretch, so use the full one with Stretch and later versions of Raspbian.

You can copy the wpa_supplicant.conf file from another Pi that has been configured to your WiFi and that would work as well.
Last edited by HawaiianPi on Sat Oct 07, 2017 9:00 am, edited 1 time in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Pi Zero W: Truly headless setup?

Sat Aug 12, 2017 5:39 am

# Country code
# The ISO/IEC alpha2 country code for the country in which this device is
# currently operating.
#country=US
Setting the regulatory domain

You can add a line to your wpa_supplicant configuration file which specifies the ISO / IEC 3166 country code. This is available as of wpa_supplicant version 0.6.7.

country=US
regulatory domain what does that mean?

p.s.
FING lists a time zone for the router,
but no country code for the router or the RPIs
my router is configured to "thailand"
all RPIs wpa_supplicant.conf are on country=GB
never had a problem.

also it looks like FING even after restart shows only old info, you must press the rescan button ( arrowed circle top right )
Image

User avatar
davidcoton
Posts: 3198
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Pi Zero W: Truly headless setup?

Sat Aug 12, 2017 9:18 am

KLL wrote:
Sat Aug 12, 2017 5:39 am

regulatory domain what does that mean?

p.s.
FING lists a time zone for the router,
but no country code for the router or the RPIs
my router is configured to "thailand"
all RPIs wpa_supplicant.conf are on country=GB
never had a problem.

regulatory domain is the area you live in, and the associated rules for WiFi transmissions.
It is important to set it correctly, otherwise you may have unfriendly government officials knocking on your door.
The computer setting must match the router setting.
The correct code for Thailand is TH. I haver no idea how the regulations in Thailand differ from GB.
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

IOC
Posts: 1
Joined: Fri Oct 06, 2017 3:25 pm

Re: Pi Zero W: Truly headless setup?

Fri Oct 06, 2017 4:27 pm

I ran into an interesting/annoying issue.

Creating the wpa_supplicant.conf file as above, my Pi zero W wouldn't connect to my network. I checked and repeated many times to no avail. So I connected the Pi to a monitor and keyboard and inspected the wpa_supplicant.conf file using

Code: Select all

sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
This showed the problem: the quotation marks around the ssid and psk values I entered weren't quotation marks. They were a square blob instead. Well, that would explain the connection fail...but WTH?

Trying to fix this using

Code: Select all

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
revealed the root cause. When I typed shift-" it produced the @ symbol on the monitor. Hmm...

A bit of poking around the forums suggested it's a British vs. US keyboard issue. I'm in the US & bought my Pi in the US but apparently got a British Pi with British keyboard settings. The short fix was to type [email protected] since this produces a quotation mark. I updated and saved the wpa_supplicant.conf file using this kluge, rebooted, and everything connected fine.

There are ways to reconfigure the keyboard settings interactively (see, e.g. https://thepihut.com/blogs/raspberry-pi ... ard-layout) but then the set up isn't headless. Does anyone know if there's a way to configure the keyboard by setting a parameter in the boot files?

User avatar
DougieLawson
Posts: 34167
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Pi Zero W: Truly headless setup?

Sat Oct 07, 2017 6:35 am

IOC wrote:
Fri Oct 06, 2017 4:27 pm

A bit of poking around the forums suggested it's a British vs. US keyboard issue. I'm in the US & bought my Pi in the US but apparently got a British Pi with British keyboard settings. The short fix was to type [email protected] since this produces a quotation mark. I updated and saved the wpa_supplicant.conf file using this kluge, rebooted, and everything connected fine.
ALL Raspberries are British but that's irrelevant. There are no hardware settings, there's no BIOS.

ALL settings are done in software and the default for Raspbian (because it's Made in Britain) is that it is configured for a UK keyboard.

There's a simple option in the GUI settings menu or in sudo raspi-config to set your timezone, your locale (silly American date format) and WiFi country. Or you can open an LXTerminal window and run sudo dpkg-reconfigure keyboard-configuration && sudo reboot to set your American keyboard layout.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
HawaiianPi
Posts: 2904
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pi Zero W: Truly headless setup?

Sat Oct 07, 2017 9:11 am

IOC wrote:
Fri Oct 06, 2017 4:27 pm
I ran into an interesting/annoying issue...

A bit of poking around the forums suggested it's a British vs. US keyboard issue.
I think the assumption was that people setting up a headless boot would be creating the wpa_supplicant.conf file on their main Windows or Mac PC (which should already be configured with the correct keyboard layout) or copying the file from another Pi that was already configured.

As Dougie said, the Raspberry Pi is a British product. Doesn't matter where you bought it (or even where it was made), the country configuration is in the Raspbian or NOOBS software, not the hardware.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
Paul Webster
Posts: 755
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK

Re: Pi Zero W: Truly headless setup?

Sun Oct 08, 2017 6:55 am

IOC wrote:
Fri Oct 06, 2017 4:27 pm
This showed the problem: the quotation marks around the ssid and psk values I entered weren't quotation marks. They were a square blob instead. Well, that would explain the connection fail...but WTH?
My guess is that you created the supplicant file on a different machine and used an editor that used word processing style open/close quotation marks rather than the simple ASCII version.

User avatar
davidcoton
Posts: 3198
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Pi Zero W: Truly headless setup?

Sun Oct 08, 2017 8:07 am

AIUI the keyboard country setting only applies to the local keyboard. So if you are truly running headless, you don't need to set it; and if you need to set it, you have a keyboard available.
Paul Webster wrote: My guess is that you created the supplicant file on a different machine and used an editor that used word processing style open/close quotation marks rather than the simple ASCII version.
+1. If the problem was a keyboard mismatch, the character that showed up would be something normal and printable, even if not what was expected.
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

Return to “Beginners”