2023年12月11日发(作者:)

iso镜像添加软件包_Linux系统自定义制作ISO安装镜像

本文主要介绍如何根据官方的CentOS7镜像文件,在保留原有默认安装的RPM包的基础下,添加自己所需要的RPM包的,最终生成一个自

定制版的ISO镜像文件。

一、安装前准备

安装工具:

[root@localhost ~]# yum install createrepo mkisofs isomd5sum squashfs-tools

下载CentOS7 镜像:

二、基础准备与介绍

1.创建目录并挂载镜像

[root@localhost ~]# mkdir /mnt/centos7

[root@localhost ~]# mount -o loop CentOS-7-x86_ /mnt/centos7/

#mount: /dev/loop1 is write-protected, mounting read-only 注此处挂载由于镜像写保护,只能挂载只读

2.查看镜像里面文件内容

[root@localhost ~]# cd /mnt/centos7/

[root@localhost centos7]# tree -a -L 1

.

├── CentOS_BuildTag # 系统版本构建标签

├── .discinfo # 包含安装盘的识别信息,如果缺少此文件,将导致使用定制后的ISO安装系统时,在初始化过程中提示找不到光盘!

├── EFI # UEFI 启动模式下必须文件,Legacy模式下是非必须文件

├── EULA # 最终用户许可协议

├── GPL # 通用公用许可证/执照(General Public License)

├── images # 启动文件和驱动盘映像文件目录,最重要的是第二阶段的引导映像

├── isolinux # 存放光盘启动时的安装界面信息

├── LiveOS # 存储了映像文件

├── Packages # 系统自带二进制RPM安装包目录

├── repodata # 系统自带RPM安装包的描述文件,如依赖关系,包含文件,校验码信息

├── RPM-GPG-KEY-CentOS-7 # rpm的GPG校验公钥

├── RPM-GPG-KEY-CentOS-Testing-7 # rpm的GPG校验公钥

├── # 提供比ISO9660标准约定的基本文件名更加灵活的文件名, 用简约符号代表目录、文件、链接;

└── .treeinfo # 记录不同的安装方式下,安装程序所在的目录结构

6 directories, 8 files

三、构建自定义镜像

1.构建ISO生成目录和复制/mnt/centos7中文件到/root/centos7目录之中

[root@localhost ~]# mkdir /root/centos7[root@localhost ~]# rsync -a --exclude=Packages/ --exclude=repodata/ /mnt/centos7/ /root/centos7/

[root@localhost ~]#

[root@localhost ~]# cp /mnt/centos7/.discinfo /root/centos7/

[root@localhost ~]# cp /mnt/centos7/.treeinfo /root/centos7/

注意:拷贝时没有拷贝隐藏文件.discinfo和.treeinfo。如果没有拷⻉ .discinfo 文件,将导致使用定制后的ISO安装系统时,在初始化过程中

提示找不到光盘!

2.复制当前系统rpm包(剔除多余的rpm包)

[root@localhost ~]# mkdir /root/centos7/{Packages,repodata}

[root@localhost ~]# vim /root/

#脚本文件内容如下

#!/bin/bash

rpm -qa >

old_rpms='/mnt/centos7/Packages'

new_rpms='/root/centos7/Packages'

while read line; do

cp ${old_rpms}/${line}*.rpm ${new_rpms} || echo "${line} "

done <

rm -f

[root@localhost ~]# chmod +x /root/

[root@localhost ~]# ./

#拷贝中有些rpm包因为版本号问题不存,关系不大

3.重新生成repodata

如果是全拷⻉原ISO文件,则不需要此步骤! 如果是精简处理后或Packages内容有变化时都要重新生成repodata。

repodata目录中的 文件包含了安装时用户所⻅到的与rpm相关的所有内容,它会检查Packages下的rpm包的依赖关系,安装

时如果缺少依赖包,它会提示您哪个rpm包需要哪些依赖库,同时它的⻆色就是相当于图形安装时选择软件包那个环节。

主要由三部分组成,首先是组列表,它描述了在安装过程中需要的不同的组(或组件),包括组名、组的描述和包含的rpm包;

其次是组的层次结构,它将组分成不同的类,并定义了组的一个顺序,从而可以决定哪些组需要先安装;最后为一系列RPM包以及它们之

间的依赖关系。

[root@localhost ~]# cp /mnt/centos7/repodata/*- /root/centos7/repodata/

[root@localhost ~]# cd /root/centos7/

