Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Installing Raspbian on headless RPi4 - how?

Fri Jul 05, 2019 11:35 am

I have ordered a new RPi4 with 4 GB RAM and will get it today.
But I do not have a monitor to hook up to the RPi during installation (micro HDMI connectors only) and it is going to be used as a headless server type computer.
So how can I set up the RPi4 from scratch without a monitor attached?
Once it is up and running I will only interact via ssh (PuTTY from Windows 7).

Previously I have briefly hooked up my RPi units to my main monitor using HDMI and attached a USB keyboard to work with it during initial setup so I can enable ssh, but that will not work this time....
Bo Berglund
Sweden

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

Re: Installing Raspbian on headless RPi4 - how?

Fri Jul 05, 2019 11:40 am

Write plain Raspbian to your SDCard with etcher.
Re-insert it in your Windows machine.

open cmd.exe and run
echo "" > f:\ssh.txt

Use notepad++ to create f:\wpa_supplicant.conf

Code: Select all

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="your WiFi service set ID here"
        psk="your WiFi password here"
}


Eject the card from Windows and when it boots it will connect to your WiFi and will have ssh active.
Change the pi user's password on first logon.
Grab a beer and celebrate a job well done.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Floxi
Posts: 1
Joined: Fri Jul 05, 2019 11:45 am

Re: Installing Raspbian on headless RPi4 - how?

Fri Jul 05, 2019 12:10 pm

Just FYI f:\ in Dougie's reply is the partition labeled "boot" on your SDcard after burning the Raspbian image. Just move the two files he mentioned to its root. (the actual path is different from machine to machine)

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Fri Jul 05, 2019 12:17 pm

Thanks a lot!

One additional question:
I am using a Swedish keyboard layout and Swedish time and date settings on an otherwise English system.
When I normally set up my RPi units while connected to a monitor I get to say which country and keyboard layout to use as well as the language. How can this be done in my situation this time with no monitor?
If the system installs ans configures autonomously I guess the defaults would be British settings?
So that will be already done when I get a chance to connect by ssh....

Or is this no longer how it works?
Bo Berglund
Sweden

User avatar
rpdom
Posts: 15353
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Installing Raspbian on headless RPi4 - how?

Fri Jul 05, 2019 12:38 pm

Once your Pi has booted and finished it's standard set up stuff (expand file system etc) which can take a few minutes and an automatic reboot, connect to it with ssh (PuTTY or similar on Windows) and run "sudo raspi-config". You can then set up the country information like time zone and stuff and other options (not the keyboard layout, but that doesn't matter if you are logged in with ssh).

User avatar
rin67630
Posts: 568
Joined: Fri Mar 04, 2016 10:15 am

Re: Installing Raspbian on headless RPi4 - how?

Mon Jul 08, 2019 6:28 pm

DougieLawson wrote:
Fri Jul 05, 2019 11:40 am
Write plain Raspbian to your SDCard with etcher.
Re-insert it in your Windows machine.

open cmd.exe and run
echo "" > f:\ssh.txt
...
Doug's answer needs imho some clarification!

Once you have created the SD Card with Etcher, insert it into the Windows machine.
You will see a FAT partition (boot) and get errors for the EXT4 partition asking you to format the partition. Do not do that!
Windows cannot cope with the ext4 partition, but that does not matter for us.

On the fat partition (drive letter may be another one than F:) create a file named ssh or ssh.txt it can remain empty, only the presence of the file matters.

Create a file named wpa_supplicant.conf and edit the content accordingly:

Code: Select all

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="your WiFi service set ID here"
        psk="your WiFi password here"
}
Enter your country code in capitals, your ssid and your password.
Edit the file with notepad, notepad+ or another programming editor, NOT Word!
DO NOT put spaces around the = signs!

Eject the sd card and put it into the Raspi, power it and cross fingers.

SSH your new system with the system name "raspberry" if you have Windows 10 or have a bonjour or avahi deamon installed.
Else get the IP address from the DHCP information of your router.
Finding the IP address with the router is the best method anyway, so you know that the WLAN match succeeded.

Of course if you have got a raspi 4, starting with a wired Ethernet connection is always better than WiFi.

Enjoy your beer...

P.S. the keyboard layout never matters if you are headless.

Andyroo

Re: Installing Raspbian on headless RPi4 - how?

Mon Jul 08, 2019 9:31 pm

You need to ssh into raspberrypi or raspberrypi.local if you cannot identify the IP address not raspberry (that being the default password for user pi) :lol:

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Mon Jul 08, 2019 10:37 pm

