Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHCP in initrd #63941

Open
sjau opened this issue Jun 30, 2019 · 8 comments
Open

DHCP in initrd #63941

sjau opened this issue Jun 30, 2019 · 8 comments

Comments

@sjau
Copy link

sjau commented Jun 30, 2019

Issue description

I'm having issues to get dhcp address into the initrd and still have network manager work properly. The reason is I have a native root encrypted zfs notebook that I'd like to reboot remotely. So since the notebook is sometimes at home, sometimes at the office (with different subnets) I need to use dhcp in the initrd, otherwise I can't login remotely.

Steps to reproduce

Add:

networking.useDHCP

to your configuration.nix and enable it. It will provide you with dynamic ip address in the initrd. However, useDHCP and networking.networkmanager.enable = true; don't mix so networkmanager has to be disabled. The problem with this approach is that once the system is fully booted (into KDE), there's no network manager available to easily turn on/off eth0, wifi0 etc......

Another option I tried is to add

boot.kernelParams = [ "ip=dhcp" ];

to the configuration.nix. This works with some caveats: Suddenly my resolv.conf only had as single entry options edns0 and wasn't able to resolve anything. I had to manually add nameserver x.x.x.x. A little solution was to use SystemD Resolved:

    services.resolved = {
        enable = true;
        fallbackDns = [ "10.0.0.1" "10.10.10.1" "10.100.100.1" "8.8.4.4" "8.8.8.8" ];
    };

That worked with some minor caveats. However the main problem with using boot.kernelParams = [ "ip=dhcp" ]; was that I just stopped the initrd bootup process waiting to obtain an ip address.

So, how can I get simple dhcp obtained ip in the initrd while still being able to use network manager later on?

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the
results.

@stale
Copy link

stale bot commented Jun 2, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
@c0deaddict
Copy link
Member

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
@sjau
Copy link
Author

sjau commented Jun 4, 2020

still important to me

@matthias-t
Copy link
Contributor

If all you want from networkmanager is turning interfaces on or off, you can do this with ip link set <interface> <up|down>. You can also do ad-hoc connections to wifi using wpa_cli. I guess initrd networking is mostly used on servers, so demand for networkmanager interoperability might be scarce. As a last resort I guess you could take a look at

+ optionalString doDhcp ''
# Bring up all interfaces.
for iface in ${dhcpIfShellExpr}; do
echo "bringing up network interface $iface..."
ip link set "$iface" up && ifaces="$ifaces $iface"
done
# Acquire DHCP leases.
for iface in ${dhcpIfShellExpr}; do
echo "acquiring IP address via DHCP on $iface..."
udhcpc --quit --now -i $iface -O staticroutes --script ${udhcpcScript} ${udhcpcArgs}
done
''

and implement this yourself using boot.initrd.preLVMCommands and postMountCommands.

@stale
Copy link

stale bot commented Mar 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 26, 2021
@b2ag
Copy link

b2ag commented Nov 19, 2023

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 19, 2023
@jrobsonchase
Copy link
Contributor

Just ran across this as well. It seems like NetworkManager sees the already-existing connection left over from the initrd and creates a "Manual" entry for it that loses its DNS configuration.

@Doc-Steve
Copy link

Doc-Steve commented Apr 27, 2024

I used these options (without boot.kernelParams = [ "ip=dhcp" ];)

boot.initrd.network.udhcpc.enable = true;
boot.initrd.network.flushBeforeStage2 = true;

Then networking.networkmanager.enable = true; worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants