5

I am building Raspberry Pi images using the raspi3-image-spec project. Since it isn't the result of a conventional d-i installation, it obviously neither asks nor configures the root with WiFi information to connect on boot.

As such, I would like to know how exactly d-i stores WiFi details and makes it so it automatically connects when booted for the first time. I want to do the same on my RPi image, so that I don't have to connect to Ethernet or keyboard and monitor to configure its WiFi connectivity.

I am not asking how to connect to WiFi using commands, I already know how to do that. All I am asking is how the preconfiguration is done by d-i.

Per @kemotep's solution, not only do I have to run a command to connect to WiFi, I have to manually activate the dhcpd, or assign a static IP address. I also know how to automate these steps using /etc/network/interfaces file, but that's beside the point.

What I want to know is how d-i does it, so it conforms to regular Debian installs and my WiFi configuration files are not accidentally deleted during updates and the like.

  • I removed the raspberry-pi tag because neither d-i nor the WiFi configuration has anything to do with the device itself. I only mentioned as context of the question. – Oxwivi Sep 16 '18 at 19:57
  • @Goro, why'd you quote the edits? – Oxwivi Sep 19 '18 at 22:55
  • Ah, as a way of highlighting? I thought the header would be enough to draw attention to new info. – Oxwivi Sep 19 '18 at 23:10
5
+500

Issue at Hand

You wish to know how to set up debian-installer to pre-configure your WiFi settings. You mention using this build to create an image of Debian for a Raspberry Pi 3.

They are using debootstrap and not the standard debian-installer to install Debian on the Raspberry Pi. I will provide information on how to pre-configure your WiFi using both processes.

Using debian-installer

If you wish to know how individual components of debian-installer works please read over this manual. Section 6.3.1.5 covers configuring the network. Section 3.3.4 helps provide information about what you will need to provide to debian-installer to set up networking.

However, all of this is a manual process that can be automated via "preseeding" or providing debian-installer with a pre-configuration file.

Here is the Debian Wiki page on how to edit a preseed file. I am also include another manual page to help provide additional information on preseeding.

Here is an example preseed.cfg for you to look over. Edit it to include the steps to add wireless firmware ( d-i hw-detect/load_firmware boolean true is the key line here ).

Add these lines to preseed a wireless WPA2 network to your preseed.cfg after you have added the lines to load your firmware. Check here for information on how to load firmware during debian-installer

d-i netcfg/wireless_essid [string] // Name of wireless network
d-i netcfg/wireless_security_type [select] // Options are wep/open or wpa
d-i netcfg/wireless_wpa [string] // Password

Here is a fairly comprehensive list to show you possible netcfg options. Add more as needed to your preseed.cfg if the ones I listed do not cut it. Once you have created your preseed.cfg add it in using the following steps.

To add a preseed file you will need to mount your debian.iso and extract the the contents to copy in your preseed.cfg. The [arch] refers to the architecture of your .iso. In your case it is most likely armhf or arm64.

udevil mount debian.iso
cp -rT /media/debian.iso/ isofiles/
chmod +w -R isofiles/install.[arch]/
gunzip isofiles/install.[arch]/initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.[arch]/initrd
gzip isofiles/install.386/initrd
chmod -w -R isofiles/install.[arch]/

Here is how you fix md5sum.txt:

# cd isofiles
# md5sum `find -follow -type f` > md5sum.txt
# cd ..

Here is how you create a new bootable ISO image:

genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat \                                                    
            -no-emul-boot -boot-load-size 4 -boot-info-table \                                                           
            -o preseed-debian.iso isofiles

Now you have created a bootable ISO image to be written to your installer USB or disk that contains your pre-configurations. Make sure to read over the Wiki page and the manual carefully to help troubleshoot any issues.

Using debootstrap

Another method of installing Debian is to use debootstrap. Here is a link to the Debian Wiki and another link to the manpage. Debootstrap can be used to create an installation of Debian from an existing Unix or Linux machine.

Using debootstrap only requires a chroot or other disk/partitions and a network connection to download the packages from the repository. You can then chroot into the new Debian rootfs and configure it as needed then propagate it out to any device you wish the install to be on. This is very similar to the Arch Linux install process.

