debian自动化安装

来源:互联网 发布:java数组的长度怎么看 编辑:程序博客网 时间:2024/05/16 23:35

http://www.debian.org/releases/stable/s390/apb.html.zh_CN



B.1. 介绍

预置提供了一种在安装过程中回答问题,而无须手动键入答案的途径。这让完全自动进行大多数的安装成为可能,并提供了一些普通安装方式下不具备的特性。

预置文件并非必须。如果您使用空的预置文件,安装程序就会跟正常手动安装一样。每个问题的预置(如果使用正确!)都会以同样的方式修改对应的基准。
B.1.1. 预置方法

一共有三种方法可用于预置: initrd、file 和 network。initrd 方法可以用于任何一种安装方式并支持较多的预置内容,但它需要做的准备工作也最多。file 和 network 方法分别用于不同的安装方式。

下面的表格显示了各种安装方式可选择的预置方法。 安装方式 initrd file network
CD/DVD yes yes yes[a]
netboot yes no yes
硬盘 yes yes yes[a]
generic/tape yes no yes

[a] 除非您有网络并正确设置 preseed/url



这些预置方法的主要不同之处在于何时预置文件被加载和处理。对于 initrd 方法,它是在第一个问题询问之前,安装开始的时候。对于 file 方法,它是在加载 CD 或 CD 映像之后。对 network 方法,它在网络配置完毕之后。

显而易见,在加载预置文件之前需要的过程都不能被预置(这里面包括只在 medium 或 low 优先级出现的问题,像首先运行的硬件检测)。第 B.2.2 节 “使用引导参数预置问题的答案” 提供了避免这些问题被询问的方法。

为了避免在预置之前询问,您可以让安装程序运行在 “auto” 模式。它延迟了预置之前出现询问问题(例如,语言、国家和键盘选择),直至连上网络,使它们可以进行预置。它还让安装运行在 critical 优先级下,避免不重要的问题。参阅 第 B.2.3 节 “auto 模式” 了解详细信息。
B.1.2. 限制

虽然使用这种方法能预先设置 debian-installer 的绝大多数问答,但还是有明显的例外。您必须(重新)分区整个硬盘,或者使用磁盘上的剩余空间; 但无法使用已经存在的分区。


B.2. 使用预置

您首先要创建一个预置文件,并将它置于希望使用的地方。创建预置文件在后面的附录中有说明。如果您打算使用网络预置或者从软盘或 U 盘读取,直接将它放到正确的地方就可以了。如果您希望将它放到 CD 或 DVD 上面,那就需要重新制作一个 ISO 映像文件。而如何将预置文件包含到 initrd 里面,超出了本文档的范围;请查询 debian-installer 开发者文档。

有一个预置文件的例子放在 http://www.debian.org/releases/squeeze/example-preseed.txt,您可以拿它作为自己预置文件的基础。此文件基于本附录所列的配置文件片段。
B.2.1. 加载预置文件

如果使用 initrd 预置,您只需确保一个名为 preseed.cfg 的文件包含在 initrd 的根目录里面。安装程序会自动检测并加载。

其他的预置方法,您需要在启动的时候告诉安装程序所使用的文件。这通过给内核传递引导参数完成,可以在启动时手动指定,或者编辑 bootloader 的配置文件(如: syslinux.cfg),并在内核的附加行后面添加参数。

如果在 bootloader 设置里指定预置文件,可以修改配置让您不再需要键入回车启动安装程序。对于 syslinux,这意味着在 syslinux.cfg 里面设置 timeout 为 1。

为了保证安装程序得到正确的预置文件,您可以选择为预置文件指定校验和。当前使用的是 md5sum,如果指定了,那么配置文件必须匹配,否则安装程序将拒绝使用。
指定引导参数:
- 如果使用网络启动:
preseed/url=http://host/path/to/preseed.cfg
preseed/url/checksum=5da499872becccfeda2c4872f9171c3d

- 如果从定制的 CD 启动:
preseed/file=/cdrom/preseed.cfg
preseed/file/checksum=5da499872becccfeda2c4872f9171c3d

- 如果用 USB 设备安装(将预置文件放入 U 盘的顶极目录):
preseed/file=/hd-media/preseed.cfg
preseed/file/checksum=5da499872becccfeda2c4872f9171c3d

注意,在作为引导参数的时候,preseed/url 可以简写为 url,preseed/file 简写为 file。
B.2.2. 使用引导参数预置问题的答案

如果预置文件无法设置一些步骤,安装也可以完全自动进行,这是因为您可以在引导安装程序时,在命令行上为内核传递预置的值。

引导参数可以在您不想使用预置的时候使用,但只提供一个特定问题的答案。在本手册中有一些这样的示例。

要设置 debian-installer 中使用的值,只须传递 path/to/variable=value,它们是本附录中所列的任何一个。如果该值是用于配置目标系统的软件包,您需要预先设置 owner:path/to/variable=value 中的 owner[19] 变量。如果您不指定 owner,该变量的值不会复制到目标系统上的 debconf 数据库,并在相关的软件包的配置中不使用。

通常,采用这种方式预置是为了问题不再被询问。为了设置一个问题的默认答案,并仍然显示问题,请使用 “?=” 替换 “=” 作为操作符。参阅 第 B.5.2 节 “使用预置修改默认值”。

注意,一些常用的引导参数变量有简写别名。如果有简写形式,它们将会被用在附录的例子里面替代全称。例如,preseed/url 变量简写为 url。另一个例子是 tasks,它转换成 tasksel:tasksel/first。

“--” 在启动选项中有特殊含义。最后一个 “--” 后面出现的内核参数将被复制到安装的 bootloader 设置(假如安装程序支持 bootloader)。安装程序可以自动发现它能识别的选项(就像预置选项)。
注意

当前的 linux 内核(2.6.9 和更新的),可以指定最多 32 个命令行选项和 32 个环境变量选项,包括安装程序默认的选项。如果数目超出,内核将崩溃。(早期的内核,接受的数目更少。)

大多数安装过程,在引导配置文件中一些默认的选项,比如 vga=normal,可以放心地删除,这让您可以添加更多的预置选项。
注意

引导参数中即使使用引号,也可能无法夹杂空格。
B.2.3. auto 模式

Debian 安装程序提供了一些特性,可以组合引导提示符后面的简单命令行,达到复杂的自动安装效果。为了表达清楚,这里有一些例子,可以用在引导提示符后面:
auto url=autoserver

这需要一个 DHCP 服务器能找到并且 DNS 可以解析 autoserver,或许要加上 DHCP 提供的本地域名。 如果域名是 example.com,并有相应的 DHCP 设置,那么预置文件将从 http://autoserver.example.com/d-i/squeeze/./preseed.cfg 获得。

url 的最后一部分(d-i/squeeze/./preseed.cfg)来自 auto-install/defaultroot。默认包括 squeeze 目录,让将来的版本在可控的方式下指定自己的代号。/./ 位用来定位相对于根目录的子目录(用于 preseed/include 和 preseed/run)。使文件可以指定为完整路径、以 / 开始的位置或者相对于最后一个预置的文件。这样可以建立更具移植性的脚本,让各级脚本完整地移动到新的位置而不被破坏。比如,复制 web 服务器上的文件到 U 盘。本例中,如果预置文件的 preseed/run 为 /scripts/late_command.sh,那么文件将从 http://autoserver.example.com/d-i/squeeze/./scripts/late_command.sh 获得。

如果本地没有 DHCP 或 DNS,或者您不想使用 preseed.cfg 的默认路径,可以直接指定路径。并且,如果不使用 /./ 元素,它将定位到路径的起始点 (例如 URL 中的第三个 /)。下面的例子是局域网中最基本的要求:
auto url=http://192.168.1.2/path/to/mypreseed.file

它会以下列方式运作:


如果 URL 不含协议,就使用 http


如果主机名不含域名,将使用 DHCP 提供的,并且


如果主机名后面没有 /,那么将加上默认路径。


除了指定 url 之外,您还可以指定不直接影响 debian-installer 自己行为的设置,但是可以传递到预置文件加载的 preseed/run 中的脚本。当前,只有一个 auto-install/classes,它的别名是 classes。可以这样用:
auto url=example.com classes=class_A;class_B

