300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > iso镜像添加软件包_Linux系统自定义制作ISO安装镜像

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

时间:2021-08-18 08:31:33

相关推荐

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

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

一、安装前准备

安装工具:

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

下载CentOS7 镜像:

[root@localhost ~]# wget /centos-vault/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso

二、基础准备与介绍

1.创建目录并挂载镜像

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

[root@localhost ~]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /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校验公钥

├── TRANS.TBL # 提供比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/copy-rpms.sh

#脚本文件内容如下

#!/bin/bash

rpm -qa > rpmpackage-list.txt

old_rpms='/mnt/centos7/Packages'

new_rpms='/root/centos7/Packages'

while read line; do

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

done < rpmpackage-list.txt

rm -f rpmpackage-list.txt

[root@localhost ~]# chmod +x /root/copy-rpms.sh

[root@localhost ~]# ./copy-rpms.sh

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

3.重新⽣成repodata

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

repodata⽬录中的 comps.xml ⽂件包含了安装时⽤户所⻅到的与rpm相关的所有内容,它会检查Packages下的rpm包的依赖关系,安装时如果缺少依赖包,它会提示您哪个rpm包需要哪些依赖库,同时它的⻆⾊就是相当于图形安装时选择软件包那个环节。

comps.xml 主要由三部分组成,⾸先是组列表,它描述了在安装过程中需要的不同的组(或组件),包括组名、组的描述和包含的rpm包;其次是组的层次结构,它将组分成不同的类,并定义了组的⼀个顺序,从⽽可以决定哪些组需要先安装;最后为⼀系列RPM包以及它们之间的依赖关系。

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

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

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

Spawning worker 0 with 10 pkgs

Spawning worker 1 with 10 pkgs

Spawning worker 2 with 10 pkgs

Spawning worker 3 with 10 pkgs

Spawning worker 4 with 10 pkgs

Spawning worker 5 with 10 pkgs

Spawning worker 6 with 10 pkgs

Spawning worker 7 with 10 pkgs

Spawning worker 8 with 10 pkgs

Spawning worker 9 with 10 pkgs

Spawning worker 10 with 10 pkgs

Spawning worker 11 with 10 pkgs

Spawning worker 12 with 10 pkgs

Spawning worker 13 with 10 pkgs

Spawning worker 14 with 10 pkgs

Spawning worker 15 with 10 pkgs

Spawning worker 16 with 10 pkgs

Spawning worker 17 with 10 pkgs

Spawning worker 18 with 10 pkgs

Spawning worker 19 with 10 pkgs

Spawning worker 20 with 10 pkgs

Spawning worker 21 with 10 pkgs

Spawning worker 22 with 10 pkgs

Spawning worker 23 with 10 pkgs

Spawning worker 24 with 10 pkgs

Spawning worker 25 with 10 pkgs

Spawning worker 26 with 10 pkgs

Spawning worker 27 with 10 pkgs

Spawning worker 28 with 10 pkgs

Spawning worker 29 with 10 pkgs

Spawning worker 30 with 10 pkgs

Spawning worker 31 with 10 pkgs

Spawning worker 32 with 10 pkgs

Spawning worker 33 with 10 pkgs

Spawning worker 34 with 10 pkgs

Spawning worker 35 with 10 pkgs

Spawning worker 36 with 10 pkgs

Spawning worker 37 with 10 pkgs

Spawning 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/

4a245f61623d34cc32c7396e283d04c126a15dff82bfece87c1acee9480e885a-other.sqlite.bz2 bc140c8149fc43a5248fccff0daeef38182e49f6fe75d9b46db1206dc25a6c1c-comps.xml.gz

59914dc0634a9a0f0544f9d7def5f5e7fb27cff32b1e4c0d0a20ff198cb96ffa-other.xml.gz e07cbf8e1a83e0dd853a80ea66a932a8aaefe462ffdcdf553b72eb84c8e1671a-primary.sqlite.bz2

5a229b511f19b05f73e85fc5104de2129c9dfe0fba9826d93a6fa1386109157c-filelists.xml.gz ef7d320aab4eecfbaf182b9670c243af769d310396c036ec54487571fc7f440a-filelists.sqlite.bz2

60540f4e347e531b6e5ba5ab9c710eb5a2949f6dc11687750739bc3c5a599af4-primary.xml.gz repomd.xml

aced7d22b338fdf7c0a71ffcf32614e058f4422c42476d1f4b9e9364d567702f-comps.xml

[root@localhost centos7]#

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

repomd.xml中所记录的不同。

4.生成一个ISO镜像文件

⽣成同时⽀持EFI启动(需指定-eltorito-alt-boot -e images/efiboot.img -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 TRANS.TBL

[root@localhost centos7]# genisoimage -v -cache-inodes -joliet-long -R -J -T -V 'CentOS 7 x86_64' -o ../c75.iso -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -b images/efiboot.img -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,必须对应isolinux.cfg中的LABEL。如果标签里面有空格转义字符需要将它转换成空格并加单引号。如inst.stage2=hd:LABEL=CentOS\x207\x20x86_64,-V ‘inst.stage2=hd:LABEL=CentOS\x207\x20x86_64’

5.嵌⼊md5值

嵌⼊md5值

[root@localhost centos7]# implantisomd5 /root/c75.iso

Inserting md5sum into iso image...

md5 = 23645008db9fc5f84b5c375e4ace39f3

Inserting fragment md5sums into iso image...

fragmd5 = 498c9b217c5ff1b6841646b5c232b5388f1a28deba14d334499c829469ea

frags = 20

Setting supported flag to 0

验证md5值

[root@localhost ~]# checkisomd5 /root/c75.iso

Press [Esc] to abort check.

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

It is OK to use this media.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。