debian

Debian Cobbler如何定制镜像

小樊
41
2025-10-03 09:22:37
栏目: 智能运维

1. 准备Debian ISO镜像
下载所需版本的Debian官方ISO文件(如Debian 12 Bookworm),并确保其完整性(可通过校验MD5/SHA256值验证)。

2. 挂载ISO并导入Cobbler

3. 下载并替换Netboot Initrd.gz
Debian DVD中的initrd.gz不支持PXE启动,需下载官方Netboot版本的initrd.gz并与原镜像中的initrd.gz拼接:

wget -O /root/debian12.11-netboot.gz https://mirrors.ustc.edu.cn/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
cat /var/www/cobbler/distro_mirror/debian12.11/install.amd/initrd.gz /root/debian12.11-netboot.gz > /var/www/cobbler/pub/debian12.11-netboot.gz

此步骤是解决PXE启动卡住的关键。

4. 修改Distro配置使用新Initrd
通过Cobbler命令修改Distro的initrd路径,指向拼接后的Netboot文件:

cobbler distro edit --name debian12.11-x86_64 --initrd "/var/www/cobbler/pub/debian12.11-netboot.gz"

确认Distro名称可通过cobbler distro list查看。

5. 编写Preseed Seed文件实现自动化应答
Debian使用Preseed文件进行无人值守安装,需创建定制化的Seed文件(如/var/lib/cobbler/templates/bookworm-workaround.seed),内容示例:

# 基本语言与区域设置
d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string CN
d-i keyboard-configuration/xkb-keymap select us
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 用户及密码配置
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password Passw0rd
d-i passwd/root-password-again password Passw0rd

# 网络配置
d-i netcfg/choose_interface select autodetect
d-i netcfg/get_hostname string debian-server
d-i netcfg/get_domain string example.com

# 镜像源配置(使用国内清华源加速)
d-i mirror/country string manual
d-i mirror/http/hostname string mirrors.tuna.tsinghua.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 软件包选择
tasksel tasksel/first multiselect standard
d-i pkgsel/include string vim,ssh

可根据需求调整语言、用户、镜像源、软件包等参数。

6. 关联Seed文件到Profile
将Seed文件与对应的Cobbler Profile关联,使PXE启动时自动加载:

cobbler profile edit --name debian12.11-x86_64 --kickstart /var/lib/cobbler/templates/bookworm-workaround.seed

确认Profile名称可通过cobbler profile list查看。

7. 添加系统并启用Netboot
若需针对特定MAC地址定制系统(如固定IP、主机名),可添加System配置:

cobbler system add --name debian-web --profile debian12.11-x86_64 --mac 00:11:22:33:44:55 --ip-address 192.168.1.100 --subnet 255.255.255.0 --gateway 192.168.1.1 --hostname debian-web.example.com --interface eth0

启用PXE启动:

cobbler system edit --name debian-web --netboot-enabled true

此步骤可选,若无需固定系统信息,可直接同步配置。

8. 同步配置并验证
将所有修改同步到Cobbler服务器,使配置生效:

cobbler sync

验证配置是否有误:

cobbler check

若输出“No configuration problems found. Everything looks good.”则表示配置成功。

9. 测试PXE启动
将客户端计算机设置为PXE启动(通过网络启动优先),若配置正确,客户端将从Cobbler服务器获取镜像并启动自动化安装流程,按照Seed文件的配置完成Debian系统部署。

0
看了该问题的人还看了