classes 可以指定系统的类型,或者本地化信息。

只要您愿意,当然可以扩充这个概念,合理应用 auto-install 名字空间就是为了这个目的。这就可能会有诸如 auto-install/style 的内容加入到您的脚本。如果您觉得需要这样做,请发邮件到 <debian-boot@lists.debian.org> 邮件列表说明,我们可以避免名字空间的冲突,还可能会为您增加一个参数的别名。

auto 引导标签并未在所有地方定义。在内核命令行上可以通过添加 auto=true priority=critical 两个参数达到同样的效果。auto 参数是 auto-install/enable 的别名,将其设为 true 可以延迟 locale 和键盘等问题的提出,使其可以提供预置,其中 priority 是 debconf/priority 的别名,设置它为 critical 可以禁止在较低优先级下的问题提出。

在使用 DHCP 自动安装时还有一个有趣的额外选项:interface=auto netcfg/dhcp_timeout=60,这让机器使用第一个可用的网卡并耐心地等待 DHCP 的查询。
提示

更多使用此框架的例子,包括示例脚本和类,可以在其开发者的网站找到。那里的例子还显示出预置可以达到更多的效果。
B.2.4. 预置中有用的别名

下面这些别名在使用(自动)预置时很有用处。注意,它们是提问名称的简写别名,您同时需要指定一个对应的值:例如,auto=true 或 interface=eth0。 auto auto-install/enable
classes auto-install/classes
fb debian-installer/framebuffer
language debian-installer/language
country debian-installer/country
locale debian-installer/locale
priority debconf/priority
file preseed/file
url preseed/url
interface netcfg/choose_interface
hostname netcfg/get_hostname
domain netcfg/get_domain
protocol mirror/protocol
suite mirror/suite

B.2.5. 使用 DHCP 服务器指定预置文件

还可以使用 DHCP 来指定从网络下载的预置文件。DHCP 允许指定文件名。通常是用于 netboot 的文件,但如果是一个 URL,那么支持网络预置的安装介质就会从该 URL 下载,并用作预置文件。这里有一个在 dhcpd.conf 中使用的例子,它用于 ISC DHCP 服务器第 3 版(Debian 里面是 dhcp3-server 软件包)。
if substring (option vendor-class-identifier, 0, 3) = "d-i" {
filename "http://host/preseed.cfg";
}

注意,上面的例子中使用的文件名限定 DHCP 客户端自己是 "d-i",因此仅适用于安装程序,而对普通的 DHCP 客户端无效。您可以将只用于一个特殊主机的文字放在一段,以避免预置网络中的其他安装。

使用 DHCP 预置的一个好方法是仅预置网络相关的值,比如所使用的 Debian 镜像。这种方式下在网络中安装将会自动选择一个合适的镜像,而其余的安装部分仍可以交互进行。使用 DHCP 预置进行完整的 Debian 自动安装应该特别小心。


[19] debconf 变量(或模板)的 owner 通常是包含对应 debconf 模板的软件包明。对于安装程序自己使用的变量,owner 是 “d-i”。模板和变量可以有多个 owner,以助于删除软件包时判断它们是否要从 debconf 数据库中删除。


B.3. 创建预置文件

预置文件是 debconf-set-selections 命令使用的格式。通常预置文件中每一行的格式为:
<owner> <question name> <question type> <value>


编写预置文件的时候要留意几条规则。


在类型和值之间只有一个空格或者 tab:任何额外的空格将被解释为值的一部分。


一行可以通过行尾的反斜杠(“\”)连接符分成多行。分割一行比较妥当的地方是在问题后面;在类型和值之间分割则是糟糕做法。被分割的行连接时会把行首和行尾的空格缩减为一个空格,再组成单独一行。


对于安装程序自己使用的 debconf 变量(模板),owner 应该设置为 “d-i”;要在安装后的系统里面预置变量,应该使用名称中包含对应 debconf 模板的软件包。只有那些 owner 为非 “d-i” 的变量将被保存到安装后系统的 debconf 数据库里面。


