kyso
Posts: 7
Joined: Sat Oct 01, 2016 10:42 pm

configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 12:27 am

Hi,

New pi user here, somewhat familiar with unix (I used to develop embedded C code on Sun workstations for test instruments ages ago).

Did some searching but did not come across any HOWTOs or best practices for configuring raspbian for a headless Pi 3.

I've got a project that uses a headless pi with gpio (I2C LCD, 1wire temp sensors, inputs, outputs) to sense temperature, control pump, fan, etc. and serve up web pages reporting state and settings.

I'm looking for advice/configs on:

- smallest footprint (binaries, filesystem, etc) for a headless pi 3
- fast startup (<10secs)
- fast shutdown (<1sec) without corrupting the filesystem
- web server

Any help on climbing the learning curve in these areas would be greatly appreciated!

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 6:26 am

Small footprint? You cannot buy a microSD card less than 8 GB, making small a minor problem. The same with the 1 GB memory in a Pi 3. You will only chew up the memory if you use the Ubuntu MATE instead of Raspbian.

Fast startup? Buy a microSD card faster than the cheapest cards. I use U1 and U3 cards for speed. The next speed problem can occur with some USB devices that make the OS wait. Check syslog in detail for errors and warnings. Switch off anything in there that seems irrelevant to your use. For fast and reliable remote desktop, I found x11vnc better than the alternatives.

Faster shutdown depends in part in flushing every write to disk earlier. There are posts on shrinking the Linux wait before writing to disk. Also look in syslog for any error messages during shutdown.

Web server? PHP 7 is faster than PHP 5. Lighttpd and Nginx are sometimes faster than Apache. I have not found startup or shutdown times for the three when configured to perform the same work.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 6:28 am

Are you going to time your changes? Time the default, make one change, and time the difference. Would help other people.

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

Re: configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 7:09 am

peterlite wrote:Small footprint? You cannot buy a microSD card less than 8 GB, making small a minor problem.
Is that supposed to be "buy" or "use"?

I can easily buy 4GB microSD cards for a few pounds. I also have some old 2GB and 1GB ones that I use.

Raspbian Lite will fit on a 2GB card with space to spare.

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

Re: configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 10:28 am

kyso wrote: I'm looking for advice/configs on:

- smallest footprint (binaries, filesystem, etc) for a headless pi 3
- fast startup (<10secs)
- fast shutdown (<1sec) without corrupting the filesystem
- web server
1. Jessie lite - 1.3GB unzipped
2. Remove the GUI and you're running in less than 10 secs with stock Raspbian Jessie Lite
3. It comes up fast, it goes down fast
4. Apache2, Lighttpd or NGinx - pick your poison
  • Apache2 is well used, well supported and well documented.
  • Lighty uses fewer resources than Apache2, is well used and well supported. Configuring CGI is a bit arcane, PHP is a pain.
  • NGinx uses fewer resources then Apache2, is well used and well supported. Configuring CGI needs FastCGI, PHP is a pain.
Install each one, measure them, see if you're happy with configuring them for your needs (cgi and php)
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.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Sun Oct 02, 2016 9:21 pm

"Is that supposed to be "buy" or "use"?"
Perhaps I should have said "would not buy" instead of "could not buy". In our local shops, the lowest price card is a U1 speed 8 GB card. To get a 4 GB card, I would have to shop online with the postage making the 4 GB card more expensive.

8 GB also appears to be the starting point for the U1 speed cards and 16 GB the start of U3 speed cards. I recommend U3 for the "fast startup" because the minimum speed of U3 is three times faster than U1. For speed, I would not "use" any of the 4 GB cards I see online.

jahboater
Posts: 4598
Joined: Wed Feb 04, 2015 6:38 pm

Re: configuring raspbian for a headless pi 3 best practices?

Tue Oct 04, 2016 3:59 pm

You can measure the startup time with

Code: Select all

systemd-analyze
For details see

Code: Select all

systemd-analyze blame

kyso
Posts: 7
Joined: Sat Oct 01, 2016 10:42 pm

Re: configuring raspbian for a headless pi 3 best practices?

Thu Oct 06, 2016 11:33 pm

OK, I found several versions to try: Raspbian Full, Raspbian Lite, and Minibian.
There are probably others, e.g. PiCore, but I am trying to stay in the Raspbian domain to minimize monkeying around with upgrades.

I am trying to make:
- a headless pi 3B that
- runs pigpio
- runs owfs
- has wifi
- has a login for the serial port

So I tried Minibian. It fits on a 4gig card.
initial bootup from .img is 3.376kernel + 13.566user = 16.942seconds
then do
apt-get update
apt-get install apt-utils
apt-get install raspi-config
use raspi-config to resize filesystem
reboot
systemd-analyze reports Startup finished in 3.403 (kernel) + 15.576 (userspace) = 18.980s

apt-get dist-upgrade
reboot
systemd-analyze reports Startup finished in 2.161 (kernel) + 12.402 (userspace) = 14.564s

apt-get install firmware-brcm80211
apt-get install wpasupplicant
use raspi-config to turn on serial port login, SPI, I2C, 1wire
systemd-analyze reports Startup finished in 3.344 (kernel) + 12.017 (userspace) = 15.361s

