定制化ISO镜像

ISO镜像版本选择

1
CentOS-7-x86_64-Minimal-1810.iso

制作工具安装

1
yum -y install anaconda createrepo mkisofs rsync syslinux

挂载光盘,同步文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mkdir /mnt/cdrom

mount -o loop /tmp/CentOS-7-x86_64-Minimal-1708.iso /mnt/cdrom/
<<'COMMENT'
mount: /dev/loop0 is write-protected, mounting read-only
COMMENT

# 同步/mnt/cdrom/下的文件到/ISO/路径下,除了Packages和repodata文件夹
/usr/bin/rsync -a /mnt/cdrom/ /ISO/

ls /ISO/
<<'COMMENT'
CentOS_BuildTag EFI EULA GPL images isolinux LiveOS RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
COMMENT

制作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
cd /ISO/isolinux

cat > ks.cfg <<EOF
#version= CentOS 7
#platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$Jg7P7.9/$TT.baSvBhZy/wOkSs9CDT/
# (Required) Wrapper around the authconfig command CCE-14063-2 (row 80)
authconfig --enableshadow --passalgo=sha512
# System language
lang en_US.UTF-8
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# Network information
network --bootproto=dhcp --device=ens160 --onboot=yes --ipv6=auto --activate
network --device=ens160 --hostname=localhost.localdomain
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --location=mbr --driveorder=sda --append=""
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
autopart --type=lvm

%packages
@^minimal
@core
@customrpm

%end

修改isolinux.cfg

1
2
3
4
5
cd /ISO/isolinux

chmod 644 isolinux.cfg

sudo vi isolinux.cfg

修改的部分内容如下:

1
2
3
4
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

inst.ks为ks.cfg文件位置;
inst.stage2为安装介质位置,hd:LABEL为介质标签,例如CentOS7。这个和后续生成ISO镜像文件的命令genisoimage的参数-V有关。
modprobe.blacklist=nouveau; 禁用nouveau驱动安装,用于NVIDIA驱动的安装准备工作;
net.ifnames=0 biosdevname=0; 用于禁用centos7的”一致性网络设备命名法”.

制作comps.xml文件