大多数问题需要使用有效的英文预置值,而不是翻译过的值。但有些问题(例如 partman),需要使用翻译过的值。


有些问题在安装过程中显示值的代码而不是英文文本。

建立预置文件最简单的方法是使用例子文件作为工作的基础,它位于 第 B.4 节 “预置文件的内容(squeeze)”。

另一种方法是手动安装,重启后,使用 debconf-utils 软件包里面的 debconf-get-selections 导出 debconf 数据库和安装程序的 cdebconf 数据库到一个文件:
$ debconf-get-selections --installer > file
$ debconf-get-selections >> file


但用此方法产生的文件,有些项无法预置。对于大多数用户,示例文件是一个较佳的开始。
注意

这种方法在安装的最后,安装程序的 cdebconf 数据库被保存到新安装系统的 /var/log/installer/cdebconf 文件。由于数据库里面常还有敏感的信息,默认只为 root 可读。

如果您清除 installation-report 软件包,/var/log/installer 目录及其中的文件将从您的系统中删除。

为了检测问题答案可用的值,您可以在安装进行中使用 nano 检查 /var/lib/cdebconf 下的文件。templates.dat 是原始的模板,questions.dat 是当前变量设置的值。

为了在安装之前测试您的预置文件是否有效,您可以使用 debconf-set-selections -c preseed.cfg 命令



B.4. 预置文件的内容(squeeze)

本附录使用的配置片段还放在预置例子文件 http://www.debian.org/releases/squeeze/example-preseed.txt 里面。

请注意,这里的例子是基于 Intel x86 架构的安装过程。如果您安装到其他架构,其中的一些例子(像键盘选择和 bootloader 安装)可能不恰当,需要用适合您架构的 debconf 设置替换。

有关不同 Debian 安装程序模块的工作细节,请参阅 第 6.3 节 “使用单独的组件”。
B.4.1. 本地化

设置本地信息只适用于使用 initrd 预置。其他方式下这些问题是在询问之后加载的。

locale 用于指定语言和国家或者任何 debian-installer 支持的语言与地区的组合。如果组合起来的不是有效的 locale,安装程序会自动选择一个指定语言可用的 locale。要在引导参数上指定本地,比如使用 locale=en_US。

虽然这个方法很容易使用,但它无法预置所有的语言、国家和地方组合[20]。 因此另一种方法是单独预置各值。语言和国家可以在引导参数里面指定。
# Preseeding only locale sets language, country and locale.
d-i debian-installer/locale string en_US

# The values can also be preseeded individually for greater flexibility.
#d-i debian-installer/language string en
#d-i debian-installer/country string NL
#d-i debian-installer/locale string en_GB.UTF-8
# Optionally specify additional locales to be generated.
#d-i localechooser/supported-locales en_US.UTF-8, nl_NL.UTF-8


键盘设置由键盘体系和 keymap 组成。大多数情况下,默认可以选择正确的键盘体系,因此通常不必预置。keymap 必须对 debian-installer 所选择的键盘体系有效。
# Keyboard selection.
#d-i console-tools/archs select at
d-i console-keymaps-at/keymap select us
d-i keyboard-configuration/xkb-keymap select us
# Example for a different keyboard architecture
#d-i console-keymaps-usb/keymap select mac-usb-us


使用 skip-config 可以跳过键盘预置 console-tools/archs。这将导致内核 keymap 保持活动。
注意

2.6 内核的输入层的变更实际上让键盘体系已经作废。对于 2.6 内核,通常应该选择 “PC” (at) keymap。
B.4.2. 网络设置

显而易见,预置网络设置对于从网络加载预置文件无效。但对从 CD 和 U 盘引导很有帮助。如果您计划从网络加载预置文件,应该使用传递网络设置给内核引导参数的方式。

如果您需要网络引导从网络加载预置文件前指定网卡,请用这种引导参数 interface=eth1。

虽然使用网络预置(用 “preseed/url”)通常并不能配置网络,但是您可以使用下面的技巧实现。例如,为网卡设置静态地址。它使加载了预置文件以后网络预置再运行一次,这需要将下面的命令包含在 “preseed/run” 脚本里面:
killall.sh; netcfg


