3

Is it possible to create a script as part of the NOOBS installation files in the FAT32 partition on the SD card, so this script runs automatically after the installation of NOOBS?

I need this in order to modify the default installation files, in order to customize each NOOBS installation, e.g. hostname or IP.

Darth Vader
  • 4,206
  • 24
  • 45
  • 69
  • Do you want this to run inside the NOOBs installer, or inside one of the operating systems installed by NOOBs (e.g. Raspbian) when it is booted? – goldilocks May 19 '15 at 13:04
  • @goldilocks: Both would be OK. If during installation, then the script can just create files for running after boot as long as the FS is visible. Prefered is just to run it in the OS once installed, as for example a batch script running once the OS has booted. – Morten Zilmer May 19 '15 at 13:08

1 Answers1

1

If you want to run a script during the boot process of one of the OS's proper, you'll have to tackle each OS specifically, although some of them may use more or less the same mechanism.

For Raspbian wheezy, this is init, which then starts the scripts linked from /etc/init.d to /etc/rc[N].d, where N is 2 - 5, but probably 2 by default (see /etc/inittab). Jessie uses a different init system, but it should still be backward compatible with this one. For information about how to add scripts to be run, see /etc/init.d/README.txt or just look around online for "debian sysv init" and you'll find lots of information -- it has been in use in this form for 20+ years (and similar ones since ~1980).

Raspbian does pretty much what you want to do in order to present you with raspi-config the first time you boot. This is done via /etc/init.d/apply_noobs_os_config; if raspi-config then runs successfully, it deletes itself:

if raspi-config --apply-os-config; then
  rm /etc/init.d/apply_noobs_os_config && update-rc.d apply_noobs_os_config remove
  log_end_msg 0
else

You could follow the same methodology, or you could insert something here to run after raspi-config, or, if you are comfortable enough with shell speak, you could modify /usr/bin/raspi-config; it is fairly simple and uses something called whiptail for the TUI menus, etc.

If what you want to do does not require user interaction, things may be even easier depending on where you are sourcing whatever data it is you need.

goldilocks
  • 58,849
  • 17
  • 112
  • 227
  • Thanks for the answer, but how do I make this part of the NOOBS installation files in the FAT32 partition on the SD card? The references above are to the filesystem (FS) created on the SD during installation, but I can't see how this is available in the initial installation files on the FAT32 partition before the installation. – Morten Zilmer May 19 '15 at 13:48
  • I think the current NOOBs comes with Raspbian pre-installed -- but to do it to an OS during/post install should be possible. You'll have to look at the scripts used to do the downloading and installation, and add to those to run something post. Someone here may have dug into that stuff before (I haven't), but presuming you can read python or shell or whatever is used (I doubt it is compiled), it should not be too hard. If you can't, you are probably out of luck unless there is some end user oriented hook, which presumably would be documented. – goldilocks May 19 '15 at 14:00