1 | Ps:因为工作内容;有一部份是需要重装系统;系统版本镜像为centos7.9。可每次装完都需要下载一些基础包;最近因为设备过多;网卡名称太乱;导致做后续配置太繁琐;不规整;索性自己定制个系统; |
搭建基础环境
将/root/iso做为定制镜像制作目录; 将/MISO作为挂载镜像的目录 ;安装制作镜像的命令及下载最小化镜像
# mkdir /root/iso # mkdir /MISO # yum install createrepo mkisofs isomd5sum squashfs-tools # wget https://mirrors.163.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso |
挂载镜像;并将/MISO目录下的所有内容copy到镜像制作目录;
1 2 | # mount -o loop,rw CentOS-7-x86_64-Minimal-2009.iso /MISO # cp -a /MISO/* /root/iso/ |
修改/root/iso/isolinux/isolinux.cfg文件,修改如下内
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | default vesamenu.timeout 100 ##安装系统时的默认引导时间; display boot.msg # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png ###安装系统背景图片;更换背景界面;替换为需要的图片,保持文件名不变,图片大小640x480 menu title SinoCache ISO 7.9 ##可以定制欢迎标题 menu vshift 8 menu rows 18 menu margin 8 #menu hidden menu helpmsgrow 15 menu tabmsgrow 13 ……………………………………………… label linux menu label ^Install SinoCache ISO 7.9 ###定制系统标题 menu default ###默认引导选项 kernel vmlinuz append initrd=initrd.img ks=cdrom: /isolinux/ks .cfg inst.stage2=hd:LABEL=CentOS quiet net.ifnames=0 biosdevname=0 ##ks=cdrom:/isolinux/ks.cfg :创建自动化安装配置文件;可以用系统默认生成的anaconda-ks.cfg文件。 ##inst.stage2=hd:LABEL= :为安装介质位置,hd:LABEL为介质标签,例如:CentOS##net.ifnames=0 biosdevname=0 :用于禁用centos7的”一致性网络设备命名法”;###centos6系统网卡命名为ethX形式;centos7系统网卡名各种各样在工作中太无序了;很烦;使用这个参数可以将网卡名改为ethX ###可以将这个标签选项注销。 #label check # menu label Test this ^media & install SinoCache ISO 7.9 # kernel vmlinuz # append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet net.ifnames=0 biosdevname=0 |
编辑isolinux/ks.cfg文件;也可以用/root/anaconda-ks.cfg
# cp -a /root/anaconda-ks.cfg /root/iso/isolinux/ks.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 #使用CD-ROM安装介质 cdrom # 使用图形化安装 graphical # 在第一次启动时运行安装代理 firstboot --enable ignoredisk --only-use=sda # 键盘布局 keyboard --vckeymap=us --xlayouts= 'us' # 设置语言 lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=eth0 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eth1 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eth2 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eth3 --onboot=off --ipv6=auto #network --device=Wan --bondopts=mode=802.3ad,xmit_hash_policy=layer3+4 --bondslaves=eth0,eth3 --onboot=yes # 设置root密码 rootpw --iscrypted $6$sNStQWknxzURmZpv$PEFIX7tG1McnzRsGBUm4UnOyRr4Kg/R8CHcujTbPYMvZRfxVWd8aetfP7gWRHhHobKMay4rGQO6Uxq2CoZ7QF1 # System services services --enabled= "chronyd" # 关闭 SELinux selinux --disabled # 关闭防火墙 firewall --disabled # 系统服务开机自启 services --enabled= "zabbix_agentd,sshd" # 设置时区 timezone Asia/Shanghai --isUtc # 系统引导配置 bootloader --append= "console=tty0 audit=0 selinux=0 net.ifnames=0 biosdevname=0 crashkernel=auto" --location=mbr --boot-drive=sda # 清空主引导分区记录MBR zerombr # 清除分区信息 clearpart --all --initlabel # 硬盘分区信息,以M为单位 part / --fstype= "xfs" --ondisk=sda --size=102400 part /boot --fstype= "xfs" --ondisk=sda --size=300 part swap --fstype= "swap" --ondisk=sda --size=32768 part /data/cache1 --fstype= "xfs" --ondisk=sda --size=92458 %packages @^minimal @core chrony kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb= 'auto' %end %post #配置sshd /bin/sed -i '13a Port 7776' /etc/ssh/sshd_config; \\ /bin/sed -i '/PermitRootLogin /d' /etc/ssh/sshd_config; \\ /bin/sed -i '32a PermitRootLogin yes' /etc/ssh/sshd_config; \\ /bin/sed -i '59a PasswordAuthentication yes' /etc/ssh/sshd_config; \\ /bin/sed -i '/GSSAPIAuthentication /d' /etc/ssh/sshd_config; \\ /bin/sed -i '71a GSSAPIAuthentication no' /etc/ssh/sshd_config; \\ /bin/sed -i '/UsePAM /d' /etc/ssh/sshd_config; \\ /bin/sed -i '82a UsePAM yes' /etc/ssh/sshd_config; \\ /bin/sed -i '/UseDNS /d' /etc/ssh/sshd_config; \\ /bin/sed -i '98a UseDNS no' /etc/ssh/sshd_config; \\ #disable NetworkManager systemctl stop NetworkManager systemctl disable NetworkManager #配置PAM会话检查 cat > /etc/pam.d/sshd << EOF #%PAM-1.0 auth required pam_sepermit.so auth include password-auth account required pam_nologin.so account include password-auth password include password-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session optional pam_keyinit.so force revoke session include password-auth EOF #配置DNS echo 'nameserver 114.114.114.114' > /etc/resolv.conf %end %anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end reboot ##重装完系统自动重启。 |
%pre 和 %post 部分 - 这两个部分的顺序不限,也不是必须的。
%addon、%packages、%pre 和 %post 部分必须以 %end 结尾,否则安装程序会拒绝 Kickstart 文 件。
更改/etc/yum.conf;使用下载缓存;
1 2 3 4 5 6 7 8 9 10 11 12 | [main] cachedir=/ var /cache/yum/ ##将缓存目录做修改;原来目录太深了;· keepcache=1 ##将原来的值0改为1(表示安装后保留软件包;为的是下载一些新系统预安装的软件;如wget等) debuglevel=2 logfile=/ var /log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http: //bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release |
安装一些预安装的软件;或者在修改yum缓存后;直接yum -y update ;升级所有的系统包;在安装系统是均是最新的包;ssh有个坑;是/etc/pam.d/sshd文件认证登录;
1 2 | # yum -y install mtr vim net-tools wget iptables-services tcpdump traceroute zabbix_agentd iptraf-ng bind-utils ipmitool pciutils rsync #上面的软件rpm包(包括依赖包)都会在/var/cache/yum/*/packages/目录下; *代表所使用的yum源仓库名称;根据自己使用yum仓库来决定。 |
需要预安装其他的包,将解决好依赖关系的包全部放入/root/iso/Packages/中,此目录下是系统最初安装的系统包。
1 2 3 4 5 6 7 8 9 | [root@localhost packages]# pwd / var /cache/yum/ali-updates/packages [root@localhost packages]# ll | head -n5 total 359436 -rw-r--r--. 1 root root 1038100 Dec 1 09:13 bash-4.2.46-35.el7_9.x86_64.rpm -rw-r--r--. 1 root root 1146744 Dec 1 09:13 bind-export-libs-9.11.4-26.P2.el7_9.8.x86_64.rpm -rw-r--r--. 1 root root 161096 Dec 1 09:13 bind-libs-9.11.4-26.P2.el7_9.8.x86_64.rpm -rw-r--r--. 1 root root 1179928 Dec 1 09:13 bind-libs-lite-9.11.4-26.P2.el7_9.8.x86_64.rpm [root@localhost packages]# cp -a ./* /root/iso/Package |
更新安装软件包xml文件;将所下载的软件包名称填写进去;在装系统的时候会自动安装好。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # cd /root/iso/repodata # vim *-minimal-x86_64-comps.xml <?xml version= "1.0" encoding= "UTF-8" ?> <!DOCTYPE comps PUBLIC "-//CentOS//DTD Comps info//EN" "comps.dtd" > <comps> <group> <id>core</id> <name>Core</name> <name xml:lang= "af" >Kern</name> ………………………… <name xml:lang= "zh_TW" >核心</name> <name xml:lang= "zu" >Okuyikhona</name> <description>Smallest possible installation.</description> <description xml:lang= "as" >ন্যূনতম ইনস্টল।</description> ………………………… <description xml:lang= "zh_TW" >最小型安裝。</description> < default >false</ default > <uservisible>false</uservisible> <packagelist> <packagereq type = "mandatory" >audit</packagereq> <packagereq type = "mandatory" >basesystem</packagereq> <packagereq type = "mandatory" >bash</packagereq> ……………………………… <packagereq type = "mandatory" >yum</packagereq> <packagereq type = "default" >aic94xx-firmware</packagereq> <packagereq type = "default" >alsa-firmware</packagereq> ……………………………… <packagereq type = "default" >ql23xx-firmware</packagereq> <packagereq type = "default" >rdma</packagereq> <packagereq type = "default" >vim-enhanced</packagereq> <packagereq type = "default" >net-tools</packagereq> <packagereq type = "default" >tcpdump</packagereq> <packagereq type = "default" >mtr</packagereq> <packagereq type = "default" >iptabels-services</packagereq> <packagereq type = "default" >traceroute</packagereq> <packagereq type = "default" >ipmitool</packagereq> <packagereq type = "default" >wget</packagereq> <packagereq type = "default" >zabbix_agentd</packagereq> <packagereq type = "default" >iptraf-ng</packagereq> <packagereq type = "default" >ansible</packagereq> <packagereq type = "default" >rsync</packagereq> <packagereq type = "default" >pciutils</packagereq> <packagereq type = "default" >kernel-devel</packagereq> <packagereq type = "default" >kernel-headers</packagereq> <packagereq type = "optional" >tboot</packagereq> </packagelist> </group> <environment> <id>minimal</id> <name>Minimal Install</name> <name xml:lang= "as" >নূন্যতম ইনস্টল</name> ………………………… <description xml:lang= "zh_CN" >基本功能。</description> <description xml:lang= "zh_TW" >基本功能。</description> <display_order>5</display_order> <grouplist> <groupid>core</groupid> <groupid>core</groupid> </grouplist> </environment> </comps> #在default标签下写自己要下载的软件。前提是制作目录/root/iso/Package/下有相应的rpm及依赖包。 |
重新生产repo源
# cd /root/iso/
# createrepo -g repodata/*-c7-minimal-x86_64-comps.xml .
# 注意当有新包加入,或者更新*comps.xml文件,均需要重新生成repodata文件夹
修改安装界面图标背景
/media/usr/share/anaconda/pixmaps/sidebar-logo.png为该安装界面的图标,只需根据自己的需要替换即可,分辨率要跟原图保持基本一致,要不会出现图标过大的情况;图片大小131×115
1 2 3 4 5 6 7 8 9 | # unsquashfs /root/iso/LiveOS/squashfs.img # 会在root家用户目录下;出现一个squashfs-root/ # mount -o loop,rw squashfs-root/LiveOS/rootfs.img /media # 把解压后的文件进行挂载,然后操作 # 将解压后的文件重新打包 # mksquashfs squashfs-root/ squashfs.img 并将生成的squashfs.img替换原来的 /root/iso/LiveOS/squashfs .img |
制作ISO
1 2 | mkisofs -o /root/*******-7.9.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 CentOS /root/iso/ # 注意参数中的-V,和上面的isolinux.cfg文件有关。 |
感谢这几位的博客及官网文档;
Kickstart官网文档 :https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/installation_guide/chap-installing-using-anaconda-x86
博客
https://www.cnblogs.com/yiy520/p/13307030.html
https://ieevee.com/tech/2016/08/20/kickstart.html
https://www.wumingx.com/linux/centos-iso.html
https://www.cnblogs.com/panyouming/p/8401038.html
https://www.jianshu.com/p/0edb49c3e9b4
https://blog.51cto.com/boytnt/2147184
https://www.cnblogs.com/yanh0606/p/10910808.html