如何在第一次启动时运行脚本?

Dim*_*ima 5 linux centos boot start runlevel

我只需要在 CentOS 机器第一次启动(安装操作系统后)时运行一些 bash 脚本这个脚本应该网络服务启动之前运行(因为这个脚本会改变网络配置)我如何注册我的脚本在网络服务启动之前运行?

fre*_*eit 11

如果您查看 /etc/init.d/network 的“chkconfig”行,您将看到网络的启动优先级为“10”。

/etc/init.d/yourscript:
#!/bin/bash
#
# yourscript  short description
# 
# chkconfig: 2345 9 20
# description: long description

case "$1" in
  start)
    Do your thing !!!
    chkconfig yourscript off
  ;;
  stop|status|restart|reload|force-reload)
    # do nothing
  ;;
esac
Run Code Online (Sandbox Code Playgroud)

然后运行chkconfig yourscript on以使其在启动时运行。该chkconfig yourscript off脚本里面应该禁用它运行在任何后续的靴子。

CentOS/RHEL/Fedora 的某些版本有一个“firstboot”程序您可以尝试使用,但这似乎很痛苦。

您确定不能在 kickstart 的 %post 内运行您的网络重新配置脚本吗?我就是做这个的。