Once the RasPi boots for first time, it shows the raspi-config utitliy. But on next boot it's gone.

I would like to run it during first boot, do some configuration stuff, and then re-enable it in order to automatically run one more time on the next (or second) boot. I found this link, but it seems that it's outdated and couldn't make it work: https://www.raspberrypi.org/forums/viewtopic.php?t=103512

In summary, what I need is:

  • 1st Boot: Run it automatically.
  • 2nd Boot: run it automatically.
  • Never run it again automatically

Is there a command that I can run on the terminal before shutting down the RasPi (during first boot) that re-enables raspi-config to automatically run on the next start? Or is there something I can edit in a configuration file?

  • Why????????????
    – Milliways
    Feb 21, 2019 at 12:18
  • raspi-config is a tool made for user interaction. It doesn't make sense to use it for automatic configuration.
    – Ingo
    Feb 21, 2019 at 22:06
  • Who mentioned automatic configuration? What I need is to trigger manual configuration on the 1st and 2nd boots. So the only thing I'm looking for is at what flag or whatever is saved somewhere once raspi-config has ran, in order to revert it.
    – nbloqs
    Feb 22, 2019 at 9:39
  • To be fair to @nbloqs , I found not all raspi-config commands can be executed outside of the utility directly from the CLI. But yes, one's goal should be unattended, scripted configuration without user interaction being required. Full scripting is the only way you assure consist and reproducible results.
    – F1Linux
    Mar 4, 2019 at 17:27
  • Could you tell us what you want to achieve? It would be easier to come up with a solution.
    – Paradox
    Mar 7, 2019 at 4:56

2 Answers 2


A fresh Raspbian actually has two stages that run automatically during the initial boot. The first is to run the init_resize.sh script to expand the second partition to fill the SD card, this triggers a reboot. If you look in the cmdline.txt of an unused SD card you'll see

... init=/usr/lib/raspi-config/init_resize.sh

at the end of the line, this tells the kernel to run the init_resize.sh script rather then the usual SystemD processes. The init_resize.sh script has a line like

sed -i 's| init=/usr/lib/raspi-config/init_resize.sh||' /boot/cmdline.txt

that removes the option from cmdline.txt when the resize is complete and then triggers a reboot.

On second boot, when LXDE starts, it goes through the files in /etc/xdg/autostart/ that includes one that runs piwiz. I've not checked this myself but running strings piwiz suggests that piwiz deletes the /etc/xdg/autostart/piwiz.desktop file at some point. I guess, to re-run the wizard, you need to re-create that file (or make a backup before closing the wizard):

[Desktop Entry]
Name=Raspberry Pi First-Run Wizard
Name[en_GB]=Raspberry Pi First-Run Wizard
GenericName=Raspberry Pi First-Run Wizard
GenericName[en_GB]=Raspberry Pi First-Run Wizard
Comment=Configure Raspberry Pi system on first run
Comment[en_GB]=Configure Raspberry Pi system on first run
Exec=sudo piwiz
  • Thanks, I will try it out. I voted up your question, and if this work will mark it as the accepted one.
    – nbloqs
    Mar 3, 2019 at 12:59
  • It did not work.
    – nbloqs
    Mar 3, 2019 at 20:53
  • @nbloqs See amended answer, I was looking for the wrong thing (raspi-config rather than piwiz). Mar 4, 2019 at 15:40
  • Thanks, I will test this weekend and will tell here how it goes.
    – nbloqs
    Mar 5, 2019 at 22:57

Always best to illustrate an answer with an example, so I'll use SSH as you don't specify what you're trying to do with raspi-config

The 2nd test should test for the change made the first time raspi-config was executed. For instance, if the first time you executed raspi-config was to enable SSH (which is probably the first thing 99.9% of most users do) you could test to see if SSH was enabled and (validating the first execution happened), then the action would be to execute raspi-config the second time and delete the script after doing so:


if [[ $(sudo systemctl list-unit-files|grep ssh.service|awk '{print $2}') = 'enabled' ]]; then
    echo "SSH is ENABLED so raspi-config has been executed ONCE previously: Executing for 2nd time:"
    sudo raspi-config
    rm /etc/rc.local/thisScript.sh
    echo "SSH *NOT* ENABLED so raspi-config NOT executed previously- starting now:"
    sudo raspi-config

The awk '{print $2}'prints just the output of the first command: either enabled or disabled. The test could be rewritten to be != then do the action.

Of course if the reason you were executing raspi-config was to set SSH to start on boot, you could write a script that does that directly without user input, substituting the SystemD command to enable SSH in lieu of running raspi-config:


if [[ $(sudo systemctl list-unit-files|grep ssh.service|awk '{print $2}') = 'enabled' ]]; then
    sudo systemctl enable ssh.service

Anyhoo, lots of ways to skin this cat, but try for unattended configuration as your ultimate goal, scripting as much as possible to ensure consistency on rebuilds. HTH-

  • Thank you so much! The other answer just worked.
    – nbloqs
    Mar 7, 2019 at 11:42

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.