B.5. 高级选项

B.5.1. 安装过程中运行用户命令

预置工具提供了一个非常强大和灵活的选项,可以在安装过程的一些环节运行命令或脚本。

当目标系统的文件系统挂载后,它可以在 /target 中使用。如果使用安装 CD,则挂载后可以在 /cdrom 中使用。

  1. # d-i preseeding is inherently not secure. Nothing in the installer checks
  2. # for attempts at buffer overflows or other exploits of the values of a
  3. # preconfiguration file like this one. Only use preconfiguration files from
  4. # trusted locations! To drive that home, and because it's generally useful,
  5. # here's a way to run any shell command you'd like inside the installer,
  6. # automatically.
  7. # This first command is run as early as possible, just after
  8. # preseeding is read.
  9. #d-i preseed/early_command string anna-install some-udeb
  10. # This command is run immediately before the partitioner starts. It may be
  11. # useful to apply dynamic partitioner preseeding that depends on the state
  12. # of the disks (which may not be visible when preseed/early_command runs).
  13. #d-i partman/early_command \
  14. # string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
  15. # This command is run just before the install finishes, but when there is
  16. # still a usable /target directory. You can chroot to /target and use it
  17. # directly, or use the apt-install and in-target commands to easily install
  18. # packages and run commands in the target system.
  19. #d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh

B.5.2. 使用预置修改默认值

也可以使用预置修改问题的默认答案,但同时显示问题。这需要在问题设定值之后,必须将 seen 旗标重置为 “false”。

  1. d-i foo/bar string value
  2. d-i foo/bar seen false

要对所有问题达到同样效果,可以通过在启动引导符后面设置 preseed/interactive=true。这对于测试和调试您的预置文件很有帮助。

注意,“d-i” owner 只应该用于安装程序里面的变量。对于那些属于目标系统软件包的变量,您应该使用软件包的名字替代。请参考 第 B.2.2 节 “使用引导参数预置问题的答案” 的脚注。

如果使用引导参数预置,您可以通过 “?=” 操作符让安装程序询问相关的问题,例如,*`foo`*/*`bar`*?=*`value`* (或者 *`owner`*:*`foo/bar`*?=*`value`*)。当然,这只会影响在安装时显示出来的问题对应的参数,而不是“内部的”参数。

获得更多的调试信息,需使用引导参数 DEBCONF_DEBUG=5。这将让 debconf 打印更多的细节,包括当前变量设置和每个软件包安装脚本的进度。

B.5.3. 预置文件链

可以在一个预置文件里面包含另外的预置文件。这些文件里面的任何设置将覆盖前面加载的设置。有一种用法,例如,通用的网络设置放在一个文件,其他规格的设置放在另外的文件里面。

  1. # More than one file can be listed, separated by spaces; all will be
  2. # loaded. The included files can have preseed/include directives of their
  3. # own as well. Note that if the filenames are relative, they are taken from
  4. # the same directory as the preconfiguration file that includes them.
  5. #d-i preseed/include string x.cfg
  6. # The installer can optionally verify checksums of preconfiguration files
  7. # before using them. Currently only md5sums are supported, list the md5sums
  8. # in the same order as the list of files to include.
  9. #d-i preseed/include/checksum string 5da499872becccfeda2c4872f9171c3d
  10. # More flexibly, this runs a shell command and if it outputs the names of
  11. # preconfiguration files, includes those files.
  12. #d-i preseed/include_command \
  13. # string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
  14. # Most flexibly of all, this downloads a program and runs it. The program
  15. # can use commands such as debconf-set to manipulate the debconf database.
  16. # More than one script can be listed, separated by spaces.
  17. # Note that if the filenames are relative, they are taken from the same
  18. # directory as the preconfiguration file that runs them.
  19. #d-i preseed/run string foo.sh

也可以通过在前面设置 preseed/url 从 initrd 或者文件预置链载进入网络预置。这将使网络预置在网络连通时执行。您应该小心使用,因为这是两种预置,意味着您有机会执行 preseed/early 命令,第二个可以在网络连通后使用。