navtz
Posts: 10
Joined: Sat Nov 29, 2014 6:37 pm

Load wifi settings from USB flash drive

Wed Dec 03, 2014 3:34 pm

Hi,
During start up, how can I make the Wifi adapter get the IP address, subnet mask, gateway IP etc from a USB flash drive? Right now, I'm modifying the /etc/network/interfaces file whenever I want to change them & rebooting. But I need to be able to modify the IP settings from an external USB flash drive.

cdo
Posts: 9
Joined: Tue Nov 19, 2013 5:13 pm

Re: Load wifi settings from USB flash drive

Wed Dec 03, 2014 4:01 pm

You can put an interfaces file somewhere on the usb drive and write a small script which mounts it on startup and copies the file to /etc/network.

renatoargh
Posts: 1
Joined: Tue Dec 27, 2016 12:29 am

Re: Load wifi settings from USB flash drive

Tue Dec 27, 2016 12:33 am

Hey! I have just followed your suggestion and came up with this script (enhancements needed)

Code: Select all

sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi

if [ -f /media/usb/interfaces ] 
then
  if cmp --silent /media/usb/interfaces /etc/network/interfaces
  then
    echo " "    
  else
    sudo cp /media/usb/interfaces /etc/network/interfaces
    sudo service networking reload
    sudo reboot
  fi
fi
Save the code above as `wifi.sh` and add an entry to crontab with `contab -e` like this: `@reboot sh /home/pi/wifi.sh`. You might need to give it execute permissions with `sudo chmod +x /home/pi/wifi.sh`

Hope this helps

User avatar
HawaiianPi
Posts: 5838
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Load wifi settings from USB flash drive

Tue Dec 27, 2016 5:48 am

Nice, except all of that is unnecessary now. You can put the wpa_supplicant.conf file in the SD card's /boot partition (the only partition visible to Windows/Mac) and it will be moved to the correct location and used when you boot the Pi. The wpa_supplicant.conf file should contain the following:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"
	key_mgmt=WPA-PSK
}
Edit country=, ssid= and psk= with your info.
www.raspberrypi.org/blog/another-update-raspbian/ wrote:• If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings; this allows a Wifi configuration to be preloaded onto a card from a Windows or other machine that can only see the boot partition.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

Return to “Beginners”