I have found myself repeatedly setting up all my pi's with raspbian in pretty much the same manner using raspi-config.

Is there a way to extract all the settings that I've made using raspi-config into an executable script that I could download with wget to each new pi I set up?

A similar solution with the same effect would also be appreciated. I guess I could try one of the rpi docker implementations but I'm not that eager to find out how bleeding edge that stuff is.

  • 1
    it depends on what configuration you would like to do ? raspi-config modify configurations files that you can modify using a other way (/boot/config.txt,/etc/module.conf...) – mpromonet Mar 22 '15 at 13:02
  • It's a pretty simple 1000 line shell script in /usr/bin, if that helps. If you want to disable it starting up with a fresh images, delete /etc/init.d/apply_noobs_os_config and the link in /etc/rc2.d. – goldilocks Mar 22 '15 at 13:34
  • Just as raspi-config concentrates all the basic setup tasks to one place without requiring me to know how to do each task I'd like a simple DSL that let's me specify all settings in one file. Kind of like docker. – 8DH Mar 22 '15 at 17:04
  • Why not just use docker? – Tim Holt Mar 22 '15 at 18:27
  • Yeah, why not? What is the preferred docker solution for rpi? – 8DH Mar 22 '15 at 20:11
up vote 9 down vote accepted

At least nowadays, raspi-config seems to support noninteractive mode:

cat /boot/cmdline.txt            # show original cmdline.txt
raspi-config nonint do_serial 1  # disable serial console
cat /boot/cmdline.txt            # confirm changes
raspi-config nonint do_serial 0  # enable serial console
cat /boot/cmdline.txt            # confirm changes

with this, you can write setup scripts that can do anything you could do via the interactive command, and it will do exactly the same things. You will need to find the relevant commands and their usage from the script's source, though.

  • That is wonderful! – 8DH May 31 '16 at 13:16
  • So when I prepare a SD card I could put the image there, add my script to the folder and then run the script when the pi has booted. – 8DH May 31 '16 at 13:18
  • Are there any other improvements to this procedure that I'm missing? – 8DH May 31 '16 at 13:18
  • That is everything I'm aware of - if there is more, it's not very visibly documented. I stumbled upon this while looking into the script, and didn't look for further information after I found this feature. – Silly Freak May 31 '16 at 14:43
  • @8DH Is there something you can't handle with this method? (if it's still relevant to you personally) – Silly Freak May 31 '16 at 14:45

