I have a custom Ubuntu Server ISO that answers installation questions via preseed and kickstart files. It also installs additional .debs I've placed on the ISO during the actual installation as well. This all works fine.

Now I need a way for a script to run on the first boot up for configuration needs. The post install script does not seem to be working (in the kickstart file). I'm reduced to using systemd or the rc.local file (at least I think those are my only options...).

Which one is easiest for simply kicking off a script that will already live on the ISO with absolutely no hands on the keyboard? Systemd seems to need me to enable the service first which is not acceptable (again, no hands on keyboard). I'm leaning towards rc.local but this post says not to use it: "Purpose and typical usage of /etc/rc.local".

Should I ignore that warning? Wondering if there are simpler ways as well.

  • An @reboot cron job might also do the trick, assuming cron is running and such.
    – thrig
    Mar 23 '16 at 22:01
  • Hmm but this script needs to run on first boot without anyone touching the keyboard to run a command/script. Is it possible to put the custom cron file in a custom deb package and have that placed on the filesystem during installation? Then maybe the script will be ran automatically. Mar 23 '16 at 22:04
  • If you can put a script in /etc/rc.local you can put a service file in /etc/systemd/system/multi-user.target.wants/...
    – jasonwryan
    Mar 24 '16 at 21:30

I followed shvahabi's advice here https://askubuntu.com/questions/9853/how-can-i-make-rc-local-run-on-startup. Basically, I'm enabling and using rc.local on the ubuntu box. Rc.local is normally not used on debian. It's very similar to Window's registry run keys. Ultimately I'll have my first boot configuration script AND the custom rc.local file in a custom deb package that places the files on the box at installation time (custom deb lives on the ISO itself). Then, on every boot, the rc.local will run my script and I can put a check in so that it only runs on the first boot.

Important note: edit and use "/etc/rc.local" to place a line to run your script... NOT "/etc/init.d/rc.local". The second one is actually controlled by another package and will NOT let you install a custom version of it from a custom deb file during installation. The init.d version's sole purpose is to call the "/etc/rc.local" one anyways.

I'm not using systemd or upstart because you need to type in commands to start the services first. This needed to be hands free. HOWEVER, I believe all those commands do is make link files, but I didn't feel like figuring out where to place those. Two files in a custom deb package is easiest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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