Background: I have several RPis which I need to re-image. I use the stock Raspbian and they get their IPs via DHCP. This makes it difficult (in my specific environment) to know which IP they received, and then to configure them.

Today this configuration is automated via Ansible but the first connection is complicated (due to the lack of knowledge of the IP). I would like to move to SaltStack, where the connection is initiated by the client (the RPi in my case).

The question: the SaltStack software still needs to be installed and I would like to "drop" this installation script somewhere on the SD with the image. One thing I do not want to do is to modify the stock Raspbian (rebuild it), just have myinstallation.sh (which would have the relevant commands and configuration) launched either as part of the first boot, or as part of any boot (I would remove it during the configuration).

Is such a functionality available? Or a similar approach?

  • Would automatic tools such as PiBakery which customise the image be suitable (I described the usage here) or is the requirement that the image can't be modified strict?
    – Aurora0001
    Jan 27, 2018 at 14:56
  • "launched either as part of the first boot, or as part of any boot (I would remove it during the configuration)... a similar approach" -> Yes, this is exactly what raspi-config does.
    – goldilocks
    Jan 27, 2018 at 16:07
  • @goldilocks: my understanding is that raspi-config is a tool one uses interactively after having logged in. This is not at all what I am trying to do (actually I do not want to log in in the first place)
    – WoJ
    Jan 27, 2018 at 22:31
  • @Aurora0001: this is an interesting solution. After going through the documentation, it looks like the number of things I can do is quite limited, though (what I would be missing is, for instance, the ability to start a bash script, or at least to edit an existing file such as /etc/hosts ).
    – WoJ
    Jan 27, 2018 at 22:32
  • Have you looked into systemd?
    – user61421
    Jan 28, 2018 at 4:42

1 Answer 1


As per comments, it is simple enough to create a boot service that runs only once, or runs until some criteria have been satisfied, then it simply disables itself (systemctl disable ...).

However, from the sound of things, you don't want to have to run the image in order to install and enable a new service. Technically this is not necessary; all you have to do to enable a systemd service is create symlink to the service file in an appropriate /etc/systemd/system/ subdirectory (e.g., graphical.target.wants if the system will be running a GUI or multi-user.target.wants otherwise).

If that seems like too much work, rather than adding a file you can replace one: /etc/rc.local, and start whatever from there.

  • I just added a comment on the way to enable ssh on a headless system (raspberrypi.stackexchange.com/a/73121/6123) which is similar to what I am looking for - but with something more elaborate than just a file which acts as a flag (to enable ssh) for the OS.
    – WoJ
    Jan 28, 2018 at 15:49
  • If you want something like that you'll have to implement it yourself, which means creating a customized image. But again: If you are able to add a file, then you might as well replace one instead. /etc/rc.local is an empty shell script by default, and it is automatically run by init/systemd.
    – goldilocks
    Jan 28, 2018 at 16:23
  • Well, the difference is that the ssh file is added to the root of the SD card (right after having flashed it, for instance as part of a script which does a dd, rhen a cp of the file (the Rpi has not booted yet)), while your proposition must be done on a running RPi (in which case I could simply install salt and be done)
    – WoJ
    Jan 28, 2018 at 17:42
  • No, it does not need to be done on a running Pi. Read the second paragraph again where it says, "...from the sound of things, you don't want to have to run the image in order to install and enable a new service. Technically this is not necessary..." and then describes enabling a service by creating a symlink. You can do that to the card in another computer without ever having used it in a Pi. Even easier: Just replace /etc/rc.local with your own script. If the problem is you don't have a computer you can read the second partition on, lol -- come on. How easy is that to solve?
    – goldilocks
    Jan 29, 2018 at 13:50
  • I was in the middle of a long reply to your comment when suddenly one word form your answer ("partition") switched on a light in my head (a bright one :)). I was flashing the SD cards on a Windows system so the only thing I was seeing is the FAT32 /boot partition, the one with actual data was hidden. Now I understand what you are saying and I will just mount the data partition to update (as you mention) either systemd with a service or /etc/rc.local. Thanks and sorry for the back-and-forth, I use Linux since 1993 but am learning everyday (especially when things are obvious). Thanks again.
    – WoJ
    Jan 29, 2018 at 15:48

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.