在开始自定义前,需确保Cobbler服务端已正确安装并配置。核心命令如下:
sudo apt-get update
sudo apt-get install cobbler cobbler-web dhcp3-server tftpd-hpa xinetd
安装完成后,启动Cobbler服务并设置开机自启:
sudo systemctl start cobbler
sudo systemctl enable cobbler
通过cobbler check命令检查配置问题(如未解决需按提示修复)。
Cobbler为Ubuntu提供了默认的Kickstart模板(通常位于/var/lib/cobbler/kickstarts/目录下),以default.seed或ubuntu.seed命名。可直接复制该模板进行修改:
sudo cp /var/lib/cobbler/kickstarts/default.seed /var/lib/cobbler/kickstarts/custom-ubuntu.ks
或从Ubuntu ISO中提取模板(挂载ISO后,路径通常为/pool/main/ubuntu-installer/amd64/)。
使用文本编辑器(如vim)打开模板文件,根据需求修改以下关键参数:
zh_CN.UTF-8)和键盘布局(如us)。lang zh_CN.UTF-8
keyboard us
Asia/Shanghai)。timezone Asia/Shanghai
mkpasswd加密,如$1$abc123$xyz456)。rootpw --iscrypted $1$abc123$xyz456
autopart快速创建默认分区(适用于大多数场景)。autopart
/boot、swap、/)。part /boot --fstype=ext4 --size=500
part swap --size=2048
part / --fstype=ext4 --grow --size=1
@base组安装核心组件,或单独指定软件包(如vim、openssh-server)。%packages
@base
vim
openssh-server
wget
%end
bootproto=static并提供IP、网关、DNS等信息。network --bootproto=static --ip=192.168.1.100 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=8.8.8.8 --hostname=my-ubuntu
bootproto=dhcp。network --bootproto=dhcp
bootloader --location=mbr
--location=esp并指定ESP分区(如--boot-drive=sda1)。bootloader --location=esp --boot-drive=sda1
更多参数可参考Cobbler官方文档或Kickstart手册。
使用cobbler profile edit命令将自定义Kickstart文件关联到Cobbler配置文件(Profile):
sudo cobbler profile edit --name=my-ubuntu-profile --kickstart=/var/lib/cobbler/kickstarts/custom-ubuntu.ks
其中,my-ubuntu-profile是自定义的Profile名称,/var/lib/cobbler/kickstarts/custom-ubuntu.ks是Kickstart文件的路径。
修改完成后,必须同步Cobbler配置以使更改生效:
sudo cobbler sync
该命令会将Kickstart文件上传至TFTP服务器,并更新PXE启动菜单。
可通过以下方式验证Kickstart文件的有效性:
cobbler validateks命令检查文件语法。sudo cobbler validateks /var/lib/cobbler/kickstarts/custom-ubuntu.ks
my-ubuntu-profile),观察是否按自定义配置自动安装。mkpasswd加密(如mkpasswd -m sha-512),避免明文存储。http://cobbler-server/cblr/svc/op/ks/profile/my-ubuntu-profile)。通过以上步骤,即可完成Ubuntu Cobbler Kickstart文件的自定义,实现自动化部署的个性化需求。