How to create a new boot file in CentOS 7?

To generate a new startup file, you need to follow these steps:

  1. Open a terminal window and login to the CentOS 7 system as an administrator.
  2. Create a new startup script file using a text editor like vi or nano. For example, enter the following command to create a startup script file named myscript.sh using the vi editor:
sudo vi /etc/init.d/myscript.sh
  1. Add script code to the startup script file. This script will be executed when the system starts. For example, you can add the following code to the script file:
#!/bin/bash
# 这是我的启动脚本
echo "Hello, World!" >> /var/log/myscript.log
  1. Save and close the file. In the vi editor, press the Esc key, then type :wq and press Enter.
  2. Set the execution permission of the script file. Run the following command:
sudo chmod +x /etc/init.d/myscript.sh
  1. Add the script file to the system startup items. Run the following command:
sudo chkconfig --add myscript.sh
  1. verify configuration
sudo chkconfig --level 35 myscript.sh on

When you restart the CentOS 7 system now, the new startup script will automatically be executed. You can modify the script code and configuration as needed.

bannerAds