Thanks all!
I got this going by creating the ssh file and editing the wifi supplicant file as described above.
Had some other issues so I moved to a different thread for that and forgot about this discussion, hence my absence.
Problem solved for both the RPi4 (built-in wifi works fine of course) but also for the RPi2B I also installed Buster on.
This has an Edimax WiFi USB dongle and it too connects good on startup.
Bo Berglund
Sweden

User avatar
Michiel O.
Posts: 178
Joined: Mon Dec 12, 2016 12:06 pm

Re: Installing Raspbian on headless RPi4 - how?

Tue Jul 09, 2019 6:13 pm

If you're going to use your RPi headless, you might also want to disable the graphical desktop environment from raspi-config. This makes the RPi boot faster, run faster, use less memory, run cooler, use less power, etc...

sudo raspi-config -> Boot Options -> Desktop/CLI -> Console
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Tue Jul 09, 2019 6:40 pm

Michiel O. wrote:
Tue Jul 09, 2019 6:13 pm
If you're going to use your RPi headless, you might also want to disable the graphical desktop environment from raspi-config. This makes the RPi boot faster, run faster, use less memory, run cooler, use less power, etc...

sudo raspi-config -> Boot Options -> Desktop/CLI -> Console
One of them (the RPi2B) was installed using the Lite version of the image because it will only ever be used as a server.
The other one installed from a full image but I set it (in raspi-config) to boot to the CLI.
Now, however I have changed it to boot to GUI but with a logon. That was the only way I could make VNC work.
It is the RPi4B 4GB box I just bought in order to explore. I have no real target for it yet.
Bo Berglund
Sweden

bls
Posts: 257
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Installing Raspbian on headless RPi4 - how?

Tue Jul 09, 2019 7:43 pm

You can definitely use VNC to connect to a Pi even if it's set to boot to console. See, for example https://github.com/gitbls/RPiVNCHowTo, which documents a method for using the TigerVNC server on Raspbian. It doesn't matter whether you're booting to console or graphical, and can work with either Raspbian Lite or Full. Hope this helps.

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 6:54 am

Thanks for the link!
It seems like it describes using a different VNC server from what is included in Raspbian, though (tigervnc).
Since I have RealVNC now running I may stay with that, but I have one additional question regarding the shipped-with-raspbian-vnc:

How can I adjust the window size of the displayed screen?
So far the only way I have found is to set the Pi itself via raspi-config to one of the very few resolutions available...
I have used another vnc solution in the past (maybe tightvnc) and there I could define any screen size I like in the configuration file or startup script (don't remember which).
As it is I have a PC screen 1920x1080 and I would like to use a vnc size of say 1440x900 so I can work within while still having fair access to the Windows desktop. But that is not available in raspi-config....
Bo Berglund
Sweden

Man in a van
Posts: 138
Joined: Sat Dec 27, 2014 2:41 pm
Location: Staffordshire, UK.

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 10:50 am

Hi Bo, this what I do, it may not be suitable for you, but, hey.. ;)

There are two parts:

Part 1.

ssh into the pi
sudo raspi-config
Advanced Options (7)
Resolution (5)
Choose one of the 16:9 configurations
I use the largest, 1920x1080
exit and reboot

Part 2.

Open a VNC connection on the pi

Navigate to

Menu > Preferences > Screen Configuration > Screen Layout Editor > Confgure > Screens > Resolution > Choose the configuration you enabled

Return to Configure > Click Apply > OK


If this screen is too big you can reduce the size by dragging a corner/side inwards

i hope this helpful

Ronnie

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 11:32 am

Man in a van wrote:
Wed Jul 10, 2019 10:50 am
Part 2.
Open a VNC connection on the pi
Navigate to
Menu > Preferences > Screen Configuration > Screen Layout Editor > Confgure > Screens > Resolution > Choose the configuration you enabled
Return to Configure > Click Apply > OK

If this screen is too big you can reduce the size by dragging a corner/side inwards
I hope this helpful

Ronnie
I get too few resolutions to select from in the last step:
1920x1080 (too big for my 1920x1080 monitor)
1020x768 (too small)
800x600
848x480
640x480

What I need is something like 1440x800 or better yet 1600x900.
With TightVNC (which I used on Jessie) I got to put any value as resolution I wanted into the configuration...

Changing the too big screen size by pulling the borders just hides part of the screen and adds scrollbars, not so good.
Bo Berglund
Sweden

User avatar
sconemad
Posts: 230
Joined: Thu Apr 28, 2016 1:47 pm
Location: Cambridge, UK
Contact: Website

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 2:05 pm

VNC Server can run in two modes: service mode and virtual mode.