下面的 debconf 变量与网络配置相关。
# Disable network configuration entirely. This is useful for cdrom
# installations on non-networked devices where the network questions,
# warning and long timeouts are a nuisance.
#d-i netcfg/enable boolean false

# netcfg will choose an interface that has link if possible. This makes it
# skip displaying a list if there is more than one interface.
d-i netcfg/choose_interface select auto

# To pick a particular interface instead:
#d-i netcfg/choose_interface select eth1

# If you have a slow dhcp server and the installer times out waiting for
# it, this might be useful.
#d-i netcfg/dhcp_timeout string 60

# If you prefer to configure the network manually, uncomment this line and
# the static network configuration below.
#d-i netcfg/disable_dhcp boolean true

# If you want the preconfiguration file to work on systems both with and
# without a dhcp server, uncomment these lines and the static network
# configuration below.
#d-i netcfg/dhcp_failed note
#d-i netcfg/dhcp_options select Configure network manually

# Static network configuration.
#d-i netcfg/get_nameservers string 192.168.1.1
#d-i netcfg/get_ipaddress string 192.168.1.42
#d-i netcfg/get_netmask string 255.255.255.0
#d-i netcfg/get_gateway string 192.168.1.1
#d-i netcfg/confirm_static boolean true

# Any hostname and domain names assigned from dhcp take precedence over
# values set here. However, setting the values still prevents the questions
# from being shown, even if values come from dhcp.
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

# Disable that annoying WEP key dialog.
d-i netcfg/wireless_wep string
# The wacky dhcp hostname that some ISPs use as a password of sorts.
#d-i netcfg/dhcp_hostname string radish

# If non-free firmware is needed for the network or other hardware, you can
# configure the installer to always try to load it, without prompting. Or
# change to false to disable asking.
#d-i hw-detect/load_firmware boolean true

请注意,如果 netcfg/get_netmask 没有预置,netcfg 将自动侦测掩码。这种情况下,为了自动安装,变量需要标记为 seen 。同样,如果 netcfg/get_gateway 没有设置,netcfg 将自动选择一个合适的地址。特殊情况下,您可以设置 netcfg/get_gateway 为 “none” 确定不使用网关。
B.4.3. 网络控制台
# Use the following settings if you wish to make use of the network-console
# component for remote installation over SSH. This only makes sense if you
# intend to perform the remainder of the installation manually.
#d-i anna/choose_modules string network-console
#d-i network-console/password password r00tme
#d-i network-console/password-again password r00tme
B.4.4. 镜像设置

根据您使用的安装方式,镜像可用于下载安装程序的额外组件、安装基本系统以及为所安装的系统建立 /etc/apt/sources.list。

参数 mirror/suite 决定了安装好的系统使用的套件。

参数 mirror/udeb/suite 决定安装程序使用的额外组件的套件。它只在组件通过网络下载并与安装时使用的 initrd 建立套件相匹配时才有效。通常安装程序会自动安装并使用正确的值而毋需手动设置。
# If you select ftp, the mirror/country string does not need to be set.
#d-i mirror/protocol string ftp
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# Suite to install.
#d-i mirror/suite string testing
# Suite to use for loading installer components (optional).
#d-i mirror/udeb/suite string testing
B.4.5. 帐号设置

root 帐号的密码和第一个普通用户的名字和密码都可以预置。您可以给密码使用纯文本或 MD5 哈希 值。
警告

要知道预置密码并不安全,每个可以访问预置文件的用户都可以看到这些密码。使用 MD5 哈希值相对安全一些,但也会造成安全的假象,MD5 哈希值也可以被暴力破解。
# Skip creation of a root account (normal user account will be able to
# use sudo).
#d-i passwd/root-login boolean false
# Alternatively, to skip creation of a normal user account.
#d-i passwd/make-user boolean false

# Root password, either in clear text
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
# or encrypted using an MD5 hash.
#d-i passwd/root-password-crypted password [MD5 hash]

