启动时运行命令

启动时运行命令

我的问题如下:我想修改我的 Ubuntu LiveCD 以在启动时运行几个命令,但我是 Ubuntu 开发新手,不知道如何做到这一点。每次启动 Ubuntu 时运行这些命令的正确方法是什么?

以下是示例命令:

sudo rm /home/ubuntu/Desktop/examples.desktop
sudo perl -e 'print("[DesktopEntry]\nVersion=1.0\nType=Application\nTerminal=false\nIcon=xinput_calibrator\nName=Calibraion\nExec=env /usr/bin/xinput_calibrator\n");' > /home/ubuntu/Desktop/Calibrate.desktop
sudo /home/ubuntu/Desktop/Calibrate.desktop

编辑!!!

我实际上已经尝试修改 rc.local 文件,现在它看起来像这样:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo rm /home/ubuntu/Desktop/examples.desktop
sudo perl -e 'print("[DesktopEntry]\nVersion=1.0\nType=Application\nTerminal=false\nIcon=xinput_calibrator\nName=Calibraion\nExec=env /usr/bin/xinput_calibrator\n");' > /home/ubuntu/Desktop/Calibrate.desktop
sudo /home/ubuntu/Desktop/Calibrate.desktop

exit 0

但我仍然不知道它是否会起作用。我想在构建 iso 之前确定一下。

编辑2!!!

我已经使用本教程构建了 iso 文件: https://help.ubuntu.com/community/LiveCDCustomization 我已经完成步骤:

  1. 提取 CD .iso 内容
  2. 提取桌面系统
  3. 然后我编辑了 rc.local 文件并保存
  4. 组装文件系统(我省略了“重新生成清单”点)

现在我收到错误

未找到 init。尝试传递 init=bootarg

在启动我的 LiveCD 时。

传递 init=bootarg 会导致:

/bin/sh:bootarg:未找到

我究竟做错了什么?

谢谢

答案1

在 Ubuntu 启动时执行脚本

Edit /etc/rc.local and add your commands
The script must always end with exit 0 

重启 Ubuntu 时执行脚本

Put your script in /etc/rc0.d
Make it executable (sudo chmod +x myscript)
Note: The scripts in this directory are executed in alphabetical order 

您的脚本名称必须以 K99 开头才能在正确的时间运行。

我不确定这是否会对您的情况有所帮助,但我会再多看看,看看我能找到什么办法。

关机时执行脚本

Put your script in /etc/rc6.d
Make it executable (sudo chmod +x myscript)
Note: The scripts in this directory are executed in alphabetical order 

您的脚本名称必须以 K99 开头才能在正确的时间运行。

这个问题之前已经问过,这里是链接。 如何在 ubuntu 12.04 登录时运行命令?

答案2

这是一次失败的构建。换句话说,它有故障,您需要使用另一张光盘。如果您决定使用其他光盘,请确保使用不同类型的光盘以排除其他问题。您需要确保这样做,以便我们继续进行故障排除。这是第一步。失败的构建非常常见,在尝试执行此类操作时,这应该始终是进行故障排除的第一步。如果您尝试这样做但仍然收到相同的错误,请回复我,我有一个朋友经常做这种事,我会把这件事传给他,看看他怎么想。但与此同时,要忙起来。

谨致问候,

马修·考尔弗斯

相关内容