mkinitfs: ip=dhcp fails on Raspberry 3B+ because network device is not ready
There's different failure modes trying to use ip=dhcp kernel command line option to set up networking to use a remote apkovl or ssh_key file on Raspberry 3B+ using Alpine 3.10.2 armhf Raspberry Pi.
https://github.com/alpinelinux/mkinitfs/blob/master/initramfs-init.in
Here's the problems in the order I found them attempting to make it work.
Problem 1: ip=dhcp does not detect device because interface is down
First I tried ip=dhcp ssh_key=https://.... noquiet
. It doesn't work and I got error:
grep: /sys/class/net/eth*/operstate: No such file or directory
ERROR: IP requested but no network device was found
If I boot with init=/bin/sh I can see the eth0 but operstate shows that it's not up even though the cable is plugged in. I conclude that eth0 is not there when the grep runs but is by the time I manually enter the command in init=/bin/sh.
So even if the interface did show as up, it wouldn't be detected. But this problem is actually hidden by the second one.
Problem 2: the interface is not detected when it is configured
If I use ip=dhcp:::::eth0
command line to get around the first problem,
I get this:
* Obtaining IP via DHCP (eth0)...: ifconfig: SIOCSIFADDR: No such device
https://github.com/alpinelinux/mkinitfs/blob/master/initramfs-init.in#L194
The problem is that the interface is not yet up.
When I do ifconfig -a in shell, the eth0 is there. From dmesg I infer that it is detected less than a second after the error above.
I suspect the problem is related to the ethernet being connected by USB on Raspberry. I could not find a way to delay the init execution.
Ideally the init should wait for a few seconds until the interface is discovered if it's not detected at this point, but was manually specified like I did.