How do I get WiFi Working in the Initramfs Pre-Boot Environment?

I got internet access to work in the pre-boot initramfs by adding rd.neednet=1 ip=dhcp to the GRUB_CMDLINE_LINUX line in /etc/default/grub but this only works with ethernet. Is it possible to get WiFi working too? Right now, running nmcli radio in the pre-boot emergency shell shows that WIFI is enabled but WIFI-HW is missing (as opposed to the normal booted OS where both are enabled).

So far, I’ve tried creating /etc/dracut.conf.d/00-wifi.conf with a line that causes some extra WiFi-related kernel modules to be added to the initrmfs: add_drivers+=" iwlwifi cfg80211 rfkill iwlmvm mac80211 libarc4 "

But this not only doesn’t work, it causes WiFi to stop working in my normal booted OS as well (it fails to find the WiFi adapter).

This is on Fedora 38 Workstation (11th gen Intel CPU with an AX210 No vPro network card) - any help would be appreciated!

I believe wpasupplicant is responsible for starting wifi, along with NetworkManager.

What I do is enable wifi with the live media – before I do the install
Then the install (and initramfs) has wifi fully functional and no other configs are required.

Hmm, not really practical for me to re-install the OS just for this. But it’s good to know that it’s possible.

Could you share more details on getting wpasupplicant to run in the preboot env? I see networkmanager is already a default dracut module, but nothing about wpasupplicant.

quite old post, but as i stumbled over it while researching this topic, here’s how i got it working
(in case anyone else is interested in):

(tested with an fc40 live image, booting via http-boot)

etc/dracut.conf.d/wifi.conf

add_dracutmodules+=" bash systemd systemd-initrd systemd-sysusers modsign nss-softokn dbus-broker dbus i18n network-manager network ifcfg url-lib drm plymouth btrfs crypt dm dmsquash-live kernel-modules kernel-modules-extra kernel-network-modules livenet lvm mdraid nvdimm overlayfs qemu qemu-net cifs iscsi lunmask nfs resume rootfs-block terminfo udev-rules virtfs virtiofs dracut-systemd pollcdrom usrmount base fs-lib img-lib memstrack shutdown wifi "
  • new dracut wifi module (to be fair, its a ‘merge’ of the bluetooth and network-manager module, so there might also be some lines that are not actually needed)

/usr/lib/dracut/modules.d/90wifi/module-setup.sh

#!/usr/bin/bash

check() {
    require_binaries ping ncat sleep || return 1

    # do not add this module by default
    return 255
}

depends() {
    echo dbus bash
    return 0
}

installkernel() {
    # intel wifi modules (adapt to your wifi adapter)
    instmods iwlmvm mac80211 iwlwifi cfg80211 rfkill
    # firmware for intel wifi (adapt to your wifi adapter)
    inst_multiple -o \
        /lib/firmware/iwlwifi*
}

install() {

    # NETWORK MANAGER PLUGIN
    _nm_version=${NM_VERSION:-$(NetworkManager --version)}

    # add packages
    inst_multiple ping ncat sleep

    # add wifi module/plugin for NetworkManager
    inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-wifi.so"

    # WIFI ASK SCRIPT
    inst_simple "$moddir"/nmtui.service "$systemdsystemunitdir"/nmtui.service
    # script that calls nmtui
    inst "$moddir/wifi.sh" "/usr/bin/wifi.sh"
    $SYSTEMCTL -q --root "$initdir" enable nmtui.service

    # WPA SUPPLICANT
    # shellcheck disable=SC2064
    trap "$(shopt -p globstar)" RETURN
    shopt -q -s globstar
    local -a var_lib_files

    inst_multiple -o \
	"$dbussystemconfdir"/wpa_supplicant.conf \
        "$dbussystemservices"/fi.w1.wpa_supplicant1.service \
        "${systemdsystemunitdir}/wpa_supplicant.service" \
	chvt \
	wpa_supplicant

    inst_multiple -o \
	/etc/wpa_supplicant/wpa_supplicant.conf \
        /etc/sysconfig/wpa_supplicant \
	eapol_test \
	wpa_cli \
	wpa_passphrase \
	nmtui \
	rfkill

    # shellcheck disable=SC1004
    sed -i -e \
        '/^\[Unit\]/aDefaultDependencies=no\
        Conflicts=shutdown.target\
        Before=shutdown.target\
        After=dbus.service' \
        "${initdir}/${systemdsystemunitdir}/wpa_supplicant.service"

    $SYSTEMCTL -q --root "$initdir" enable wpa_supplicant.service
}
  • customer service nmtui that is called in initrd to setup wifi

/usr/lib/dracut/modules.d/90wifi/nmtui.service

[Unit]
Requires=systemd-vconsole-setup.service
After=systemd-vconsole-setup.service nm-initrd.service
#Before=initrd-root-device.target
Before=dracut-initqueue.service
Conflicts=multi-user.target
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/usr/bin/wifi.sh
StandardInput=tty
TTYPath=/dev/tty3
TTYReset=yes
TTYVHangup=yes

[Install]
WantedBy=sysinit.target
  • the actual script of the above service, it switches to tty3 and starts nmtui for ‘interactive’ wifi/network setup (basically adapted from here)

/usr/lib/dracut/modules.d/90wifi/wifi.sh

#!/bin/bash

# set try var
try=0

# check for network
while ! ping -c 1 -4 google.de >/dev/null 2>&1; do
    # drop to shell if tried for more than 3 times
    if [ "$try" == "3" ]; then
        echo "starting debug shell"
        /bin/bash
    fi
    # switch to tty3
    chvt 3
    # print message, and wait 2sec
    echo "no network, please try to set up wifi"
    sleep 2
    # start nmtui to set up wifi/network
    /usr/bin/nmtui
    # wait a moment
    sleep 2
    # increment try
    try=$((try+1))
done
# switch back to tty1
if [ "$try" != "0" ]; then
    chvt 1
fi
  • install nmtui (only required if you also want to use the above interactive script)
    dnf -y install NetworkManager-tui

  • building the new initrd
    dracut -f --xz --nomdadmconf --nolvmconf --no-hostonly /boot/initramfs.xz.img

(for me) it was neccessary to also adapt the kernel cmdline and remove the splash screen (remove quiet rhgb) to have the tty switch work correctly

hope that helps anyone who want’s to achieve something like that in the in the future :slight_smile:

1 Like