How do you add a script to execute at system boot in Linux?

Prepare for the Linux Professional Institute Certification Level 1. Use flashcards and multiple choice questions, complete with hints and explanations. Enhance your understanding and get ready to ace the exam!

Adding a script to execute at system boot in Linux can be achieved mainly through two methods: modifying the /etc/rc.local file or creating a systemd service.

The /etc/rc.local file is a traditional method used in many Linux distributions. The scripts or commands added to this file will be executed at the end of the boot process. This approach is straightforward and effective for running simple commands or scripts upon system boot.

On the other hand, creating a systemd service is the modern and more flexible approach, particularly for systems that use systemd as their init system. By defining a service unit file, systemd allows for detailed configuration, including service dependencies, execution order, and more advanced handling of the script, such as automatic restarts on failure.

Together, these methods provide a comprehensive way to ensure that scripts are executed during the boot process, making option A the most effective and correct response for the question. Other options do not adequately fulfill the requirement of executing scripts at boot time. For example, including scripts in /etc/init.d/ may still work for some legacy systems, while placing scripts in /usr/bin/ simply makes them executable without controlling when they run. Finally, using crontab is typically for scheduling tasks at specified times

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy