1

I have a Raspberry Pi 2 here that's running the latest Minibian image, plus a few needed items - vsftpd, wpasupplicant, firmware for the Edimax Wi-Fi Adapter, mono-runtime, and a few others. However, I've noticed that during boot, it tries to configure the network interface to get onto the network. I'm alright with that, however it seems to block up the boot process, not letting anything else go while it sits there and gets a DHCPOFFER from the router.

Is there any way I could have the network configuration occur in the background while the rest of the system boots?


EDIT after @goldilocks helped pinpoint - Seems like ifup is calling for dhclient to start. ifup -v confirmed it. Is there any way I can have ifup pass -nw to dhclient?

sctjkc01
  • 306
  • 1
  • 3
  • 10
  • [Init](http://en.wikipedia.org/wiki/Init) starts boot services; raspbian wheezy uses SysV init which starts things in a single chain. Persistent processes usually fork to background right away, anything which doesn't must complete before the next thing in the chain can occur, since they are organized in terms of dependency. By default `dhclient` will fork *after* it gets a lease, but it can be instantiated to fork immediately with `-nw`. You have to figure out which service is starting `dhclient` and how to configure it to do that... – goldilocks Mar 20 '15 at 13:03
  • ...or: the easy way IMO is to just disable the system networking service and take care of it yourself: http://raspberrypi.stackexchange.com/a/28695/5538 But as I say there, that's probably not a *best* practice. I'm sure there is some way to get NetworkManager or whatever to behave in various ways. I've just never bothered to figure it out because I have not had a purpose for it. – goldilocks Mar 20 '15 at 13:07
  • Luckily another thing I opted to install was `htop` so I can see the process tree. I see one `dhclient -v -pf` running directly off `init`. – sctjkc01 Mar 20 '15 at 13:07
  • @goldilocks Rooting through `/etc/init.d/networking` I find it calls `ifup` when booting up, which is what seems to be calling `dhclient`... and one `ifup -v` just confirmed it for me. – sctjkc01 Mar 20 '15 at 13:37

1 Answers1

1

From the looks of this, you have to custom compile ifup in order to change the hardcoded switches it supplies to dhclient in various circumstances. But that isn't going to make it anymore flexible if for some reason you change your mind because, e.g., this ends up having unintended consequences.

Another choice would be to wrap dhclient so that it ends up called with the -nw switch added. To do that first find out where the executable is with which dhclient. It is most likely /sbin/dhclient.

Now check echo $PATH. /sbin is probably not the first thing in the list, which is checked in order. So if there's another dhclient in a one of the earlier directories, it will get used. This is going to be the wrapper:

#!/bin/sh

echo "Starting dhclient..."
exec /sbin/dhclient -nw $@

The echo you can remove once you are sure this works -- it will just help to confirm at boot this is being used. $@ is whatever argument list is passed to the script.

Call that script dhclient (no .sh at the end) and put it in one of the first directories from $PATH (hopefully /usr/local/bin is first so you can just use that). Make sure to:

sudo chown root.root dhclient
sudo chmod 755 dhclient

Which leaves it owned root and world executable.

If that doesn't work, i.e., it seems to call the dhclient in /sbin anyway:

sudo mv /sbin/dhclient /sbin/dhclient-real

Modify the script to call /sbin/dhclient-real $@, and move it into /sbin. This method is foolproof, since /sbin/dhclient is now yours.

goldilocks
  • 56,430
  • 17
  • 109
  • 217
  • Worked out perfectly. Mildly concerning that `dhclient` doesn't show in `htop` anymore, but it works out just as well. Thanks! – sctjkc01 Mar 20 '15 at 14:40
  • Hmmm -- if you didn't rename (`-real`), try `ps -C dhclient`. It should be there. – goldilocks Mar 20 '15 at 14:51
  • I've also modified that script a bit to use `exec /sbin/dhclient` -- probably doesn't make much difference, it just saves a fork. – goldilocks Mar 20 '15 at 14:54
  • Figured out why it wasn't showing in `htop` - turns out I wrote `#@` instead of `$@`. Whoops. Fixed, and now it shows up. – sctjkc01 Mar 20 '15 at 16:41