自动安装后运行命令

use*_*831 6 system-installation subiquity

我正在通过 UEFI HTTP 引导、subiquity 和 NoCloud 数据源安装 Ubuntu 20.04 服务器。实际安装有效,我让基本操作系统运行起来。

安装完成后,或者安装程序重新启动后首次启动时,我还需要配置一些内容。

我尝试过各种方法user-data

  write_files:
    - path: /target/etc/example.conf
      permissions: 644
      content: |
        example content
    - path: /target/var/lib/cloud/scripts/per-once/test.sh
      permissions: 755
      content: |
        #!/bin/sh
        date > /tmp/i_ran
        date
        echo test1
  runcmd:
    - echo test2 > /tmp/test2
    - cloud-init-per once testing echo test3
    - [ cloud-init-per, once, testing2, touch, /tmp/test4 ]
    - [ curtin, in-target, --target=/target, --, cloud-init-per, once, testing3, touch, /tmp/testing5 ]
  late-commands:
    - echo test5 > /target/etc/test5.conf
    - curtin in-target --target=/target -- cloud-init-per once testing9 touch /tmp/testing9

Run Code Online (Sandbox Code Playgroud)

命令运行(如 subiquity 调试日志中所示),但似乎没有在已安装的系统上留下任何痕迹。例如,我发现在/tmp或中没有文件,并且在重新启动后日志中没有消息。/etc我之前尝试过write_files使用和不使用/target它。

在目标上写入任意文件或安装后运行任意命令的预期方法是什么?

use*_*831 4

我不确定这是否是官方方法,但现在正在将文件写入目标系统的是:

 late-commands:
    - echo test5 > /target/etc/test5.conf
Run Code Online (Sandbox Code Playgroud)

我之前曾尝试过,但没有成功,但我只能假设我错过了一些其他错误,导致测试失败。

curtin in-target --target=/target -- cmd作为后期命令的一部分使用适用于运行命令。

我还没有设法让任何其他方法(例如cloud-init-perwrite_files)起作用。不过,这解决了我的燃眉之急。