Skip to content

Instantly share code, notes, and snippets.

@telenieko
Created March 5, 2018 16:57
Show Gist options
  • Save telenieko/d17544fc7e4b347beffa87252393384c to your computer and use it in GitHub Desktop.
Save telenieko/d17544fc7e4b347beffa87252393384c to your computer and use it in GitHub Desktop.
Sample files to enable wireless on Debian initramfs
#!/bin/sh
# this goes into /etc/initramfs-tools/scripts/init-premount/a_enable_wireless
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
AUTH_LIMIT=30
INTERFACE="wlp5s0"
alias WPACLI="/sbin/wpa_cli -p/tmp/wpa_supplicant -i$INTERFACE "
log_begin_msg "Starting WLAN connection"
/sbin/wpa_supplicant -i$INTERFACE -c/etc/wpa_supplicant.conf -P/run/initram-wpa_supplicant.pid -B -f /tmp/wpa_supplicant.log
# Wait for AUTH_LIMIT seconds, then check the status
limit=${AUTH_LIMIT}
echo -n "Waiting for connection (max ${AUTH_LIMIT} seconds)"
while [ $limit -ge 0 -a `WPACLI status | grep wpa_state` != "wpa_state=COMPLETED" ]
do
sleep 1
echo -n "."
limit=`expr $limit - 1`
done
echo ""
if [ `WPACLI status | grep wpa_state` != "wpa_state=COMPLETED" ]; then
ONLINE=0
log_failure_msg "WLAN offline after timeout"
panic
else
ONLINE=1
log_success_msg "WLAN online"
fi
configure_networking
# !/bin/sh
# This goes into /etc/initramfs-tools/hooks/enable-wireless
set -e
PREREQ=""
prereqs()
{
echo "${PREREQ}"
}
case "${1}" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
# CHANGE HERE for your correct modules.
manual_add_modules iwlwifi iwlmvm
copy_exec /sbin/wpa_supplicant
copy_exec /sbin/wpa_cli
copy_file config /etc/initramfs-tools/wpa_supplicant.conf /etc/wpa_supplicant.conf
# This is run on the shell
chmod +x /etc/initramfs-tools/scripts/local-bottom/kill_wireless
chmod +x /etc/initramfs-tools/scripts/init-premount/a_enable_wireless
chmod +x /etc/initramfs-tools/hooks/enable-wireless
update-initramfs -k all -u
update-grub
#!/bin/sh
# this goes into /etc/initramfs-tools/scripts/local-bottom/kill_wireless
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
echo "Killing wpa_supplicant so the system takes over later."
kill `cat /run/initram-wpa_supplicant.pid`
# sample /etc/initramfs-tools/wpa_supplicant.conf
# note that this is independent of the system /etc/wpa_supplicant.conf (if any)
# only add the network you need at boot time. **And keep the ctrl_interface** !!
ctrl_interface=/tmp/wpa_supplicant
network={
ssid="MyNetwork"
scan_ssid=1
psk="network passphrase"
key_mgmt=WPA-PSK
}
@leksmut
Copy link

leksmut commented Jul 26, 2022

Thanks for this scripts.
To add autodetection of wlan interface name in a_enable_wireless.sh
change

INTERFACE="wlp5s0"

to

INTERFACE=`ip link | awk '{if(substr($2,1,1) =="w") {gsub(":","",$2); print($2); exit;}}'`

it finds first interface by mask "w*",
and then add check if INTERFACE is zero string and skip wpa_supplicant.

if ! [ -z "$INTERFACE" ]; then
  # wpa supllicant stuff
fi

configure_networking

@maxime1992
Copy link

Hello, I'm having a little issue. I've tried the above (thanks for the scripts!) but I'm now stuck and not able to boot my server.

image

I think the connection is failing for some reason except that I never end up again in a command line to unlock my disk manually from the laptop (without using wifi).

Any idea how I can solve this?

@telenieko
Copy link
Author

Hello, I'm having a little issue. I've tried the above (thanks for the scripts!) but I'm now stuck and not able to boot my server.

You are welcome.

I am not using Debian on this scenarios anymore so I cannot be of much help but:

a) I think there have been some considerable changes to initramfs/dracut that could make all this not very usefull
b) The dropbear packages (dropbear-initramfs), if memory serves well, had some scripts on line with what is proposed here which may be useful.
c) The mandos-client package also had some sample scripts that could help you

Oh, and check the comments posted here by some users giving updates! like @morfikov & @leksmut (Thank you all for those comments!)

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