Installation and provisioning of Raspberry Pi computers can be so much easier with the automated bootstraping. This especially becomes very useful when you have to provision more than one Raspberry Pi and want to configure these devices similarly.

The following configuration works nicely with Rasbian / Debian Buster, and was not yet tested with Bookwork

Installing the OS

The operating system (OS) is usually located on a SD-card. This SD-card has to get configured or filled with the help of a different computer.

Since 05.03.2020 there is an offical helper tool available: the Raspberry Pi Imager

The Raspberry Pi Imager allows you to select the desired operating-system to install. In my case this is nearly always “Raspberry Pi OS”, based on Debian Linux, either as default version or as “Lite”-version (without graphical-environment).

Well, just using the Raspberry Pi Imager to install Raspberry Pi OS to some SD-card or USB-drive should be easy and straightforward, but how to continue?

If you’re using MacOS or Windows to create the images, you’ll see your destination device for your Raspberry Pi OS shows one visible and writeable partition labbeled “BOOT”. We’ll use this partition/volume to configure our Raspberry Pi in the next steps.

TLDR

Basically you can prepare config-files, copy these to the partition labbeled “BOOT”, put the SD-card into your Raspberry Pi and boot it up.

Configuration of WiFi

In my Badminton-setup, I use Raspberry Pi as wireless-clients presenting some browser-window in Kiosk-mode. The point is now: wireless.

I only put this file into the mentioned “BOOT”-volume:

Filename: wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE
network={
        scan_ssid=1
        ssid="<The-WiFi-SSID-goes-here>"
        psk=<The-WiFi-PSK-goes-here>
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
}

For me this works flawlessly with the last versions of Debian / Raspberry Pi OS.

According to the Raspberry Pi OS network configuration you can even use multiple network-blocks in this file to support multiple WiFi networks.

Configuration of Users

Previously there was some default user pi on Raspberry Pi OS, but this default user was dropped for security reasons. Now you’d have to configure some user manually at first startup. But configuring a user manually at the first startup is very cumbersome and error-prone.

I follow the documentation how to do it differently:

  • Place a file with the filename userconf.txt into the mentioned “boot”-volume using this content scheme:
<username>:<hashed-password>

Use the command openssl passwd -6 to create a hashed password.

Example:

username:$6$nbLUJeL0WK93K6Sw$CfT59XqmEMyzIszjeNbvTdvkDn0VUV0iYu9xNuoasBePtJl5b.yJY3bbGpCuaTEJartPOpLZvcRi02MOYj7Qv.

This will create a user username with the password password.

This user is configured to auto-login by default.

After the first bootup (and initial configuration of the user) I usually apply some Ansible-Playbook to configure this user, change the password and configure the ssh-keys.

If I want my Raspberry Pi directly into some browser running in kiosk-mode, the auto-login feature of the display-manager is a nice solution.

How to disable auto-login on tty

See https://raspberrypi.stackexchange.com/a/139980/140760.

sudo ln -s /dev/null /etc/systemd/system/[email protected]/autologin.conf

Configuration of SSH

I need SSH access to my Raspberry Pi’s to have some remote admin access and apply additional configuration with Ansible.

The (for me) easiest way to enable the SSH-server is just this:

  • Put a file named ssh into the mentioned “Boot”-volume.

That’s just it. Upon boot-up of your Raspberry Pi the SSH-server is started.

You now could use ssh-copy-id to configure the authorized_keys of your user and start using Ansible for further configuration.

Further configuration

You can apply further detailed configuration via the file config.txt in the “boot”-volume.

Use can use this file to apply this configuration for example:

  • Configure modes of the HDMI-output
  • enable / disable Bluetooth
  • enable / disable Audio
  • Overclocking

# For more options and information see

# <http://rpf.io/configtxt>

# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode

# hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible

# and your display can output without overscan

disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console

# goes off screen, and negative if there is too much border

# overscan_left=16
# overscan_right=16
# overscan_top=16
# overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus

# overscan

# framebuffer_width=1280
# framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output

hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)

# hdmi_group=2
# hdmi_mode=85

# uncomment to force a HDMI mode rather than DVI. This can make audio work in

# DMT (computer monitor) modes

# hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or

# no display

# config_hdmi_boost=4

# uncomment for composite PAL

# sdtv_mode=2

# uncomment to overclock the arm. 700 MHz is the default.
# arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces

# dtparam=i2c_arm=on
# dtparam=i2s=on
# dtparam=spi=on

# Uncomment this to enable the lirc-rpi module

# dtoverlay=lirc-rpi

# Disable Bluetooth

dtoverlay=disable-bt

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)

dtparam=audio=on

disable_splash=1

# Enable Debug-mode

# dtdebug=1

# sudo vcdbg log msg

# dtc -I fs /proc/device-tree