# To create a normal user account.
#d-i passwd/user-fullname string Debian User
#d-i passwd/username string debian
# Normal user's password, either in clear text
#d-i passwd/user-password password insecure
#d-i passwd/user-password-again password insecure
# or encrypted using an MD5 hash.
#d-i passwd/user-password-crypted password [MD5 hash]
# Create the first user with the specified UID instead of the default.
#d-i passwd/user-uid string 1010

# The user account will be added to some standard initial groups. To
# override that, use this.
#d-i passwd/user-default-groups string audio cdrom video

passwd/root-password-crypted 和 passwd/user-password-crypted 值可以使用 “!” 作为他们的预置值。这种情况下,对应的帐号关闭。它常用于 root 帐号,用其他替代方法允许管理或 root 登录(例如使用 SSH key 认证或 sudo)。

下面的命令可用于生成密码的 MD5 值。
$ printf "r00tme" | mkpasswd -s -m md5

B.4.6. 时钟与时区设置
# Controls whether or not the hardware clock is set to UTC.
d-i clock-setup/utc boolean true

# You may set this to any valid setting for $TZ; see the contents of
# /usr/share/zoneinfo/ for valid values.
d-i time/zone string US/Eastern

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true
# NTP server to use. The default is almost always fine here.
#d-i clock-setup/ntp-server string ntp.example.com
B.4.7. 分区

使用预置进行硬盘分区受限于 partman-auto 提供的支持。您可以选择使用磁盘上已有的空闲分区或者整个磁盘。磁盘的布局将取决于所使用的预定义方案,用户自定义的方案文件或预置文件包含的方案。

已经支持包括 RAID、LVM 和加密高级分区设置的预置,但对于非预置安装的分区仍然弹性不足。

下面的例子仅提供了使用方案的最基本信息。详细的内容清参考文件 partman-auto-recipe.txt 和 partman-auto-raid-recipe.txt,它们包含在 debian-installer 软件包内。这两个文件也可以从 debian-installer source repository 获取。注意不同发布版支持的功能会有所改变。
警告

磁盘的标识基于对应驱动加载的次序。如果系统里面有多个磁盘,要确定预置使用了正确的那一个。
B.4.7.1. 分区示例
# If the system has free space you can choose to only partition that space.
# This is only honoured if partman-auto/method (below) is not set.
#d-i partman-auto/init_automatically_partition select biggest_free

# Alternatively, you may specify a disk to partition. If the system has only
# one disk the installer will default to using that, but otherwise the device
# name must be given in traditional, non-devfs format (so e.g. /dev/hda or
# /dev/sda, and not e.g. /dev/discs/disc0/disc).
# For example, to use the first SCSI/SATA hard disk:
#d-i partman-auto/disk string /dev/sda
# In addition, you'll need to specify the method to use.
# The presently available methods are:
# - regular: use the usual partition types for your architecture
# - lvm: use LVM to partition the disk
# - crypto: use LVM within an encrypted partition
d-i partman-auto/method string lvm

# If one of the disks that are going to be automatically partitioned
# contains an old LVM configuration, the user will normally receive a
# warning. This can be preseeded away...
d-i partman-lvm/device_remove_lvm boolean true
# The same applies to pre-existing software RAID array:
d-i partman-md/device_remove_md boolean true
# And the same goes for the confirmation to write the lvm partitions.
d-i partman-lvm/confirm boolean true

# You can choose one of the three predefined partitioning recipes:
# - atomic: all files in one partition
# - home: separate /home partition
# - multi: separate /home, /usr, /var, and /tmp partitions
d-i partman-auto/choose_recipe select atomic

# Or provide a recipe of your own...
# If you have a way to get a recipe file into the d-i environment, you can
# just point at it.
#d-i partman-auto/expert_recipe_file string /hd-media/recipe

# If not, you can put an entire recipe into the preconfiguration file in one
# (logical) line. This example creates a small /boot partition, suitable
# swap, and uses the rest of the space for the root partition:
#d-i partman-auto/expert_recipe string \
# boot-root :: \
# 40 50 100 ext3 \
# $primary{ } $bootable{ } \
# method{ format } format{ } \
# use_filesystem{ } filesystem{ ext3 } \
# mountpoint{ /boot } \
# . \
# 500 10000 1000000000 ext3 \
# method{ format } format{ } \
# use_filesystem{ } filesystem{ ext3 } \
# mountpoint{ / } \
# . \
# 64 512 300% linux-swap \
# method{ swap } format{ } \
# .

