-2

Some changes seem to be made in recent Raspi OS Lite versions again. So here I am again, asking for an automated solution. It's 2024 and I was asked these questions when booting the Pi for the first time:

  • Keyboard layout
  • Create new user and set password

How can these be avoided? I'm downloading the latest OS Lite image and mount it to make some modifications to it before the image will be written to an SD card. When booting the device, the image must work fully unattended (also headless). No interruptions or questions are acceptable because no screen or keyboard will be attached when the device is put in use. If that happens, the system will be unresponsive and dead.

So, what files do I have to write in the new image to prevent such questions and set up things in an automated way?

In this case, I'd prefer the "de" keyboard layout (only for the rare case that a local maintenance will be necessary; and since it's asking...) and the default old "pi" user with any password. That user will be disabled anyway and only root will be used in the future. This is an IoT device (maybe a bit comparable to embedded devices that will only do one thing) and nobody will sit in front of it. The root account is only needed for future remote maintenance. The IoT app may also need access to GPIO or other system resources, so a limited user account won't do.

Seems like a Raspberry Pi is not made for industrial usage but only for humans interacting with it through a screen, keyboard and mouse on their home desktop.

Clarifications: I create that OS image with a script that does all the work automatically. This script also needs to be automated, i.e. called from another process. Also, each image contains a unique identity, so cloning a standard image won't do. The image contains login data and a device ID so that it can start working in its target environment immediately without any further configuration (which would be impossible for end users to do).

PS: Some of the comments and answers go in the direction I had anticipated. I didn't provide many details about the complete environment and all use cases because I have no questions about those. I just need that OS to boot without any interruptions or questions.

6
  • Have you looked at Pi Imagers advanced options? makeuseof.com/how-to-use-raspberry-pi-imager-advanced-options
    – CoderMike
    Commented Jan 18 at 20:22
  • No. Where can I find out what that app does to configure things? I cannot use it directly because it will not set up the image for my application. I need special packages and configuration in the image that are specific for my use case. And I need to automate my image creation script as well. I can't use a GUI app.
    – ygoe
    Commented Jan 18 at 20:50
  • I would ask on the Pi forums - they wrote it. forums.raspberrypi.com
    – CoderMike
    Commented Jan 18 at 21:04
  • Your question requires some clarification. In 2nd paragraph you say, "There cannot be any interruptions or questions because no screen or keyboard will be attached when the device is put in use.". And then in 4th paragraph you say. "In this case, I'd prefer the "de" keyboard layout ...". Please edit your question to make it clear what you want to do.
    – Seamus
    Commented Jan 19 at 4:45
  • @ygoe DO NOT put additional detail in comments EDIT your question. Many people don't read comments.
    – Milliways
    Commented Jan 19 at 7:23

2 Answers 2

1

If you run the imager and preconfigure BUT do not boot and look at the created files all will become clear.

It modifies cmdline.txt to run a script on boot and writes a customised startup script firstrun.sh.

These files are deleted on first boot.

You could just copy these files when you create your own image but inspection will show how it works if you want to create your own. The /usr/lib/raspberrypi-sys-mods/imager_custom scripts on Raspberry Pi OS are reasonably documented and even have help.

2
  • The imager doesn't seem to like me to configure anything. I know it can do, but you have to press a secret hotkey. Documentation or help is not discoverable in the imager itself. It's a pretty stupid GUI. After downloading it, I can only select hardware, OS and an SD card. No options, no writing to a file.
    – ygoe
    Commented Jan 19 at 18:17
  • @ygoe If you run an up-to-date imager there is no "secret hotkey" (and if you use an old version it is unlikely to work). Most people who want a custom image make their own - there is no point complaining about the imager (which is well documented on the Raspberry Pi Ltd. site).
    – Milliways
    Commented Jan 20 at 23:20
0

Your question confuses me a bit; I'm not sure exactly what you want to do. It sounds like you want to configure RPi to run "headless", but with certain (un-specified for now) options pre-selected. As you said, "the image must work fully unattended". As I understand your question, I can see no reason why the 'Raspberry Pi OS Lite' distribution would not meet your requirements.

The "RPi Lite OS" distro is a much smaller distro than the alternatives, but has no "GUI"/graphics components. This means the only way to interact with it is via SSH (remotely), or the command line interface via local keyboard & monitor, or via serial port.

As far as specifying user id's & passwords on first login, I don't think that's necessary. AFAICR, this and many other details, are specified during the "setup" phase when using the Raspberry Pi Imager. Also, wrt disabling the default user in favor of root, I'd recommend against that. It will needlessly complicate your configuration; root login is disabled by default, and sudo is easily configured to allow whatever username you choose (no longer limited to pi) all available privileges.

And so if I understand your requirements, once you have installed "RPi Lite OS" on your SD card (bootable media), you may proceed as follows:

  1. Login to your system via SSH, and configure it exactly as you need it. Add/remove packages, change userid, set timezones, generate a SSH key pair (if needed)... in short, configure the system as you need it to serve as your "IOT device".

  2. When you have finished your configuration, install image-utilsNote 1 to make a duplicate image file of your newly-configured system that can be saved remotely. You can retain this duplicate image file to create as many additional SD cards (or bootable media) as required.

  3. If subsequent changes to the configuration are needed, the image file can be "loop mounted" from another Linux device. This will allow you to make any necessary changes, then save as a revised image file - while keeping the original intact.

Note 1:

image-utils is a collection of scripts designed to backup a running RPi system. It is available as a zip file download, or via git.

2
  • I'm using this image: downloads.raspberrypi.org/raspios_lite_armhf_latest And it hangs at boot asking things. Keyboard layout and user name and apssword. It is necessary, just try it out yourself. I'm not discussing the root/user topic here, I have reasons and that's the better option here. - Your process won't work because I need an image that does everything on its own. SSH is initially disabled, BTW, so it's part of my modifications. Each image will be customised as well.
    – ygoe
    Commented Jan 19 at 18:04
  • If you'll read the complete answer, the image I'm talking about "does everything on its own". But you must take some steps to get it to that point after the install.
    – Seamus
    Commented Jan 19 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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