To set the boot command in the Ubuntu system, you can follow the steps below:
- Create a startup script: First, use a text editor such as nano or vim to create a startup script file, for example
startup.sh
:
sudo nano /etc/init.d/startup.sh
- Add commands or programs to be executed in the script file. For example, assuming you want to start a
myprogram
program called at boot time, you can add the following to your script file:
#!/bin/bash
/path/to/myprogram
Please /path/to/myprogram
replace with the path of the actual program.
- Save and close the file. Then, add execution permission to the script file:
sudo chmod +x /etc/init.d/startup.sh
- Create a boot link: Run the following command to add a boot script to the boot sequence:
sudo update-rc.d startup.sh defaults
Now your startup script will be executed automatically every time the system boots. Make sure that the path to the command or program specified in the script is correct. You can adjust startup behavior and add additional commands by editing the script file.
Note: Starting from Ubuntu 16.04, using /etc/init.d/
the startup script in the directory is outdated, and it is recommended to use /etc/systemd/system/
the systemd service unit in the directory for management. If you're using a newer Ubuntu version, consider using systemd to set it up on boot.