下面我分概念 → 示例 → 实战模板三部分,讲清楚怎样写一个 Debian 的 Cobbler 自动化安装脚本(kickstart / preseed),以及 Cobbler 中如何使用。
kickstart(.cfg).seed)Cobbler 对两者都支持,但 Debian 必须用 preseed。
Cobbler 中的关键文件:
/var/lib/cobbler/kickstarts/
cobbler import \
--path=/mnt/debian11 \
--name=debian11 \
--arch=amd64
cobbler profile edit \
--name=debian11-x86_64 \
--kickstart=/var/lib/cobbler/kickstarts/debian11.seed
# debian11.seed
### 语言和地区
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
### 网络
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string debian-node
d-i netcfg/get_domain string local
### 镜像源
d-i mirror/country string manual
d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
### 账号
d-i passwd/root-password password rootpw
d-i passwd/root-password-again password rootpw
d-i user-setup/allow-password-weak boolean true
d-i passwd/make-user boolean false
### 分区
d-i partman-auto/method string lvm
d-i partman-auto/disk string /dev/sda
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
### 软件包
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server vim wget curl
### 安装 GRUB
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/sda
### 安装完成
d-i finish-install/reboot_in_progress note
Cobbler 支持在 preseed 中使用变量:
d-i netcfg/get_hostname string $hostname
d-i netcfg/get_domain string $domain
常见变量:
| 变量 | 含义 |
|---|---|
$hostname |
主机名 |
$ip_address |
IP |
$domain |
域名 |
$mac_address |
MAC |
示例:
cobbler system add \
--name=node01 \
--profile=debian11-x86_64 \
--hostname=node01.local \
--ip-address=192.168.1.10 \
--mac=52:54:00:11:22:33
d-i preseed/late_command string \
in-target sh -c 'echo "Hello Cobbler" > /root/cobbler.txt'; \
in-target apt-get update
$dollar=$
#include snip/debian_post
/var/lib/cobbler/snippets/debian_post:
#!/bin/sh
echo "Configured by Cobbler" > /etc/motd
cobbler profile getks --name=debian11-x86_64
priority=low
可一步步看 preseed 是否生效
❌ Debian 不能用 kickstart
❌ preseed 里注释必须用 #
❌ 分区一定要 confirm=true
❌ hostname 不设置会卡住
❌ Cobbler 变量要用 $ 不是 {{ }}
你可以直接告诉我:
我可以 直接写一份可复制的 Cobbler + preseed 完整模板。