apt-get install owfs-common
apt-get install owfs
apt-get install pigpio
reboot
systemd-analyze reports Startup finished in 3.315s (kernel) + 11.054s (userspace) = 14.369s
---
Then I tried Raspbian Lite, fits on a 4gig card. Using PiBakery to run some mods automatically:
Used Pibakery to add:
- owfs-common
- owfs
- pigpio
- login from serial port
- turn on SPI, I2C
reboot
systemd-analyze reports Startup finished in 3.627s (kernel) + 15.486s (userspace) = 19.113s

use raspi-config to
- turn on 1wire
- turn off wait for network
- resize filesystem
reboot
systemd-analyze reports Startup finished in 3.601s (kernel) + 10.173s (userspace) = 13.774s

sudo apt-get dist-upgrade
reboot
systemd-analyze reports Startup finished in 4.973s (kernel) + 10.256s (userspace) = 15.229s
---
Then I tried Raspbian Full, fits on an 8gig card. Same configs as Lite:
Used Pibakery to add:
- owfs-common
- owfs
- pigpio
- login from serial port
- turn on SPI, I2C
reboot
systemd-analyze reports Startup finished in 1.964s (kernel) + 9.811s (userspace) = 11.776s

use raspi-config to
- turn on 1wire
- turn off wait for network
- resize filesystem
reboot
systemd-analyze reports Startup finished in 1.977s (kernel) + 11.264s (userspace) = 13.241s

sudo apt-get dist-upgrade
reboot
systemd-analyze reports Startup finished in 1.962s (kernel) + 10.996s (userspace) = 12.959s
---
About half the time spent in startup was from just a few tasks, typically the UART, one-wire, and networking services.

Summary: They are all slower than I would like. Was looking for <5secs.

To reduce headaches, I will probably got with Raspbian Lite initially.

Thanks to all who responded. Off to the next task, one-wire and owfs insanity.

See you in the Interfaces forum,

kyso

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Fri Oct 07, 2016 4:50 am

If network startup includes getting an address from router, you could use static address. I add reserved address in router then experiment with static address in Pi to bypass router delay. I have not timed the change.

You can also get other messages in syslog. Startup can be made faster by changing network time and other things. There are a few posts on various tricks.

My fastest microSD card has a read time double that of the regular cards I used to use. Startup is faster but not by a big chunk because the network delays appear to be a larger component.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Fri Oct 07, 2016 5:16 am

Looking through syslog for some boots, the largest delays appear to be around IPv6. My router does not respond for IPv6. A static IPv6 address might cut a second off the boot.

kyso
Posts: 7
Joined: Sat Oct 01, 2016 10:42 pm

Re: configuring raspbian for a headless pi 3 best practices?

Fri Oct 07, 2016 3:38 pm

peterlite wrote:If network startup includes getting an address from router, you could use static address. I add reserved address in router then experiment with static address in Pi to bypass router delay. I have not timed the change.

You can also get other messages in syslog. Startup can be made faster by changing network time and other things. There are a few posts on various tricks.

My fastest microSD card has a read time double that of the regular cards I used to use. Startup is faster but not by a big chunk because the network delays appear to be a larger component.
Using raspi-config to turn off 'wait for network at boot' was helpful. If I knew how to turn off ipv6 I would, it's not helping at all.

All my SD cards are class 4, even the ones I ordered thru Amazon (which were supposed to be class 10, grrr). I will shop for faster cards this weekend.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: configuring raspbian for a headless pi 3 best practices?

Sat Oct 08, 2016 9:51 pm

UHS Speed Class 3 (U3) https://www.sdcard.org/developers/overview/speed_class/
I searched Amazon for class 3 microsd cards and the results were mostly rubbish. Most of the photographs showed a better card than what was specified in the text.

kyso
Posts: 7
Joined: Sat Oct 01, 2016 10:42 pm

Re: configuring raspbian for a headless pi 3 best practices?

Fri Dec 09, 2016 3:32 am

Well, startup is still slow, but I managed to speed up shutdown - the pi responds to shutdown differently depending on the commands you use.

To time them, I sense a GPIO pin that is tied to the supply to the DC/DC converter. It is scaled so that 12V is about 2.8v when the system is running.

When the pin goes low, I turn on another pin, then execute the shutdown command, then turn the pin high.

This tells me how long it takes to perform a command.

To execute system("shutdown now") takes over 2.3 seconds.
To execute system("poweroff -f") takes about 980 milliseconds.
To execute system("/bin/systemctl -f poweroff") takes about 11 milliseconds.

Since I have at most about 50 milliseconds before the 5V bus decays (energy stored in the DC/DC converter), this is more than enough time to shut down nicely before the power goes away.

Startup still needs work, it takes about 30 secs before the system launches my app via /etc/rc.local - is there something I can use (besides rc.local) to launch my app sooner?

User avatar
Gerd
Posts: 66
Joined: Wed Mar 16, 2016 10:48 am
Location: Europe

Re: configuring raspbian for a headless pi 3 best practices?

Fri Dec 09, 2016 3:19 pm

Hi, for better startup times you could try to disable, or better not enable, any interfaces and services you do not need. E.g. Pi3 connected to LAN by ethernetcable; WLAN, BT and HDMI not enabled shows:

Code: Select all

$ systemd-analyze
Startup finished in 2.202s (kernel) + 5.016s (userspace) = 7.219s

Return to “Raspbian”