This is still not documented anywhere, but the rc_gui tool (I'm assuming it would be a graphical user interface to the raspi-config if I were to ever install the full desktop) uses command line options to the raspi-config bash script. You can see the full list of options in the C source code

/* Command strings */
#define GET_CAN_EXPAND  "sudo raspi-config nonint get_can_expand"
#define EXPAND_FS       "sudo raspi-config nonint do_expand_rootfs"
#define GET_HOSTNAME    "sudo raspi-config nonint get_hostname"
#define SET_HOSTNAME    "sudo raspi-config nonint do_hostname %s"
#define GET_BOOT_CLI    "sudo raspi-config nonint get_boot_cli"
#define GET_AUTOLOGIN   "sudo raspi-config nonint get_autologin"
#define SET_BOOT_CLI    "sudo raspi-config nonint do_boot_behaviour B1"
#define SET_BOOT_CLIA   "sudo raspi-config nonint do_boot_behaviour B2"
#define SET_BOOT_GUI    "sudo raspi-config nonint do_boot_behaviour B3"
#define SET_BOOT_GUIA   "sudo raspi-config nonint do_boot_behaviour B4"
#define GET_BOOT_WAIT   "sudo raspi-config nonint get_boot_wait"
#define SET_BOOT_WAIT   "sudo raspi-config nonint do_boot_wait %d"
#define GET_SPLASH      "sudo raspi-config nonint get_boot_splash"
#define SET_SPLASH      "sudo raspi-config nonint do_boot_splash %d"
#define GET_OVERSCAN    "sudo raspi-config nonint get_overscan"
#define SET_OVERSCAN    "sudo raspi-config nonint do_overscan %d"
#define GET_CAMERA      "sudo raspi-config nonint get_camera"
#define SET_CAMERA      "sudo raspi-config nonint do_camera %d"
#define GET_SSH         "sudo raspi-config nonint get_ssh"
#define SET_SSH         "sudo raspi-config nonint do_ssh %d"
#define GET_VNC         "sudo raspi-config nonint get_vnc"
#define SET_VNC         "sudo raspi-config nonint do_vnc %d"
#define GET_SPI         "sudo raspi-config nonint get_spi"
#define SET_SPI         "sudo raspi-config nonint do_spi %d"
#define GET_I2C         "sudo raspi-config nonint get_i2c"
#define SET_I2C         "sudo raspi-config nonint do_i2c %d"
#define GET_SERIAL      "sudo raspi-config nonint get_serial"
#define GET_SERIALHW    "sudo raspi-config nonint get_serial_hw"
#define SET_SERIAL      "sudo raspi-config nonint do_serial %d"
#define GET_1WIRE       "sudo raspi-config nonint get_onewire"
#define SET_1WIRE       "sudo raspi-config nonint do_onewire %d"
#define GET_RGPIO       "sudo raspi-config nonint get_rgpio"
#define SET_RGPIO       "sudo raspi-config nonint do_rgpio %d"
#define GET_PI_TYPE     "sudo raspi-config nonint get_pi_type"
#define GET_OVERCLOCK   "sudo raspi-config nonint get_config_var arm_freq /boot/config.txt"
#define SET_OVERCLOCK   "sudo raspi-config nonint do_overclock %s"
#define GET_GPU_MEM     "sudo raspi-config nonint get_config_var gpu_mem /boot/config.txt"
#define GET_GPU_MEM_256 "sudo raspi-config nonint get_config_var gpu_mem_256 /boot/config.txt"
#define GET_GPU_MEM_512 "sudo raspi-config nonint get_config_var gpu_mem_512 /boot/config.txt"
#define GET_GPU_MEM_1K  "sudo raspi-config nonint get_config_var gpu_mem_1024 /boot/config.txt"
#define SET_GPU_MEM     "sudo raspi-config nonint do_memory_split %d"
#define GET_HDMI_GROUP  "sudo raspi-config nonint get_config_var hdmi_group /boot/config.txt"
#define GET_HDMI_MODE   "sudo raspi-config nonint get_config_var hdmi_mode /boot/config.txt"
#define SET_HDMI_GP_MOD "sudo raspi-config nonint do_resolution %d %d"
#define GET_WIFI_CTRY   "sudo raspi-config nonint get_wifi_country"
#define SET_WIFI_CTRY   "sudo raspi-config nonint do_wifi_country %s"
#define CHANGE_PASSWD   "(echo \"%s\" ; echo \"%s\" ; echo \"%s\") | passwd"

UPDATE: I notice that there is nothing in there about the locale or keyboard settings. So, that suggests to me that we must examine the source of raspi-config. Luckily we have plenty examples above to get an idea of how to use that script noninteractively. So, what I need to do to solve this problem headlessly is:

locale=en_US.UTF-8
layout=us
sudo raspi-config nonint do_change_locale $locale
sudo raspi-config nonint do_configure_keyboard $layout

The variables are the values I would have selected from the curses UI. Locale options are the first field in the file /usr/share/i18n/SUPPORTED. Keyboard layout options are the directory names in /usr/share/X11/xkb/symbols/. Being in the US, I use en_US.UTF-8 and us. YMMV

  • 1
    If you are interested in automating the setup of Raspberry Pis, you should check out my pi-init2 project on github. It provides the long-requested feature of "run a script on boot (headlessly)". – Bruno Bronosky Apr 11 at 16:18

Use dd (or similar) to copy the working Pi image to your PC.

Use dd (or similar) to copy the copied image from your PC to your Pi.

man dd

  • Yeah, there is of course the image way but then I would need to maintain the image with updates and stuff. (unless there is an elegant solution for that as well...) – 8DH Mar 22 '15 at 16:59
  • @8DH, your suggestion of downloading settings then uploading also means you have to maintain an "image" with updates as well. – Tim Holt Mar 22 '15 at 18:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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