导读搭建好 Cobbler 服务端后,使用默认的 kickstarts 引导文件对客户端安装系统,且默认安装的是最小化的系统。我们可以自定义 kickstarts 引导文件进而实现对客户端的自定义安装系统。
环境:
VMware Workstation Pro 14
定制系统安装的软件包
查看默认的 ks 文件
[root@Jaking ~]# cobbler report
distros:
==========
Name : CentOS-7.6-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.6-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <>
Red Hat Management Server : <>
Template Files : {}
profiles:
==========
Name : CentOS-7.6-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7.6-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
注: distros 是发行版本,即光盘镜像信息。 profiles 指的是 ks 应答文件。 systems 是指通 Cobbler 安装好的物理机名称。
[root@Jaking ~]# cd /var/lib/cobbler/kickstarts/
[root@Jaking kickstarts]# ls
default.ks legacy.ks sample_esx4.ks sample.ks
esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed
esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed
install_profiles sample_end.ks sample_esxi6.ks sample.seed.28
可以看到有很多默认的配置文件。
上传 CentOS7.ks 到 Cobbler 服务器上。CentOS7.ks 这个配置文件里面安装了开发工具相关软件包。
[root@Jaking kickstarts]# rz
[root@Jaking kickstarts]# lsCentOS7.ks install_profiles sample_end.ks sample_esxi6.ks sample.seed.28default.ks legacy.ks sample_esx4.ks sample.ksesxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seedesxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed[root@Jaking kickstarts]# cat CentOS7.ks# Cobbler for Kickstart Configurator for CentOS 7 by clsninstallurl --url=$treetextlang en_US.UTF-8keyboard uszerombrbootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"#Network information$SNIPPET('network_config')#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7timezone --utc Asia/Shanghaiauthconfig --enableshadow --passalgo=sha512rootpw --iscrypted $default_password_cryptedclearpart --all --initlabelpart /boot --fstype xfs --size 1024part swap --size 1024part / --fstype xfs --size 1 --growfirstboot --disableselinux --disabledfirewall --disabledlogging --level=inforeboot%pre$SNIPPET('log_ks_pre')$SNIPPET('kickstart_start')$SNIPPET('pre_install_network_config')# Enable installation monitoring$SNIPPET('pre_anamon')%end%packages@additional-devel@development@platform-develbash-completionchronydos2unixkexec-toolslrzszsysstattreevimwgetgitnet-tools%end%postsystemctl disable postfix.service%end[root@Jaking kickstarts]# cobbler profile list #查看当前启动项,使用的配置文件 CentOS-7.6-x86_64
修改 name 是 CentOS-7.6-x86_64 的 kickstart 文件为 CentOS7.ks
[root@Jaking kickstarts]# cobbler profile edit --name CentOS-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7.ks
[root@Jaking kickstarts]# cobbler report | grep Kickstart
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.6-x86_64'}
Kickstart : /var/lib/cobbler/kickstarts/CentOS7.ks
Kickstart Metadata : {}
通过给内核传参数,修改网卡名称为 eth0
[root@Jaking kickstarts]# cobbler profile edit --name CentOS-7.6-x86_64 --kopts='net.ifnames=0 biosdevname=0'
配置文件内容如下:
[root@Jaking kickstarts]# vim CentOS7.ks #查看配置文件中的,默认就可以,不需要修改# Cobbler for Kickstart Configurator for CentOS 7 by clsnInstall #安装系统url --url=$tree #url 地址为 Cobbler 内置变量text #文本方式安装,修改为图形界面则为 Graphicallang en_US.UTF-8 #语言keyboard us #键盘zerombr #该参数用于清除引导信息,需要让其生效可以在参数后添加 yes 即可。可选项,一般不用。bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"#指定引导装载程序怎样被安装.对于安装和升级,这个选项都是必需的.#Network information$SNIPPET('network_config') #该参数表示使用下方%pre 中的脚本来配置网络,相关脚本存放于/var/lib/cobbler/snippets#如果不需要脚本配置可启用以下配置#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6--hostname=CentOS7timezone --utc Asia/Shanghai #时区authconfig --enableshadow --passalgo=sha512 #加密 shadowrootpw --iscrypted $default_password_crypted #设置 root 密码clearpart --all --initlabel #--all 初除所有分区,后者将磁盘标签初始化为缺省值设置。part /boot --fstype xfs --size 1024 #boot分区大小part swap --size 1024 #swap分区大小part / --fstype xfs --size 1 --grow #根分区大小firstboot --disable #决定是否在系统第一次引导时启动"设置代理”,禁用。selinux --disabled #在系统里设置 SELinux 状态firewall --disabled #在系统狸设置而防火墙状态logging --level=info #这个命令控制安装过程中anaconda的错误日志,它对安装好的系统没有影响。reboot #安装后重启%pre #pre 中定了前面使用的具体脚本名称。$SNIPPET('log_ks_pre')$SNIPPET('kickstart_start')$SNIPPET('pre_install_network_config')# Enable installation monitoring$SNIPPET('pre_anamon')%end%packages #自定义安装内容,这里可以可以自行生成 ks 文件然后把对应的配置复制到这里。当前配置为最小化安装,以及安装系统常用工具。@additional-devel@development@platform-develbash-completionchronydos2unixkexec-toolslrzszsysstattreevimwgetgitnet-tools%end%post #安装后执行操作,可以执行脚本也可以直接执行命令。systemctl disable postfix.service%end
定制 Cobbler 引导菜单(名称、超时时间、默认启动菜单)
[root@Jaking kickstarts]# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Jaking #菜单名称
TIMEOUT 100 #超时时间
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items #该变量是我自定义的引导菜单,复制到 LABEL local 配置项上方,否则默认启动还是 local。
MENU end
同步 Cobbler 配置
[root@Jaking kickstarts]# systemctl restart cobblerd[root@Jaking kickstarts]# cobbler synctask started: 2020-01-04_050537_synctask started (id=Sync, time=Sat Jan 4 05:05:37 2020)running pre-sync triggerscleaning treesremoving: /var/www/cobbler/images/CentOS-7.6-x86_64removing: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/imagesremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/images/CentOS-7.6-x86_64removing: /var/lib/tftpboot/s390x/profile_listcopying bootloaderstrying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efitrying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.eficopying distros to tftpbootcopying files for distro: CentOS-7.6-x86_64trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.6-x86_64/initrd.imgcopying imagesgenerating PXE configuration filesgenerating PXE menu structurecopying files for distro: CentOS-7.6-x86_64trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.6-x86_64/initrd.imgWriting template files for CentOS-7.6-x86_64rendering DHCP filesgenerating /etc/dhcp/dhcpd.confrendering TFTPD filesgenerating /etc/xinetd.d/tftpprocessing boot_files for distro: CentOS-7.6-x86_64cleaning link cachesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning: dhcpd -t -qreceived on stdout: received on stderr: running: service dhcpd restartreceived on stdout: received on stderr: Redirecting to /bin/systemctl restart dhcpd.servicerunningshelltriggers from /var/lib/cobbler/triggers/sync/post/*running python triggers from /var/lib/cobbler/triggers/change/*running python trigger cobbler.modules.manage_gendersrunning python trigger cobbler.modules.scm_trackrunning shell triggers from /var/lib/cobbler/triggers/change/**** TASK COMPLETE ***
新建虚拟机进行测试。
注意:内存要足够大,网络模式要和 Cobbler 服务端的网络模式一致。
创建过程省略,直接来到开机启动界面:
可以看到,需要安装 1262 个包,不再是原来的最小化安装了。
安装成功后,默认启动命令行模式
输入 root 123456 登录系统:
设置默认启动模式为图形化模式 graphical.target
[root@localhost ~]# systemctl get-default
multi-user.target
[root@localhost ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@localhost ~]# systemctl get-default
graphical.target
[root@localhost ~]# reboot
不能正常启动图形化模式
解决方法
安装图形化软件
[root@localhost ~]# yum install -y xorg* gnome* glx*
切换到图形化模式
[root@localhost ~]# init 5
本文原创地址:https://www.linuxprobe.com/?p=170731编辑:传棋,审核员:逄增宝
网友评论