一、基础环境搭建
1. 原始ISO获取
OS版本:银河麒麟高级服务器操作系统V10SP1(X86_64)
百度网盘:https://pan.baidu.com/s/1xAdxWht0wMB-ebQVbjehbQ 提取码:cns2
2. 系统安装
这里我们选择银河麒麟服务器系统常用的“带UKUI GUI的服务器”以及“自动分区”方案。
二、ISO镜像定制
1. 准备工作
(1)创建“ISO镜像制作目录”;
[root@localhost ~]# mkdir /root/kylin-iso
(2)将原始ISO镜像挂载到系统(插入光盘后系统会自动挂载);
(3)将ISO挂载目录下的所有文件拷贝到“ISO镜像制作目录”;
[root@localhost ~]# rsync -a /run/media/root/Kylin-Server-10/ /root/kylin-iso/
(4)获取当前系统中安装的所有rpm包列表;
[root@localhost ~]# rpm -qa > /root/package-list.txt
2. 修改ISO镜像
(1)为使后面我们生成的ISO文件尽可能的小,我们只保留系统安装所需要的RPM包以及其它需要定制的RPM包;
A. 首先,删除ISO制作目录/root/kylin-iso/Packages/下所有的RPM包;
[root@localhost ~]# cd /root/kylin-iso/Packages/
[root@localhost Packages]# rm -rf *.rpm
B. 接着,从ISO挂载目录/run/media/root/Kylin-Server-10/Packages/拷贝系统安装所需的RPM包拷贝到“ISO镜像制作目录”/root/kylin-iso/Packages/中;
[root@localhost Packages]# cat /root/package-list.txt | awk ‘{print $0}’ |xargs -i cp /run/media/root/Kylin-Server-10/Packages/{}.rpm /root/kylin-iso/Packages/
C. 修改系统/etc/yum.conf配置文件,开启安装软件保留缓存设置;
[root@localhost ~]# vim /etc/yum.conf
修改前:
修改后:
D. 使用yum将系统自带的OpenSSH等软件更新到最新版本;
[root@localhost ~]# yum install openssh audit mate-indicators
E. 将yum缓存目录/var/cache/yum/下的RPM缓存包拷贝到“ISO镜像制作目录”的Packages文件夹中;
[root@localhost ~]# cd /var/cache/yum/ks10-adv-updates-b74b513216569387/packages/
[root@localhost packages]# cp -a *.rpm /root/kylin-iso/Packages/
F. 更新“ISO镜像制作目录”的repodata文件夹下的xxx-comps.xml文件;
[root@localhost ~]# cd /root/kylin-iso/
[root@localhost kylin-iso]# createrepo -g repodata/8cdeadbf13f3898044bd53454eab119481c7fcb672eae31327419bcf1516d54d-Kylin-x86_64-V10-ukui-comps.xml .
(2)配置KickStart自动化安装;
A. 系统安装完成后,默认会在/root/目录下生成anaconda-ks.cfg文件,该文件记录了系统安装过程中的配置。我们将其复制到“ISO镜像制作目录”的isolinux文件夹中,并改名为ks.cfg;
[root@localhost ~]# cp /root/anaconda-ks.cfg /root/kylin-iso/isolinux/ks.cfg
B. 编辑ks.cfg自动化安装脚本文件,修改以下几个配置:
①修改SSH端口号为6022,并设置“允许root账户使用SSH远程登录”
②系统安装前自动清除原有的分区信息
③系统安装完成后自动重启
④安装升级openssh,audit和mate-indicators
#version=DEVEL
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use graphical install
graphical
# Use CDROM installation media
cdrom
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --bootproto=dhcp --device=ens37 --onboot=off --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted \(6</span><span class="token variable">\)qZquFjZf5nbW3GyN$G/x3FR11KkE0eSPeYFOmYx8mhYcvkssy1vKOPF4rVLB7Estu5L/Fi62SIgtxW0VHeksm5WzcJI2Q30OX3Hr1a0
# X Window System configuration information
xconfig --startxonboot
# Run the Setup Agent on first boot
firstboot --enable
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
%post --nochroot
#####copy kyinfo and LICENSE
if [ -e /tmp/.kyinfo ];then
echo y | cp -a /tmp/.kyinfo \(ANA_INSTALL_PATH</span>/etc/
<span class="token keyword">fi</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> -e /tmp/LICENSE <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
<span class="token builtin class-name">echo</span> y <span class="token operator">|</span> <span class="token function">cp</span> -a /tmp/LICENSE <span class="token variable">\)ANA_INSTALL_PATH/etc/
fi
if [ -e /run/install/repo/.kyinfo ];then
echo y | cp -a /run/install/repo/.kyinfo \(ANA_INSTALL_PATH</span>/etc/
<span class="token keyword">fi</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> -e /run/install/repo/LICENSE <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
<span class="token builtin class-name">echo</span> y <span class="token operator">|</span> <span class="token function">cp</span> -a /run/install/repo/LICENSE <span class="token variable">\)ANA_INSTALL_PATH/etc/
fi
##### kylin postaction
## cdrom install, copy .kylin-post-actions
if [ -e /run/install/repo/.kylin-post-actions ];then
echo y | cp -a /run/install/repo/.kylin-post-actions /tmp/.kylin-post-actions
echo "repo=/run/install/repo" > /tmp/.kylin-repo
fi
## copy kylin post scripts in new os
if [ -e /tmp/.kylin-post-actions ];then
echo y | cp -a /tmp/.kylin-post-actions \(ANA_INSTALL_PATH</span>/bin
<span class="token keyword">fi</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> -e /tmp/.kylin-repo <span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token keyword">then</span>
<span class="token builtin class-name">echo</span> y <span class="token operator">|</span> <span class="token function">cp</span> -a /tmp/.kylin-repo <span class="token variable">\)ANA_INSTALL_PATH/tmp/
fi
## copy and run .kylin-post-actions-nochroot
if [ -e /run/install/repo/.kylin-post-actions-nochroot ];then
echo y | cp -a /run/install/repo/.kylin-post-actions-nochroot /tmp/.kylin-post-actions-nochroot
fi
if [ -e /tmp/.kylin-post-actions-nochroot ];then
/bin/bash -x /tmp/.kylin-post-actions-nochroot &> $ANA_INSTALL_PATH/var/log/.kylin-post-actions-nochroot.log
fi
%end
%post
/bin/sed -i '13a Port 6022' /etc/ssh/sshd_config; </span></span>
/bin/sed -i '/PermitRootLogin /d' /etc/ssh/sshd_config; </span></span>
/bin/sed -i '32a PermitRootLogin yes' /etc/ssh/sshd_config; </span></span>
systemctl disable systemd-networkd-wait-online.service
systemctl disable multipathd.service
### do kylin post action
if [ -e /bin/.kylin-post-actions ];then
/bin/bash -x /bin/.kylin-post-actions &> /var/log/.kylin-post-actions.log
fi
%end
%packages
@^kylin-desktop-environment
kexec-tools
openssh
audit
mate-indicators
%end
%addon com_redhat_kdump --enable --reserve-mb='1024M'
%end
%anaconda
pwpolicy root --minlen=8 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=8 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=8 --minquality=1 --notstrict --nochanges --notempty
%end
reboot
(3)修改启动文件isolinux.cfg;
[root@localhost ~]# vim /root/kylin-iso/isolinux/isolinux.cfg
注意:这里“LABEL=“后面的参数值”Kylin-Server-10“要和后续制作的U盘启动盘卷标名称或者刻录的光盘名称一致。
修改前:
修改后:
3. 生成ISO镜像;
[root@localhost ~]# cd /root/kylin-iso/
[root@localhost kylin-iso]# mkisofs -o kylin10.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T -joliet-long -V Kylin-Server-10 /root/kylin-iso/
[root@localhost kylin-iso]# ls -lh kylin10.iso
三、ISO镜像验证
注:验证环境为VMware虚拟机环境。
(1)修改“CD/DVD(IDE)”为“使用ISO映像文件”,如下图:
(2)直接从“CD/DVD(IDE)”启动虚拟机,系统会自动开始安装,如下图:
(3)系统安装完成;
(4)进系统验证上述步骤中的定制选项配置是否生效。
A. SSH端口正常;
B. OpenSSH软件包版本正常;