Installing Raspbian via CLI

# Install and unpack image
wget https://url-to-image.com/image.img.xz
unxz image.img.xz

# dd image onto drive
sudo dd if=image.img of=/dev/sdx bs=4M status=progress

Now we have a working boot drive! This will automatically resize on first boot. Now we need to configure it to allow for a headless install

First boot configuration

First boot configuration can be achieved by placing a config file in the bootfs partition. This will be done by mounting the sdx1 partition and creating a config.toml file.

# Mount bootfs partition
sudo mount /dev/sdx1/ /mnt/rasp-boot
cd /mnt/rasp-boot

# Create and edit config.toml
sudo nvim config.toml

Then we will provide the following into the file, this can be changed for different uses

# Raspberry PI OS config.toml
# This file is used for the initial setup of the system on the first boot, if
# it's s present in the boot partition of the installation.
#
# This file is loaded by firstboot, parsed by init_config and ends up
# as several calls to imager_custom.
# The example below has all current fields.
#
# References:
# - https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/master/usr/lib/raspberrypi-sys-mods/firstboot
# - https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/master/usr/lib/raspberrypi-sys-mods/init_config
# - https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/master/usr/lib/raspberrypi-sys-mods/imager_custom

# Required:
config_version = 1

[system]
hostname = "raspberrypi"

[user]
# If present, the default "rpi" user gets renamed to this "name"
name = "rpi"
# The password can be encrypted or plain. To encrypt, we can use "openssl passwd -5 raspberry"
password = "$5$pN7oRnie.WDOHoJY$aWEYmKUytN/S/bxMza5ksBiurbSJmcvcysBKHSmYa45"
password_encrypted = true

[ssh]
# ssh_import_id = "gh:user" # import public keys from github
enabled = true
password_authentication = true
# We can also seed the ssh public keys configured for the default user:
# authorized_keys = [ "ssh-rsa ... user@host", ... ]

[wlan]
ssid = "mywifi"
password = "$5$pN7oRnie.WDOHoJY$aWEYmKUytN/S/bxMza5ksBiurbSJmcvcysBKHSmYa45"
password_encrypted = true
hidden = false
# The country is written to /etc/default/crda
# Reference: https://wireless.wiki.kernel.org/en/developers/Regulatory
country = "IE"

[locale]
keymap = "en"
timezone = "America/New_York"

Now we can save the file and unmount the partition


References