1. 准备构建服务器
我们必须从原始 Red Hat 或者 CentOS DVD 复制 Vanilla ISO 中存在的目录结构。
注意:遵循与 DVD 中存在的相同目录结构不是强制性的,但它会使生活更轻松,或者最后必须修改一些另外的配置文件以确保引导过程在正确的位置查找引导文件.
我将使用与 vanilla DVD 中相同的目录结构
下面将是我的父目录,我将其中复制用于自定义的 DVD 目录结构
# mkdir /root/geniso
我已经在我的服务器上安装了 vanilla DVD,因此会将 DVD 安装到临时安装点
# mount /dev/sr0 /mnt
接下来将整个内容复制到我的构建服务器位置,稍后我们可以删除或者自定义所需的内容
# cp -rvf /mnt/* /root/geniso
成功复制所有内容后,让我们进入下一步
2. 创建一个 kickstart 文件
自己从头开始创建 kicstart 文件可能会很棘手,因此我们在这里有两个选择。
- 我们使用根文件夹中可用的 anaconda.cfg 文件作为模板并根据要求对其进行修改
- 使用以下链接使用 Red Hat Kickstart Generator 创建我们自己的自定义 kickstart 文件
https://access.redhat.com/labs/kickstartconfig/
这里是我使用的 kickstart 示例文件
# Kickstart configuration for RHEL7.3 #platform=x86, AMD64, or Intel EM64T # System authorization information auth --enableshadow --passalgo=sha512 # Clear the Master Boot Record zerombr # Partition clearing information clearpart --drives=sda --all # Use text mode install #text graphical # Firewall configuration firewall --disabled # Run the Setup Agent on first boot firstboot --reconfig --enable # System keyboard keyboard us # System language lang en_US.UTF-8 # Skipping input of key #key --skip # Installation logging level logging --level=info # Use NFS installation media cdrom # Network Information network --bootproto=static --hostname=my-linux --device=eth0 --gateway=1.2.3.1 --ip=1.2.3.4 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate # System bootloader configuration bootloader --location=mbr --driveorder=sda # The following is the partition information you requested ignoredisk --only-use=sda # Disk Partioning clearpart --all --initlabel autopart #Root password rootpw --iscrypted $uiq8l/7xEWsYXfc0$c9RrvkF/jRzk1JtvQNX2l4NZfkKyokorhv/gieuBMHhrvaEgan4N21yhLa8K.U7UA12Th3PD11GOXvEcI40gp1 # SELinux configuration selinux --disabled # Do not configure the X Window System # Do not configure the X Window System skipx #Disabling kdump services, owing to few problems with current kexec package services --disabled kdump # System timezone timezone --utc Europe/Berlin # Install OS instead of upgrade install # Reboot after installation reboot # list of packages to be installed %packages @ Core @ Base --nodefaults # packages deleted according to OS minimization %end
根据需要修改网络、存储和root密码相关配置。
创建加密密码
# python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())' Password: fJnhduoqOGzwUPrZHvcXyj3ktC9qrCKjuQrToM9kPFTJuG7zB1GAmeFdls07WPl9k29fo0HCcw3EycpaBASpGyajt1xU4HELid00
在 kickstart 中使用此加密密码
将这个 kickstart 文件 'ks.cfg' 放在构建服务器的父目录中,对我们来说是 '/root/geniso/'
3. 最小包列表
注意:如果我们不想减少 ISO 内容并且只想自动安装 ISO,则可以跳过此步骤
这是最棘手的部分和努力,因为很难为我们添加到列表中的任何软件包一一确定依赖项 rpm。
首先假设我们要创建一个最小设置,就像我在上面的 kickstart 文件中使用的那样。
从 Packages 目录中删除所有 rpms 并开始最小化
# pwd /root/geniso/Packages
# rm -f /root/geniso/Packages/* Search for below xml inside repodata directory
/root/geniso/repodata # ls 211ef0fc36ef7d137b1568cda9de2c7a551633b04260624153506c85fb03e226-primary.sqlite.bz2 4650720b42b35d199c8eb6520e301c182331bce1d1855d93a01282db26be7c20-productid.gz 5d580d3677a32816bfe7c5e53c050a9679e3194b26c39ac986899ad99e6a258a-other.xml.gz 7ee8d6ba4218ef10cbfb95da1eff204bbe43d76332bfc316f87398a9ea64a1e9-comps-Server.x86_64.xml 8c38f297395ffac87645682f245154e73ac05dbffde238782ee5bd4cfb29c340-primary.xml.gz b72258747300ae8f5d6195382942ef5b1e22913ca590ccc5cddc7957fe172468-filelists.xml.gz c098a816e33b2b2ac0be14d42d9a2a28caf6800fa6d68350764fb45b40edbd62-other.sqlite.bz2 c542e4cf37dd210de68877b53f41d92dc7686c6e1b35ca4b1852f2e62fca2c72-comps-Server.x86_64.xml.gz c92d15710455d42727585e36beef547c254e0c677d695f64dfaaf66a2f85f3cd-filelists.sqlite.bz2 productid repomd.xml TRANS.TBL
使用 *comps-Server.x86_64.xml 打开文件,该文件将包含用于最小设置的强制性软件包列表
在xml文件中搜索如下组核心
<group> <id>core</id> <name>Core</name> which will be followed by mandatory package list <packagelist> <packagereq type="mandatory">Red_Hat_Enterprise_Linux-Release_Notes-7-en-US</packagereq> <packagereq type="mandatory">audit</packagereq> <packagereq type="mandatory">basesystem</packagereq> <packagereq type="mandatory">bash</packagereq> <packagereq type="mandatory">biosdevname</packagereq> <packagereq type="mandatory">btrfs-progs</packagereq> <packagereq type="mandatory">coreutils</packagereq> <packagereq type="mandatory">cronie</packagereq> <packagereq type="mandatory">curl</packagereq> .... </packagelist> </group>
我们可以创建一个脚本,该脚本将仅使用 rpm 名称对上述列表进行排序,并将这些 rpm 复制到原始 DVD 的 Packages 目录中
接下来我们必须为这个新内容创建一个 repodata 所以在你的构建服务器上安装 createrepo rpm
# rpm -Uvh createrepo-0.9.9-26.el7.noarch.rpm warning: createrepo-0.9.9-26.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating/installing... 1:createrepo-0.9.9-26.el7 ################################# [100%]
可能存在一些依赖项,例如 python-deltarpm、deltarpm、libxml2-python,因此请确保它们也已安装。
假设我们有一个已配置的 yum 存储库,则可以使用 'yum' 进行安装。
注意:在 RHEL 系统上,我们必须有 RHN 的有效订阅,或者我们可以配置本地离线存储库,使用“yum”包管理器可以安装提供的 rpm 及其依赖项。
接下来更新 Packages 目录的 repodata
# createrepo Packages/ Spawning worker 0 with 469 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
这将在 Packages 中创建一个 repodata 目录,其中包含所需的 comps xml 文件。
注意:这里可能存在许多 rpm 的依赖问题,我们可以使用以下命令单独识别
# rpm -qpR createrepo-0.9.9-26.el7.noarch.rpm warning: createrepo-0.9.9-26.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY /bin/sh /usr/bin/python deltarpm libxml2-python pyliblzma python >= 2.1 python(abi) = 2.7 python-deltarpm rpm >= 4.1.1 rpm-python rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 yum >= 3.4.3-4 yum-metadata-parser rpmlib(PayloadIsXz) <= 5.2-1
接下来执行以下命令以获取单个文件的依赖项 rpm 例如
# yum whatprovides */python-deltarpm* Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. python-deltarpm-3.6-3.el7.x86_64 : Python bindings for deltarpm Repo : Server Matched from: Filename : /usr/share/doc/python-deltarpm-3.6/LICENSE.BSD Filename : /usr/share/doc/python-deltarpm-3.6 python-deltarpm-3.6-3.el7.x86_64 : Python bindings for deltarpm Repo : installed Matched from: Filename : /usr/share/doc/python-deltarpm-3.6/LICENSE.BSD Filename : /usr/share/doc/python-deltarpm-3.6/
在这里我们可以看到python-deltarpm的依赖rpm名称
我总是更喜欢使用安装了“最小”组的 Red Hat 中的包列表,它会给我“核心”和依赖项 rpm 的列表( rpm -qa | sort ),并且同样可以用于所有未来的自定义作为基本软件包列表,
4. 修改 GRUB 菜单
将目录更改为
# pwd /root/geniso/isolinux
请注意“isolinux.cfg”文件中的以下几行
# vim isolinux.cfg label linux menu label ^Install Red Hat Enterprise Linux 7.3 kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.3x20Server.x86_64 quiet
这里改成
label linux menu label ^Install Red Hat Enterprise Linux 7.3 kernel vmlinuz append initrd=initrd.img inst.repo=cdrom ks=cdrom:/ks.cfg net.ifnames=0 biosdevname=0
注意:这里我使用另外的引导菜单参数“net.ifnames=0 biosdevname=0”来禁用一致的网络设备命名,因为我更喜欢为我的接口使用“ethXX”名称。
这是可选的,我们可以选择不在系统中使用它
这里 ks.cfg 是我们在本文第 2 步中创建的 kickstart 文件。
5. 创建 ISO
我们几乎完成了所有需要的配置。
安装 'genisoimage' rpm 来构建 ISO
# rpm -Uvh libusal-1.1.11-23.el7.x86_64.rpm genisoimage-1.1.11-23.el7.x86_64.rpm warning: libusal-1.1.11-23.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating/installing... 1:libusal-1.1.11-23.el7 ################################# [ 50%] 2:genisoimage-1.1.11-23.el7 ################################# [100%]
接下来执行以下命令在 /tmp/中创建一个名为“new.iso”的 ISO
# cd /root/geniso # mkisofs -o /tmp/new.iso -b isolinux/isolinux.bin -c isolinux/boot.cat --no-emul-boot --boot-load-size 4 --boot-info-table -J -R -V "RHEL-7.3x20Server.x86_64" .
此处“RHEL-7.3x20Server.x86_64”是我分配给我的 DVD 的标签,我们可以根据需要进行修改
.... 98.02% done, estimate finish Sun Jan 21 16:18:13 2015 99.22% done, estimate finish Sun Jan 21 16:18:13 2015 Total translation table size: 2048 Total rockridge attributes bytes: 296100 Total directory bytes: 602112 Path table size(bytes): 1802 Max brk space used 322000 418288 extents written (816 MB)
我们的 ISO 已准备就绪,可用于自动安装。