slashbeast / better-initramfs

Small and reliable initramfs solution supporting (remote) rescue shell, lvm, dmcrypt luks, software raid, tuxonice, uswsusp and more.
BSD 3-Clause "New" or "Revised" License
318 stars 54 forks source link

feature request: dhcp timeout #58

Closed DrMcCoy closed 1 year ago

DrMcCoy commented 1 year ago

Would be nice if I could configure a timeout for dhcp, so that it continues onwards even if I don't have an ethernet cable connected at the moment.

I just ran into this on my laptop, and as workaround, had to reboot and modify the parameters in grub. I guess as a semi-permanent workaround, I now need to add a second grub entry, but I'd prefer if I could just set a timeout to 60s or something.

slashbeast commented 1 year ago

From the look of it it actually works like that, it does not exist if lease is not obtained, which actually is a bug and it would block the boot forever,. the default is sleep of 20s between retries, is it possible that your case you did not waited over 20s after you plugged the cable?

The DHCP support needs more love from the look of it, it will not fall back to link local address, and if I just add option to exit on failing to get lease on address it will generate empty query result and most likely later crash on error from iproute2.

I see they fallback to avahi in such cases https://git.busybox.net/buildroot/tree/package/busybox/udhcpc.script. perhaps this is finally the moment to get avahi up and running as requested in #57

DrMcCoy commented 1 year ago

No, I know, it works when I plug in a cable afterwards and wait 20s. That works, I tried that before, but that wasn't my situation this time.

This time, I had no cable available at all. So I waited and waited, hoping that it would run into a timeout and just not try to get a lease at all. Which it did not.

What I'd like is: I'd like a parameter to set a timeout and if I no dhcp reply is received after that timeout, it just doesn't configure the network at all and ignores it (and probably also doesn't start sshd). So if I'm out and about with my laptop without any network accessible at all, I can still unlock my system.

slashbeast commented 1 year ago

Okay, I misunderstood your report. yeah indeed it should not run without timeout, will sort it perhaps tomorrow, one thing is switch to udhcpc client and another some logic to actually not set anything or link local address on interface.

slashbeast commented 1 year ago

Give a try latest devel branch, if it address your usecase.

DrMcCoy commented 1 year ago

Well, first of all, you forgot a then, so the system kernel panics when the initramfs' init dies :P

diff --git a/sourceroot/functions.sh b/sourceroot/functions.sh
index fb2e553..7a96d08 100755
--- a/sourceroot/functions.sh
+++ b/sourceroot/functions.sh
@@ -380,6 +380,7 @@ SetupNetwork() {
    if [ "${binit_net_addr}" =  'dhcp' ]; then
        einfo "Using DHCP on ${binit_net_if} ..."
        if udhcpc -i "${binit_net_if}" -s /bin/dhcp-query -q -f -n
+       then
            . /dhcp-query-result
        else
            ewarn "Failed to get network address via DHCP, continuing without network configured ..."

Also, this unfortunately doesn't work, because now it dies while trying to bring up sshd when there's no network configured.

Starting dropbear sshd ...
'dropbear -s -p dhcp:2020' failed.
Dropping to rescue shell [...]
slashbeast commented 1 year ago

Well, no quick win then. I need to add autoip logic, will seek into adding it this weekend.

DrMcCoy commented 1 year ago

Thanks!

slashbeast commented 1 year ago

Let me know how it works right now for you, tested here and the fallback to link local works here, Didn't tested with actual DHCP though

DrMcCoy commented 1 year ago

Yes, that seems to work fine now, thanks! :)