# The full recipe format is documented in the file partman-auto-recipe.txt
# included in the 'debian-installer' package or available from D-I source
# repository. This also documents how to specify settings such as file
# system labels, volume group names and which physical devices to include
# in a volume group.

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
B.4.7.2. 使用 RAID 分区

您可以使用预置来建立软 RAID 阵列。支持 RAID 等级 0、1、5、6 和 10,建立降级阵列(degraded arrays)和指定额外设备。
警告

这种自动分区方式很容易出错。debian-installer 开发人员对它的功能只进行了相对较少的测试。让各种方案都正确(有意义而不冲突)的责任在于用户。如果您遇到问题,检查一下 /var/log/syslog。
# The method should be set to "raid".
#d-i partman-auto/method string raid
# Specify the disks to be partitioned. They will all get the same layout,
# so this will only work if the disks are the same size.
#d-i partman-auto/disk string /dev/sda /dev/sdb

# Next you need to specify the physical partitions that will be used.
#d-i partman-auto/expert_recipe string \
# multiraid :: \
# 1000 5000 4000 raid \
# $primary{ } method{ raid } \
# . \
# 64 512 300% raid \
# method{ raid } \
# . \
# 500 10000 1000000000 raid \
# method{ raid } \
# .

# Last you need to specify how the previously defined partitions will be
# used in the RAID setup. Remember to use the correct partition numbers
# for logical partitions. RAID levels 0, 1, 5, 6 and 10 are supported;
# devices are separated using "#".
# Parameters are:
# <raidtype> <devcount> <sparecount> <fstype> <mountpoint> \
# <devices> <sparedevices>

#d-i partman-auto-raid/recipe string \
# 1 2 0 ext3 / \
# /dev/sda1#/dev/sdb1 \
# . \
# 1 2 0 swap - \
# /dev/sda5#/dev/sdb5 \
# . \
# 0 2 0 ext3 /home \
# /dev/sda6#/dev/sdb6 \
# .

# For additional information see the file partman-auto-raid-recipe.txt
# included in the 'debian-installer' package or available from D-I source
# repository.

# This makes partman automatically partition without confirmation.
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
B.4.7.3. 分区挂载控制

文件系统一般使用 UUID 作为关键字挂载; 这使得在设备名变更的情况下仍然可以正常挂载。UUID 本身很长不容易阅读,因此,安装程序也可以依照您的意愿使用传统设备名或者指定标签(label)挂载文件系统。假如安装程序使用标签方式,那些没有标签的文件系统仍然使用 UUID 方式挂载。

具有固定名称的设备,比如 LVM 逻辑卷,将继续使用它们自己的名字而不是 UUID 方式挂载。
警告

传统设备名会根据内核在引导时发现的次序进行调整,这将导致挂载错误的文件系统。与此类似,假如您插入一个新磁盘或 USB 设备,标签也可能有冲突发生。这样系统启动后会出现一些随机的情况。
# The default is to mount by UUID, but you can also choose "traditional" to
# use traditional device names, or "label" to try filesystem labels before
# falling back to UUIDs.
#d-i partman/mount_style select uuid
B.4.8. 基本系统安装

本阶段的安装并没有多少东西需要预置。仅有一个与内核安装相关的问题。
# Configure APT to not install recommended packages by default. Use of this
# option can result in an incomplete system and should only be used by very
# experienced users.
#d-i base-installer/install-recommends boolean false

# Select the initramfs generator used to generate the initrd for 2.6 kernels.
#d-i base-installer/kernel/linux/initramfs-generators string initramfs-tools

# The kernel image (meta) package to be installed; "none" can be used if no
# kernel is to be installed.
#d-i base-installer/kernel/image string linux-image-2.6-486
B.4.9. 设置 apt

