Skip to content

Description

Notes on creating a headless startup disk for a Raspberry Pi 4.


Attributes

Updated
Created
CategoryNotes
EffortOutline

Topics


Links

References
Cloning a Disk Image

Source

View on sourcehut

License

Creating a Headless Raspberry Pi Startup Disk © 2022 by Jon Webb is licensed under CC BY-SA 4.0

Creating a Headless Raspberry Pi Startup Disk

Contents

These steps have been tested using a Raspberry Pi 4.

Option 1: Using the Raspberry Pi Imager

The Raspberry Pi Imager software GUI can be used to download, copy, and modify disk images.

Raspberry Pi Imager software

  1. Select the Raspberry Pi OS Lite (64-bit) image and the target storage device.

  2. Select the advanced options icon (lower right) and adjust the following settings:

    • Set hostname (optional)
    • Enable SSH (required)
    • Set username and password (required)
    • Set locale settings (optional)
      • Time zone
      • Keyboard layout
  3. Write the image to the target storage device.

Option 2: Manual setup

A headless setup can also be achieved by copying the image and modifying it manually.

Copy disk image

  1. Download the Raspberry Pi OS Lite (64-bit) disk image.

As of 2022, the downloaded image uses the xz compression format, so you’ll need the unxz command to get the img file (e.g. unxz 2022-04-04-raspios-bullseye-arm64-lite.img.xz).

  1. Clone the disk image to the target storage device.

Required setup

Find the FAT32 partition labeled boot using lsblk-f (e.g. sda1).

Mount the boot partition:

$ udisksctl mount -b /dev/sda1
$ cd /run/media/jon/boot

Networking

Ethernet should work out of the box, but WiFi can be configured by creating a wpa_supplicant.conf file.

Default user

The userconf.txt file can be used to configure a default user account.1

Creating a default user jon with the password raspberry:

$ echo "jon:$(echo 'raspberry' | openssl passwd -6 -stdin)" > userconf.txt

SSH

Enable SSH by creating an empty file called ssh in the boot partition root.2

$ touch ssh

Finally, unmount the boot partition:

$ cd
$ umount /run/media/jon/boot

Optional setup

Find the ext4 partition labeled rootfs using lsblk-f (e.g. sda2).

Mount the root partition:

$ udisksctl mount -b /dev/sda2
$ cd /run/media/jon/rootfs

Hostname

Update the hostname in both etc/hostname and etc/hosts (the default is raspberrypi).

Timezone

Create a symlink from the time zone file to /etc/localtime:

$ sudo ln -sf usr/share/zoneinfo/America/New_York /etc/localtime

Keyboard layout

Edit /etc/default/keyboard, changing XKBLAYOUT from gb to us, for example.

Wrapping up

Unmount the boot (and root partition, if used):

$ cd
$ umount /run/media/jon/boot
$ umount /run/media/jon/rootfs

The startup disk should now be configured for headless use.

Connecting via SSH

Raspberry Pi OS supports multicast DNS, which resolves to its hostname and the .local suffix.3

Assuming a default user jon and a hostname raspberrypi:

$ ssh jon@raspberrypi.local