Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to install an init script that only runs on the first boot after it's installation. How can I accomplish that on Ubuntu?

share|improve this question
Why do you need to do that? – Khaled May 2 '12 at 9:27
I need it for an EC2 AMI. I want to make certain modifications depending on the provided user-data. – Jan Deinhard May 2 '12 at 11:05

You can use a trick like this to avoid executing the script more than once:

test ! -e /path/to/chosen/file || exit 0
touch /path/to/chosen/file
echo "Executing my job"

You can run the above script only once. Other executions will exit because the file should be created in the first execution. Of course, you need to have enough permissions to create the file.

To keep this valid after reboot, you need to avoid creating the file under a temporary file system like /tmp. Also, this prevent multiple execution of the script regardless of whether it is executed manually or part of startup process.

share|improve this answer

There are a few tools within the oem-config packages to carry out initial configuration immediately following installation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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