1
cp /mnt/cdrom/repodata/*-minimal-x86_64-comps.xml /ISO/comps.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
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
<?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="am">ማዕከላዊ ቦታ</name>
<name xml:lang="ar">اللبّ</name>
<name xml:lang="as">ভিত্তি</name>
....
<name xml:lang="tr">Çekirdek</name>
<name xml:lang="uk">Основа</name>
<name xml:lang="ur">مرکز</name>
<name xml:lang="vi">Lõi</name>
<name xml:lang="zh_CN">核心</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="bn">ন্যূনতম ইনস্টলেশন।</description>
<description xml:lang="bn_IN">ন্যূনতম ইনস্টলেশন।</description>
<description xml:lang="cs">Nejmenší možná instalace.</description>
<description xml:lang="de">Kleinstmögliche Installation.</description>
<description xml:lang="es">La instalación más pequeña posible.</description>
<description xml:lang="fr">Plus petite installation possible.</description>
....
<description xml:lang="ru">Минимально возможная установка</description>
<description xml:lang="sv">Minsta möjliga installation</description>
<description xml:lang="ta">மிகச் சிறிய செயல்படுத்தக்கூடிய நிறுவல்.</description>
<description xml:lang="te">సాధ్యమగు అతిచిన్న సంస్థాపన.</description>
<description xml:lang="uk">Мінімально можливе встановлення.</description>
<description xml:lang="zh_CN">最小可能安装。</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">biosdevname</packagereq>
<packagereq type="mandatory">irqbalance</packagereq>
<packagereq type="mandatory">kbd</packagereq>
<packagereq type="mandatory">kexec-tools</packagereq>
<packagereq type="mandatory">less</packagereq>
...
<packagereq type="default">rdma</packagereq>
<packagereq type="optional">dracut-config-generic</packagereq>
<packagereq type="optional">dracut-fips</packagereq>
<packagereq type="optional">dracut-fips-aesni</packagereq>
<packagereq type="optional">dracut-network</packagereq>
<packagereq type="optional">openssh-keycat</packagereq>
<packagereq type="optional">selinux-policy-mls</packagereq>
<packagereq type="optional">tboot</packagereq>
</packagelist>
</group>
<group>
<id>custom</id>
<name>custom</name>
<name xml:lang="af">custom</name>
<name xml:lang="am">custom</name>
<name xml:lang="ar">custom</name>
<name xml:lang="as">custom</name>
<name xml:lang="bal">custom</name>
...
<name xml:lang="vi">custom</name>
<name xml:lang="zh_CN">custom</name>
<name xml:lang="zh_TW">custom</name>
<name xml:lang="zu">custom</name>
<description>installation custom sofeware.</description>
<description xml:lang="as">installation custom sofeware.</description>
<description xml:lang="bn">installation custom sofeware.</description>
<description xml:lang="bn_IN">installation custom sofeware.</description>
<description xml:lang="cs">installation custom sofeware.</description>
...
<description xml:lang="uk">installation custom sofeware.</description>
<description xml:lang="zh_CN">installation custom sofeware.</description>
<description xml:lang="zh_TW">installation custom sofeware.</description>
<default>false</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq type="default">redis50-5.0.6-1.el7.x86_64</packagereq>
</packagelist>
</group>
<environment>
<id>minimal</id>
<name>Minimal Install</name>
<name xml:lang="as">নূন্যতম ইনস্টল</name>
<name xml:lang="bn_IN">ন্যূনতম ইনস্টল</name>
<name xml:lang="cs">Minimální instalace</name>
<name xml:lang="de">Minimale Installation</name>
<name xml:lang="es">Instalación mínima</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>
<groupid>custom</groupid>
</grouplist>
</environment>
</comps>

comps文件以group来区分包,以environment来区分环境,例如centos的mini版本为minimal,其核心包为core。类似于其格式,可定制自己的rpm包,建立自己的group id和name,包含自己的language及描述,最重要的是packagelist,类型default为默认的,mandatory为强制的

将定制的rpm安装包放到/ISO/Packages/中。这里需要注意rpm包的依赖性,可以通过以下命令来获得依赖,例如以下需要perl安装rpm,然后同样添加到comps.xml中

由comps.xml生成repodata包。注意当有新包加入,或者更新comps.xml文件,均需要重新生成repodata文件夹

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cd /ISO

createrepo -g comps.xml .
<<'COMMENT'
Spawning worker 0 with 369 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
COMMENT

ls repodata/
<<'COMMENT'
2b873dfb5efcd23c4556c64f85f8752dea89a1b78ac2d81f5a3a2479a6364aed-primary.sqlite.bz2 ba731bbd51e5526bdf722d98e006d633bfd76ec48c283921f4dfd1eeb95c6478-filelists.xml.gz
36f3b0cba95abd61f2f871ed31db124a1b9c7838e29cf992a59a093935ecf626-other.xml.gz d36769d1a5c1b5480e99904a03b6d487f84d34c8075b5eb6b290e90802e3ea2a-comps.xml
6d916600909af4ba73f09e2c5877a3fa8e2811d8bf8f43909e83c72c27af51f2-comps.xml.gz e2987de1d65f29e23f8d4ac01f8544b1fe47596dd93928026f4ac4a766cfb018-primary.xml.gz
6e0e0fec735b69e035c67f68ab629182c703ad1840b37dceefaba9e5093a7747-filelists.sqlite.bz2
repomd.xml
ac0924ead0d2101950c99e0670d1b74c8fea364a6bddca6415d04eb6102d0b08-other.sqlite.bz2
COMMENT

制作ISO镜像

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
cd /ISO

# 注意参数中的-V,和上面的isolinux.cfg文件有关
genisoimage -joliet-long -V CentOS7 -o CentOS-7-custom.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 -e images/efiboot.img -no-emul-boot /ISO

I: -input-charset not specified, using utf-8 (detected in locale settings)
genisoimage 1.1.11 (Linux)
Scanning /ISO
Scanning /ISO/EFI
Scanning /ISO/EFI/BOOT
Scanning /ISO/EFI/BOOT/fonts
Excluded: /ISO/EFI/BOOT/fonts/TRANS.TBL
Excluded: /ISO/EFI/BOOT/TRANS.TBL
Excluded: /ISO/EFI/TRANS.TBL
Scanning /ISO/LiveOS
Excluded: /ISO/LiveOS/TRANS.TBL
Scanning /ISO/images
Scanning /ISO/images/pxeboot
Excluded: /ISO/images/pxeboot/TRANS.TBL
Excluded: /ISO/images/TRANS.TBL
Scanning /ISO/isolinux
Excluded: /ISO/isolinux/TRANS.TBL
Excluded by match: /ISO/isolinux/boot.cat
Excluded: /ISO/TRANS.TBL
Scanning /ISO/Packages
Scanning /ISO/repodata
Using RPM_G000.;1 for /RPM-GPG-KEY-CentOS-Testing-7 (RPM-GPG-KEY-CentOS-7)
Using PYTHO000.RPM;1 for /ISO/Packages/python2-crypto-2.6.1-15.el7.x86_64.rpm (python2-cryptography-1.7.2-1.el7.x86_64.rpm)
...
Using HUNSP002.RPM;1 for /ISO/Packages/hunspell-en-0.20121024-6.el7.noarch.rpm (hunspell-en-US-0.20121024-6.el7.noarch.rpm)
Using LIBER000.RPM;1 for /ISO/Packages/liberation-fonts-common-1.07.2-15.el7.noarch.rpm (liberation-sans-fonts-1.07.2-15.el7.noarch.rpm)
Writing: Initial Padblock Start Block 0
Done with: Initial Padblock Block(s) 16
Writing: Primary Volume Descriptor Start Block 16
Done with: Primary Volume Descriptor Block(s) 1
Writing: Eltorito Volume Descriptor Start Block 17
Size of boot image is 4 sectors -> No emulation
Done with: Eltorito Volume Descriptor Block(s) 1
Writing: Joliet Volume Descriptor Start Block 18
Done with: Joliet Volume Descriptor Block(s) 1
Writing: End Volume Descriptor Start Block 19
Done with: End Volume Descriptor Block(s) 1
Writing: Version block Start Block 20
Done with: Version block Block(s) 1
Writing: Path table Start Block 21
Done with: Path table Block(s) 4
Writing: Joliet path table Start Block 25
Done with: Joliet path table Block(s) 4
Writing: Directory tree Start Block 29
Done with: Directory tree Block(s) 42
Writing: Joliet directory tree Start Block 71
Done with: Joliet directory tree Block(s) 29
Writing: Directory tree cleanup Start Block 100
Done with: Directory tree cleanup Block(s) 0
Writing: Extension record Start Block 100
Done with: Extension record Block(s) 1
Writing: The File(s) Start Block 101
1.43% done, estimate finish Tue Nov 14 17:08:17 2017
2.87% done, estimate finish Tue Nov 14 17:08:17 2017
4.30% done, estimate finish Tue Nov 14 17:08:17 2017
...
95.89% done, estimate finish Tue Nov 14 17:08:18 2017
97.33% done, estimate finish Tue Nov 14 17:08:18 2017
98.76% done, estimate finish Tue Nov 14 17:08:18 2017
Total translation table size: 106045
Total rockridge attributes bytes: 46850
Total directory bytes: 79872
Path table size(bytes): 140
Done with: The File(s) Block(s) 376656
Writing: Ending Padblock Start Block 376757
Done with: Ending Padblock Block(s) 150
Max brk space used 85000
349350 extents written (736 MB

Hybird模式

采用“hybird模式”(混合模式),操作系统可以直接刻录成物理光盘,也可以直接做成可引导的U盘。

1
isohybrid -v /ISO/CentOS-7-custom.iso

制作镜像MD5值

1
2
3
4
5
6
7
8
9
10
implantisomd5 /ISO/CentOS-7-ChenjianOS.iso

<<'COMMENT'
Inserting md5sum into iso image...
md5 = ed6233dc8bf6e59353a646e286b7a51f
Inserting fragment md5sums into iso image...
fragmd5 = 4c9fb671374f6b26bdaf49d5452ec7862f97e3899f9eac23a7e8f4f84d25
frags = 20
Setting supported flag to 0
COMMENT

安装系统

iso安装系统不再叙述;

由于是text模式,则进入安装界面,会有一个类似图形安装界面的排版,里面可以选择。所有选择均为x的时候,表示正常无误;有!的话,则为错误。错误时需要查看日志,其中Alt+F1快捷键可以进入main界面,Alt+F2快捷键可以进入Shell界面等等。在Shell界面中,可以从/tmp/packaging.log中找到rpm包日志,可以从/tmp/anaconda.log中找到安装过程中的报错日志;可以从/run/install/repo路径下找到外部文件夹;

当选项均为x时,即表示正常无误,可以不进行操作,其自动进入下一步安装过程,直至安装成功,然后自动重启,显示登录界面。

参考文章

https://www.cnblogs.com/fantasyxo/p/14434035.html