Set up eth0 network interface using DHCP in initramfs

20,205

The simplest solution is to use ipconfig via the kernel's ip= command-line option in grub.cfg (or pxelinux.cfg or however you boot your kernel). I'm not aware of a man page for it, but there is a README.ipconfig file in the klibc Git repository and installed at /usr/share/doc/klibc-utils/README.ipconfig.gz. So your /etc/default/grub might have a line such as the following:

GRUB_CMDLINE_LINUX="ip=:::::eth0:dhcp"

You may need to make a simple script in /etc/initramfs-tools/scripts/local-top that sources the functions file and then calls the configure_networking function, like so:

#!/bin/sh
. /scripts/functions
configure_networking

(I had mistakenly thought configure_networking was called by default, but something has to explicitly call it—either your own script or one from a package. In my case, it was called from open-iscsi.)

Share:
20,205

Related videos on Youtube

Jason Dunbar
Author by

Jason Dunbar

Updated on September 18, 2022

Comments

  • Jason Dunbar
    Jason Dunbar over 1 year

    I created my own initramfs script (based on live-initramfs) and I need set up network connection (using DHCP) to get remote file. So what do I need to add to initramfs hook file (ifconfig, dhclient?). And how to write my initramfs script? Now I am trying something like this:

    mkdir -p /var/run/network  # needed by ifup
    modprobe af_packet         # for DHCP?
    udevadm trigger            
    udevadm settle  
    ifup eth0                  #???            
    

    for ifup I need /etc/network/interfaces file to have:

    auto eth0
    iface eth0 inet dhcp
    

    But generally I don't know what exactly need to be done for network device to work properly in initramfs.

    Any idea or help?