什么是 Preseed?
Preseed 是 Debian 及其衍生发行版(如 Ubuntu)提供的一种自动化安装机制。 通过预定义配置文件(即 preseed 文件),可以在系统安装过程中自动回答所有安装问题, 实现无人值守安装,极大提高批量部署效率。
基本使用步骤
- 编写或获取一个
preseed.cfg配置文件。 - 将该文件放在可访问的位置(如 HTTP 服务器、U 盘、ISO 镜像中)。
- 在启动安装程序时,通过内核参数指定 preseed 文件路径。
示例 Preseed 配置片段
# 设置语言 d-i debian-installer/language string zh d-i debian-installer/country string CN d-i debian-installer/locale string zh_CN.UTF-8 # 键盘布局 d-i keyboard-configuration/xkb-keymap select us # 网络配置(DHCP) d-i netcfg/choose_interface select auto # 分区方案(警告:会清除整个磁盘!) d-i partman-auto/method string regular d-i partman-auto/choose_recipe select atomic 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 # 设置 root 密码(建议使用加密后的密码) d-i passwd/root-password password yourpassword d-i passwd/root-password-again password yourpassword # 安装完成后自动重启 d-i finish-install/reboot_in_progress note
启动时加载 Preseed 文件
在 GRUB 启动菜单中,按 e 编辑启动项,在 linux 行末尾添加:
auto url=http://your-server/preseed.cfg
或者从本地介质加载:
file=/cdrom/preseed.cfg
注意事项
- 不同版本的 Debian/Ubuntu 对 preseed 语法支持略有差异,请参考对应版本官方文档。
- 敏感信息(如密码)建议使用加密形式,避免明文存储。
- 测试 preseed 脚本前,务必在非生产环境中验证。