Service mode is what you get when you enable VNC via raspi-config, which lets you access the Pi's console screen remotely (i.e. what you would see if you had a monitor plugged in). If you don't have a monitor plugged in, it doesn't know what resolution to use on the console, so you would need to configure it manually via raspi-config. As you have seen, the list of possible resolutions offered is quite small. Others are actually available, but you would need to go and edit /boot/config.txt yourself and enter the right hdmi_group and hdmi_mode according to the tables here:
https://www.raspberrypi.org/documentati ... t/video.md

An alternative would be to use Virtual mode, which creates an in-memory desktop that you can only access over VNC. This is started via the "vncserver' command, as described here:
https://www.realvnc.com/en/connect/docs ... pi-virtual
The resolution can be specified on the vncserver command line, using "-geometry WxH", and is not restricted (within reason).
It's possible to create multiple VNC Virtual desktops, and each is allocated a unique display number, starting from :1, which it will tell you in the output of the vncserver command. You must append this to the hostname or IP address when connecting in order for it to connect to the correct desktop (":0" or blank means connect to the Service mode server).

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 3:14 pm

Thanks!
I will test this ASAP!
My use case is normally to go to the RPi desktop via VNC, never to connect a cable to a monitor.
So the "virtual" mode is probably exactly what I need! :D

Most of my RPi units are working as servers in some setting and I only use the CLI interface via PuTTY.
Some of them, though, I use as development platform using FreePascal and Lazarus and for these I need the desktop via VNC.
And I want to be able to set a suitable size so it can co-exist on my PC desktop while still being fairly usable fora dev IDE.
Bo Berglund
Sweden

davesteele
Posts: 59
Joined: Wed Nov 30, 2016 4:16 pm

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 5:31 pm

Take a look at Comitup. i just tried it on a 4.


https://davesteele.github.io/comitup/

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 5:31 pm

I have started a new instance of vncserver with a specified desktop size1400x900 as shown by the process list:

Code: Select all

 $ ps aux|grep vncserver
root       442  0.0  0.0   8360  2116 ?        Ss   18:15   0:00 /usr/bin/vncserver-x11-serviced -fg
root       457  0.0  0.3  29960 14036 ?        S    18:15   0:01 /usr/bin/vncserver-x11-core -service
root       581  0.0  0.0   9932  3068 ?        Ss   18:15   0:00 vncserver -randr=1400x900  <== THIS!
root       622  0.0  0.3  31732 12580 ?        S    18:15   0:00 /usr/bin/vncserverui virtual 12
root       674  0.0  0.3  31400 14956 ?        S    18:15   0:00 /usr/bin/vncserverui -statusicon 5
pi        1221  0.3  0.3  31768 12704 ?        S    19:17   0:00 /usr/bin/vncserverui service 15
pi        1243  0.1  0.3  31396 14260 ?        S    19:17   0:00 /usr/bin/vncserverui -statusicon 5
In fact I put this into the /etc/rc.local so it would always be done on startup.

However, when I try to open it in RealVNC I get to a login screen where I enter the pi/pipassword combination.
But then I get a dialog box saying:
VNCViewer
Access is denied

So somehow I am not allowed to log in to the vnc screen in this situation...

Question:
I did not change the VNC setting in raspi-config, do I have to disable the VNC service in raspi-config?
Bo Berglund
Sweden

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 6:12 pm

Bosse_B wrote:
Wed Jul 10, 2019 5:31 pm
In fact I put this into the /etc/rc.local so it would always be done on startup.
Now I commented out that line in rc.local and instead after a reboot I logged in with PuTTY and executed this command:
$ vncserver -randr=1400x900

Then I went back to RealVNC and used the connection that was not allowed before, but this time it did connect and I now have the 1400x900 desktop I was looking for.

So how can I make the vncserver command run at boot time such that I can then connect via VNC?
To me it seems like the instance running from rc.local might define a window only for root, whereas the one I started myself is for pi...
Can this be the case for the disallowed connection?

Notice that on Raspbian Stretch (on another RPi3 I have available here) I have the same entry in rc.local but in that case I can connect just fine. Something has changed with Buster????
Bo Berglund
Sweden

Bosse_B
Posts: 834
Joined: Thu Jan 30, 2014 9:53 am

Re: Installing Raspbian on headless RPi4 - how?

Wed Jul 10, 2019 8:06 pm

SOLUTION FOR STARTING VNC
I fixed my problem of how to start the vncserver process on boot by adding this to crontab:

Code: Select all

@reboot sleep 120 && /usr/bin/vncserver -randr=1400x900 
This makes the pi user run vncserver 2 min after boot and then it will be possible to log in via VNC to the virtual desktop.
Bo Berglund
Sweden

Return to “Raspbian”