[root@localhost centos7]# createrepo -g /root/centos7/repodata/ ./

Spawning worker 0 with 10 pkgs

Spawning worker 1 with 10 pkgs

Spawning worker 2 with 10 pkgs

Spawning worker 3 with 10 pkgsSpawning worker 4 with 10 pkgsSpawning worker 5 with 10 pkgsSpawning worker 6 with 10 pkgsSpawning worker 7 with 10 pkgsSpawning worker 8 with 10 pkgsSpawning worker 9 with 10 pkgsSpawning worker 10 with 10 pkgsSpawning worker 11 with 10 pkgsSpawning worker 12 with 10 pkgsSpawning worker 13 with 10 pkgsSpawning worker 14 with 10 pkgsSpawning worker 15 with 10 pkgsSpawning worker 16 with 10 pkgsSpawning worker 17 with 10 pkgsSpawning worker 18 with 10 pkgsSpawning worker 19 with 10 pkgsSpawning worker 20 with 10 pkgsSpawning worker 21 with 10 pkgsSpawning worker 22 with 10 pkgsSpawning worker 23 with 10 pkgsSpawning worker 24 with 10 pkgsSpawning worker 25 with 10 pkgsSpawning worker 26 with 10 pkgsSpawning worker 27 with 10 pkgsSpawning worker 28 with 10 pkgsSpawning worker 29 with 10 pkgsSpawning worker 30 with 10 pkgsSpawning worker 31 with 10 pkgsSpawning worker 32 with 10 pkgsSpawning worker 33 with 10 pkgsSpawning worker 34 with 10 pkgsSpawning worker 35 with 10 pkgsSpawning worker 36 with 10 pkgsSpawning worker 37 with 10 pkgsSpawning worker 38 with 10 pkgs

Spawning worker 39 with 10 pkgs

Spawning worker 40 with 10 pkgs

Spawning worker 41 with 10 pkgs

Spawning worker 42 with 10 pkgs

Spawning worker 43 with 9 pkgs

Spawning worker 44 with 9 pkgs

Spawning worker 45 with 9 pkgs

Spawning worker 46 with 9 pkgs

Spawning worker 47 with 9 pkgs

Workers Finished

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

[root@localhost centos7]# ls repodata/

4a245f62

bc140c8

59914dc

e07cbf8e12

5a229b511f1

ef7d320aab42

60540f4e3

aced7d2

[root@localhost centos7]#

编辑了,要重新生成新的,因为的sha值会改变,这样就会导致跟

中所记录的不同。

4.生成一个ISO镜像文件

生成同时支持EFI启动(需指定-eltorito-alt-boot -e images/ -no-emul-boot)的ISO镜像。

[root@localhost centos7]# ls

CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-

CentOS-Testing-7

[root@localhost centos7]# genisoimage -v -cache-inodes -joliet-long -R -J -T -V 'CentOS 7 x86_64' -o ../ -c

isolinux/ -b isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -b

images/ -no-emul-boot ./genisoimage 命令参数说明:

-o 指定映像文件的名称

-b 指定在制作可开机光盘时所需的开机映像文件

-c 制作可开机光盘时,会将开机映像文件中的no-eltorito-catalog全部内容作成一个文件

-no-emul-boot 非模拟模式启动

-boot-load-size 4 设置载入部分的数量

-boot-info-table 在启动的图像中现实信息

-joliet-long 使用joliet格式的目录与文件名称,⻓文件名支持

-R或-rock 使用Rock RidgeExtensions

-J或-joliet 使用Joliet格式的目录与文件名称

-v或-verbose 执行时显示详细的信息

-T或-translation-table 建立文件名的转换表,适用于不支持Rock Ridge Extensions的系统

-V CentOS7 指定光盘的label,必须对应中的LABEL。如果标签里面有空格转义字符需要将它转换成空格并加单引号。如

2=hd:LABEL=CentOSx207x20x86_64,-V ‘2=hd:LABEL=CentOSx207x20x86_64’

5.嵌入md5值

嵌入md5值

[root@localhost centos7]# implantisomd5 /root/

Inserting md5sum into

md5 = 23645008db9fc5f84b5c375e4ace39f3

Inserting fragment md5sums into

fragmd5 = 498c9b217c5ff1b6841646b5c232b5388f1a28deba14d334499c829469ea

frags = 20

Setting supported flag to 0

验证md5值

[root@localhost ~]# checkisomd5 /root/

Press [Esc] to abort check.

The media check is complete, the result is: PASS.

It is OK to use this media.