However, if you are using this script from GitHub, and you wish to pre-stage your wireless configuration then you will need to edit raspi3.yaml and use vmdb2.

Install vmdb2: ( This assumes you are using Debian Stretch! )

 apt install kpartx parted qemu-utils qemu-user-static python3-cliapp \
 python3-jinja2 python3-yaml

Note that python3-cliapp is not available in Stretch, but as it does not carry any dependencies, can be manually installed by fetching its .deb package and installing it manually.

Next download a copy of the image:

 git clone --recursive https://github.com/Debian/raspi3-image-spec
 cd raspi3-image-spec

Now edit the raspi3.yaml to include the following:

After - apt: install on line 68 add these lines:

- iw

Now after line 90 ( - shell: | ) you can add this code on its own line:

wpa_passphrase [WiFi SSID] [WiFI Password] > /etc/wpa_supplicant.conf

As long as wpa_supplicant installs correctly during your image process this line should add your WiFi configuration to allow you to connect automatically. You will still need to probably run these commands after boot, but they could potentially be added to the script too.

ip link set wlan0 down
ip link set wlan0 up
wpa_supplicant -B -iwlan0 -c /etc/wpa_supplicant.conf -Dwext
dhclient wlan0

Once you have edited raspi3.yaml, you can generate the image by issuing the following. If you are using the systemwide vmdb2:

umask 022
sudo env -i LC_CTYPE=C.UTF-8 PATH="/usr/sbin:/sbin:$PATH" \
vmdb2 --output raspi3.img raspi3.yaml --log raspi3.log

Or, if you are using it from the submodule in this repository

umask 022
sudo env -i LC_CTYPE=C.UTF-8 PATH="/usr/sbin:/sbin:$PATH" \
./vmdb2/vmdb2 --output raspi3.img raspi3.yaml --log raspi3.log

After that you should be able to install the new image onto an SD card and it will follow the extra steps you added in the script. You can add any additional steps you wish to the file.

The OP of this stack exchange post noted that the second method user GAD3R advises works as well to add wireless configurations via command line.

Conclusion

If you are using debian-installer you will need to preseed your debian.iso with the configuration you desire.

If you are using debootstrap you will have to include any additional steps you wish to take in the installation process or chroot in afterwards.

I will be including the Debian Wiki Page on WiFi as well as the How To page and the information on adding missing firmware. The wireless firmware can be found here for Raspberry Pi

Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.

Best of Luck!

  • It is my fault that I was not explicit in my question, but I'm aware how to connect using command prompts, using precisely the commands you answered with. My aim of the question was to let RPi connect to WiFi so that I don't have to attach a keyboard and screen to it and remotely ssh into it. Adding the wpapassphrase file will not let it connect to WiFi automatically either, hence your answer is moot anyway. – Oxwivi Sep 19 '18 at 22:29
  • @Oxwivi To correct my answer, are you wishing to know in general how debian-installer configures WiFi? If I am reading the script from GitHub correctly you are not using debian-installer but taking an image of Debian and running the commands from the raspi3.yaml to build it on the Raspberry Pi. Or are you using this installer and not the scripts? I think that is where I am confused. I can edit my post accordingly to satisfy that requirement. I left the 2nd part in for others who may not know how to do that. Thank you. – kemotep Sep 20 '18 at 12:16
  • Yes, I'm using the GitHub script, and I wish to know how d-i does it in general to use it on the image created by the script. It's literally the title: "How does debian-installer confugre WiFi" – Oxwivi Sep 20 '18 at 20:30
  • @Oxwivi Thank you for clarifying. The GitHub page you linked uses qemu-debootstrap and not debian-installer. It appears that debian-installer uses NetworkManager but can also be preseeded to include certain configurations. I can edit my post to reflect this but if you are using the GitHub script you linked to that will not help you. – kemotep Sep 20 '18 at 20:50
  • There isn't anything stopping me from modifying the .img file after it has been generated. Other than that, is there anyway to run d-i in the qemu-debootstrap environment? – Oxwivi Sep 20 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.