设置 /etc/apt/sources.list 和其他的基本配置选项,将自动地基于您使用的安装方式以及前面问题的回答。您也可以选择性地安装其他(或本地)的仓库。
# You can choose to install non-free and contrib software.
#d-i apt-setup/non-free boolean true
#d-i apt-setup/contrib boolean true
# Uncomment this if you don't want to use a network mirror.
#d-i apt-setup/use_mirror boolean false
# Select which update services to use; define the mirrors to be used.
# Values shown below are the normal defaults.
#d-i apt-setup/services-select multiselect security, volatile
#d-i apt-setup/security_host string security.debian.org
#d-i apt-setup/volatile_host string volatile.debian.org

# Additional repositories, local[0-9] available
#d-i apt-setup/local0/repository string \
# http://local.server/debian stable main
#d-i apt-setup/local0/comment string local server
# Enable deb-src lines
#d-i apt-setup/local0/source boolean true
# URL to the public key of the local repository; you must provide a key or
# apt will complain about the unauthenticated repository and so the
# sources.list line will be left commented out
#d-i apt-setup/local0/key string http://local.server/key

# By default the installer requires that repositories be authenticated
# using a known gpg key. This setting can be used to disable that
# authentication. Warning: Insecure, not recommended.
#d-i debian-installer/allow_unauthenticated boolean true
B.4.10. 选择软件包

您可以选择安装存在的任务的组合。本文编撰时已有的任务包括:


standard


desktop


gnome-desktop


kde-desktop


web-server


print-server


dns-server


file-server


mail-server


sql-database


laptop

您可以不选任务,并用其他方法安装一系列软件包。我们推荐选上 standard 任务。

如果您打算安装一些安装任务之外的独立软件包,可以使用参数 pkgsel/include。该参数的值可以是用逗号或空格分开的软件包列表,便于在内核命令行上使用。
#tasksel tasksel/first multiselect standard, web-server
# If the desktop task is selected, install the kde and xfce desktops
# instead of the default gnome desktop.
#tasksel tasksel/desktop multiselect kde, xfce

# Individual additional packages to install
#d-i pkgsel/include string openssh-server build-essential
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
#d-i pkgsel/upgrade select none

# Some versions of the installer can report back on what software you have
# installed, and what software you use. The default is not to report back,
# but sending reports helps the project determine what software is most
# popular and include it on CDs.
#popularity-contest popularity-contest/participate boolean false
B.4.11. 完成安装
# During installations from serial console, the regular virtual consoles
# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
# line to prevent this.
#d-i finish-install/keep-consoles boolean true

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

# This will prevent the installer from ejecting the CD during the reboot,
# which is useful in some situations.
#d-i cdrom-detect/eject boolean false

# This is how to make the installer shutdown when finished, but not
# reboot into the installed system.
#d-i debian-installer/exit/halt boolean true
# This will power off the machine instead of just halting it.
#d-i debian-installer/exit/poweroff boolean true
B.4.12. 预置其他的软件包
# Depending on what software you choose to install, or if things go wrong
# during the installation process, it's possible that other questions may
# be asked. You can preseed those too, of course. To get a list of every
# possible question that could be asked during an install, do an
# installation, and then run these commands:
# debconf-get-selections --installer
> file
# debconf-get-selections
>
> file


[20] 比如预置 locale 为 en_NL 在安装后的系统中默认的 locale 将是 en_US.UTF-8。如果想使用 en_GB.UTF-8,该值应该分别进行预置。



B.5. 高级选项
B.5.1. 安装过程中运行用户命令

预置工具提供了一个非常强大和灵活的选项,可以在安装过程的一些环节运行命令或脚本。
# 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
B.5.2. 使用预置修改默认值

也可以使用预置修改问题的默认答案,但同时显示问题。这需要在问题设定值之后,必须将 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)。当然,这只会影响在安装时显示出来的问题对应的参数,而不是“内部的”参数。
B.5.3. 预置文件链

可以在一个预置文件里面包含另外的预置文件。这些文件里面的任何设置将覆盖前面加载的设置。有一种用法,例如,通用的网络设置放在一个文件,其他规格的设置放在另外的文件里面。
# 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 命令,第二个可以在网络连通后使用。