Skip to content

Instantly share code, notes, and snippets.

@kakurasan
Forked from telenieko/a_enable_wireless.sh
Last active November 21, 2021 06:41
Show Gist options
  • Save kakurasan/a7b9f636c19fff889ab278c3b0115990 to your computer and use it in GitHub Desktop.
Save kakurasan/a7b9f636c19fff889ab278c3b0115990 to your computer and use it in GitHub Desktop.
initramfs-tools files for Raspberry Pi Zero W/WH NFS booting with built-in WiFi
#!/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="wlan0"
alias WPACLI="/sbin/wpa_cli -p/tmp/wpa_supplicant -i$INTERFACE "
log_begin_msg "Starting WLAN connection"
/sbin/wpa_supplicant -Dnl80211 -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
manual_add_modules brcmfmac brcmutil cfg80211
copy_exec /sbin/wpa_supplicant
copy_exec /sbin/wpa_cli
copy_file config /etc/initramfs-tools/wpa_supplicant.conf /etc/wpa_supplicant.conf
# On Jessie, copy_file() is not supported but you can replace
# "copy_file <type> <path> (<path2>)" with "copy_exec <path> (<path2>)".
#copy_exec /etc/initramfs-tools/wpa_supplicant.conf /etc/wpa_supplicant.conf
# If your "update-initramfs" copies "brcmfmac43430-sdio.txt" into
# newly created initrd without next line, remove or comment out the line.
copy_file firmware /lib/firmware/brcm/brcmfmac43430-sdio.txt
# For Jessie
#copy_exec /lib/firmware/brcm/brcmfmac43430-sdio.txt
# 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
# Pi Zero uses "X.Y.Z+" kernel versions (not "-v*" versions)
KERNELVER="`ls -1 /lib/modules | grep -v -`"
update-initramfs -k "$KERNELVER" -d 2>/dev/null
update-initramfs -k "$KERNELVER" -c &&
echo "Renaming initrd.img-${KERNELVER} to initrd.img" &&
mv /boot/initrd.img-"$KERNELVER" /boot/initrd.img
#!/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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment