预置工具提供了一个非常强大和灵活的选项,可以在安装过程的一些环节运行命令或脚本。
当目标系统的文件系统挂载后,它可以在 /target
中使用。如果使用安装 CD/DVD,则挂载后可以在 /cdrom
中使用。
# d-i preseeding is inherently not secure. Nothing in the installer checks # for attempts at buffer overflows or other exploits of the values of a # preconfiguration file like this one. Only use preconfiguration files from # trusted locations! To drive that home, and because it's generally useful, # here's a way to run any shell command you'd like inside the installer, # automatically. # This first command is run as early as possible, just after # preseeding is read. #d-i preseed/early_command string anna-install some-udeb # This command is run immediately before the partitioner starts. It may be # useful to apply dynamic partitioner preseeding that depends on the state # of the disks (which may not be visible when preseed/early_command runs). #d-i partman/early_command \ # string debconf-set partman-auto/disk "$(list-devices disk | head -n1)" # This command is run just before the install finishes, but when there is # still a usable /target directory. You can chroot to /target and use it # directly, or use the apt-install and in-target commands to easily install # packages and run commands in the target system. #d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh
也可以使用预置修改问题的默认答案,但同时显示问题。这需要在问题设定值之后,必须将 seen 旗标重置为 “false”。
d-i foo/bar string value 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
打印更多的细节,包括当前变量设置和每个软件包安装脚本的进度。
可以在一个预置文件里面包含另外的预置文件。这些文件里面的任何设置将覆盖前面加载的设置。有一种用法,例如,通用的网络设置放在一个文件,其他规格的设置放在另外的文件里面。
# More than one file can be listed, separated by spaces; all will be # loaded. The included files can have preseed/include directives of their # own as well. Note that if the filenames are relative, they are taken from # the same directory as the preconfiguration file that includes them. #d-i preseed/include string x.cfg # The installer can optionally verify checksums of preconfiguration files # before using them. Currently only md5sums are supported, list the md5sums # in the same order as the list of files to include. #d-i preseed/include/checksum string 5da499872becccfeda2c4872f9171c3d # More flexibly, this runs a shell command and if it outputs the names of # preconfiguration files, includes those files. #d-i preseed/include_command \ # string if [ "`hostname`" = bob ]; then echo bob.cfg; fi # Most flexibly of all, this downloads a program and runs it. The program # can use commands such as debconf-set to manipulate the debconf database. # More than one script can be listed, separated by spaces. # Note that if the filenames are relative, they are taken from the same # directory as the preconfiguration file that runs them. #d-i preseed/run string foo.sh
也可以通过在前面设置 preseed/url 从 initrd 或者文件预置链载进入网络预置。这将使网络预置在网络连通时执行。您应该小心使用,因为这是两种预置,意味着您有机会执行 preseed/early 命令,第二个可以在网络连通后使用。