定制自动化镜像

==作者:YB-Chi==

[TOC]

打包

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
# 安装系统时只勾选必要的组件 保持系统的精简

# 操作时请按照此文档
# 创建文件夹
mkdir /ISO
mkdir -p /root/iso/

# copy镜像文件至/root/iso 挂载
mount -o loop /root/iso/CentOS-7-x86_64-DVD-1708.iso /mnt
# 同步/mnt/cdrom/下的文件到/ISO/路径下,除了Packages和repodata文件夹
/usr/bin/rsync -a --exclude=Packages/ --exclude=repodata/ /mnt/cdrom/ /ISO/

# 查看ISO下文件
ls /ISO/

CentOS_BuildTag EFI EULA GPL images isolinux LiveOS RPM-GPG-KEY-CentOS-7 RPM-GPGKEY-CentOS-Testing-7 TRANS.TBL
# 在/ISO/文件夹下新建Packages和repodata文件夹
mkdir -p /ISO/{Packages,repodata}

ls /ISO/

CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPGKEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL

# ======================================================================
# 以下内容为,缩减rpm包数量,减少不必须的安装文件
# 问题:这类做法安装时提示--Error Checking Software Selection--导致安装失败
# 预估为安装包不完整,当把/mnt/cdrom/Packages下全部的rpm包放到/ISO/Packages中,安装完成
cd /root/iso/
vim copy_rpm.sh

#!/bin/bash
cd /root
rpm -qa > package.txt
DVD='/mnt/cdrom/Packages'
NEW_DVD='/ISO/Packages'
while read LINE
do
cp ${DVD}/${LINE}*.rpm /${NEW_DVD} || echo "\$LINE don't cp......."
done < package.txt
rm -rf package.txt

# 给执行权限
chmod +x copy_rpm.sh
# 执行copy程序
./copy_rpm.sh
# ======================================================================
# 如果报错则copy全部rpm包
cp /mnt/cdrom/Packages/* /ISO/Packages/
# 查看两个路径下包的数量
ll /mnt/cdrom/Packages/ | wc -l
ll /ISO/Packages/ | wc -l
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
105
106
107
108
109
110
111
112
113
114
115
116
# 制作ks.cfg文件
cp ~/initial-setup-ks.cfg /ISO/isolinux/ks.cfg
vim /ISO/isolinux/ks.cfg

#version=DEVEL
# X Window System configuration information
xconfig --startxonboot
# License agreement
eula --agreed
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# System services
services --enabled="chronyd"
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8

# Network information
# network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network --hostname=xwzx.160.com

# Root password
rootpw --iscrypted
$6$yYuwYKvNEEx376YS$.a9czD0NQuJzq7dF2xX1kOT1NsghSU.kLHeBjSKnSKc9TXV4jl93T54w9/SLJMEa.4Dju
mmlyFgMfAg0YgPWE1
# dev用户组
group --name=dev
# dev用户
user --groups=dev --name=dev --password=dev
# System timezone
timezone Asia/Shanghai --isUtc
# Firewall configuration
firewall --disabled

# SELinux configuration
selinux --disabled

# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr

# Partition clearing information
clearpart --all --initlabel
# autopart --type=lvm
part swap --fstype="swap" --ondisk=sda --size=6017
part / --fstype="xfs" --grow --ondisk=sda --size=1
# 多快盘不挂载home 如果raid方式做成一块盘则需要挂载home 修改/的size为102400 home的size=1
#part /home --fstype="xfs" --size=895626
part /boot --fstype="xfs" --ondisk=sda --size=1024
#part /boot/efi --fstype="xfs" --size=1024

reboot

%packages
@^developer-workstation-environment
@additional-devel
@base
@core
@debugging
@desktop-debugging
@development
@dial-up
@directory-client
@fonts
@gnome-apps
@gnome-desktop
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-applications
@internet-browser
@java-platform
@kde-desktop
@legacy-x
@multimedia
@network-file-system-client
@performance
@perl-runtime
@perl-web
@platform-devel
@print-client
@python-web
@ruby-runtime
@security-tools
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
@web-server
@x11
chrony
kexec-tools

%end

%post
id dev &>; /dev/null || useradd dev
echo dev | passwd –stdin dev
%end

%addon com_redhat_kdump --enable --reserve-mb=auto
%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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vim /ISO/isolinux/isolinux.cfg
# 给安装和测试安装的部分加入inst.ks=cdrom:/isolinux/ks.cfg,以及更改
inst.stage2=hd:LABEL=CentOS7
# inst.ks为ks.cfg文件位置;
# hd:LABEL为介质标签,例如CentOS7。这个和后续生成ISO镜像文件的命令genisoimage的参数-V有关。

label linux
menu label ^Install CentOS 7 # 此行为安装界面展示的列表
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS7 inst.ks=cdrom:/isolinux/ks.cfg
quiet

label check
menu label Test this ^media & install CentOS 7 # 此行为安装界面展示的列表
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS7 inst.ks=cdrom:/isolinux/ks.cfg
rd.live.check quiet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 制作comps.xml
cp /mnt/cdrom/repodata/*comps.xml /ISO/comps.xml
cd /ISO
createrepo -g comps.xml ./
ls repodata/

# 安装createrepo (将安装打包工具放在最后是为了避免一开始生成的package.txt包含这个组件)
yum -y install anaconda createrepo mkisofs rsync syslinux

# 打包
# 注意参数中的-V,和上面的isolinux.cfg文件有关
# -o CentOS-7.4.iso为镜像名
# /home/software/ISO为镜像存放路径
genisoimage -joliet-long -V CentOS7 -o CentOS-7.4.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -cache-inodes -T -eltorito-alt-boot -b images/efiboot.img -no-emul-boot /home/software/ISO

文章作者: CYBSKY
文章链接: https://cybsky.top/2024/01/29/cyb-mds/linux/定制自动化镜像/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CYBSKY