8

I am using Minibian(lightweight version of Raspbian) and if the Pi is not connected to a network it will wait a whole minute before finishing booting.

I noticed that if I commented out lines 3 and 4 in /etc/network/interfaces the Pi would boot in a normal amount of time. However, I then lost the ability to SSH into my Pi. When I want fast boots this is what my /etc/network/interfaces file looks like:

auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet dhcp

So I now I am in this awkward situation where I have to edit this file to alternate between fast boots and the ability to use SSH with my Pi.

Does anyone know how I can fix this, to satisfy both conditions?

goldilocks
  • 60,325
  • 17
  • 117
  • 234
NULL
  • 2,240
  • 8
  • 28
  • 49

6 Answers6

10

Create file (with subdirs)

/etc/systemd/system/networking.service.d/reduce-timeout.conf

with content:

[Service]
TimeoutStartSec=1

On my Pi model B (with Minibian) this solution resolved the problem. Pi boot time reduced to 15 sec, and network works.

5

Run sudo raspi-config and disable 4th option: Wait for Network at Boot.

Huczu
  • 1,251
  • 9
  • 13
2

I don't have the reputation to comment on the accepted answer yet. But just a quick update on the answer, for the latest Raspbian Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux

The file you want to edit is:

/etc/systemd/system/network-online.target.wants/networking.service

It already exists,and you should edit the section already mentioned in the answer. In my case, from TimeoutStartSec=5min, to TimeoutStartSec=1 did the trick.

regisin
  • 73
  • 7
2

I had no success applying the many other good solutions to my setup which involves having a macvlan interface on top of eth0. Install based on 2018-06-27-raspbian-stretch-lite. What works well for me:

Disable dhcpcd service.

systemctl disable dhcpcd

Reduce timeout in /etc/dhcp/dhclient.conf.

# Do not hold boot for default 60 seconds, give up faster
# but not too fast, see what work with your DHCP server
timeout 10;

# Retry faster
# This is after initial give up and dhclient went to background and boot proceeded without a lease
# Default 5 minutes is too long
retry 20;

# Consider backoff-cutoff setting as well

So now that waits at boot for up to 10 seconds, and if there is no DHCP lease the dhclient goes into background and boot continues without a lease.

Without dhcpcd I have the added benefit of being manually stop/start/restart wlan0 without having to hunt down wpa_supplicant started presumably by dhcpcd and which was refusing to stop with ifdown wlan0. Note: this might mean you might not be able to use rapsi-config to configure your wifi, and need to write config into /etc/network/interfaces, which is preferred for me anyway.

The otherwise neat solution by Evgeniy Chukanov using /etc/systemd/system/networking.service.d/reduce-timeout.conf to reduce timeout causes dhcpcd to NOT bring up my macvlan interface IF lease timeout on eth0 at boot gets reached.

Not that my macvlan config matters for OP, but it was the reason to come up with this solutions, so for completeness: In /etc/network/interfaces.d/macvlan1

auto macvlan1
iface macvlan1 inet static
    address .....
    netmask .....
    pre-up ip link add macvlan1 link eth0 type macvlan
    post-down ip link del macvlan1

I have since swapped eth0 and mavclan1, and I do static IPv4 on eth0 and DHCP client on macvlan1, which gets me further even using dhcpcd, interface gets created, but still does not re-try to obtain lease after initial timeout. I have not bothered to investigate further because my solution without dhcpcd works very well for me.

AnyDev
  • 123
  • 4
1

Does anyone know how I can fix this, to satisfy both conditions?

Perhaps, but not in a canonical way ("proper practice") way without examining the system (I've never used minibian), and learning more about how network configuration on GNU/Linux in general is supposed to work, because I've never used it properly.

All my debian style machines, including pis, have an /etc/network/interfaces that looks like your commented out version.

auto lo
iface lo inet loopback

Non "debian style" distros don't have this file at all -- although they'll have something roughly equivalent, which I'll also crudely disable. I do this because the whole if-up/down autoconfig system in my opinion causes more problems than it solves. However, part of my perspective includes the fact that I understand linux networking on a lower level well enough, and that I find scripting for this sort of thing and/or adding something to the init system myself fairly simple. But that's a perspective that took some years to acquire.

My recommendation here would be to leave that file as you have it (with everything but the first two lines commented out or removed) and try adding this to /etc/rc.local:

 (
     ip link set eth0 up
     dhclient -v eth0
 ) &> /var/log/ethernet.log

First make sure dhclient is installed (dhclient --version), and if not install it.

Also check the system for ifplugd: ps -C ifplugd. If it is in use, disable it.

There are some drawbacks to this:

  • It assumes you are only using the pi on a wire, i.e., you don't want it to prefer or fallback on wifi.

  • If you disconnect, you'll have to re-run those commands again or reboot.

If it doesn't work, have a look in /var/log/ethernet.log.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
0

I remove the static ip from /boot/cmdline.txt and that works.

Bex
  • 2,929
  • 3
  • 26
  • 34
G3z
  • 1
  • 1