Fedora Server定制化封装ISO(4)-定制额外安装包

上一章节中,我们创建了自己的rpm包,这一章节中,将这个新的helloworld包放入我们的ISO构建过程中,让它能在系统安装过程中自动安装。

一般来说安装用户自己的包有两种基本的方法,一种是在ks中直接定义安装,如下所示:

...

# firstboot
firstboot --enable
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
%packages
@^server-product-environment
# 增加个性化包位置
%end

...

这种主要是比较适用于数量较少的包的安装,比较简单,容易操作,这里就不展开说明。

我们这里采用另一种方法,通过定义repodata进行定制化,这种方式适用于包比较多的情况,且包可以进行分类,用户在安装ISO的过程中可以通过图形洁面进行选择是否安装

要修改的文件在ISO文件目录的repodata中,一般是以一个比较长的字符串+comps+***+.xml的以xml结尾的文件,大家的名称可能有所不同,我这里是这样的:

[root@localhost repodata]# ls
06d801cd0a16b2afe227be8246d7196a081af7651a1bb137069e911f6c0cc81c-primary.sqlite.bz2
1c22bcfa2d36eb5d12343e2196df11f929d49cc86db2e2c94350b7bf75a8eb2f-comps-Server.x86_64.xml.xz
1e2ee4c0e23306dd479a439a0c8737cdc4d943d84a6c8fc7246799aa2a374630-comps-Server.x86_64.xml
2c6524439fabfab700ce3cb021213781ba4ea6fb9ab34b0f8429640bc6ed8281-other.xml.gz
55aaa239e4a907a146c4ebf0f4daec5f77ba35c32c2c3f39ca0fadaa555463f9-other.sqlite.bz2
5fa810c1a36379398055a9ea4501b2cfdc89700d2ffae9bb7d4a00d4551049b1-comps-Server.x86_64.xml.gz
6b89e68bc65b5eacd9b5fcd905386de3fb8d56d6544b2c894564f55ae9e4349d-primary.xml.gz
b646007b141f78470138abf9c260d3afb8541e53c1923c2560a0a6fb5ec9cf3d-filelists.xml.gz
b8b3ebb5697d7e51cd60686be9f883e4cea691a5bb09543f499a28ca85827260-filelists.sqlite.bz2
d13409d329f4c2e730f7b65e1bed2fe61643b38ebb5ee1e70a86250f714542c0-comps-Server.x86_64.xml.zck
repomd.xml

打开1e2ee4c0e23306dd479a439a0c8737cdc4d943d84a6c8fc7246799aa2a374630-comps-Server.x86_64.xml

主要看一下结构,在ks中写的安装了一个@^server-product-environment的包组,在xml中可以找到:

  <environment>
    <id>server-product-environment</id>
    <name>Fedora Server Edition</name>
    <name xml:lang="bg">Fedora Server Edition</name>
    ...
    <name xml:lang="zh_TW">Fedora Server 版本</name>
    <description>An integrated, easier to manage server.</description>
    ...
    <description xml:lang="zh_TW">整合且易於管理的伺服器。</description>
    <display_order>2</display_order>
    <grouplist>
      <groupid>core</groupid>
      <groupid>hardware-support</groupid>
      <groupid>headless-management</groupid>
      <groupid>networkmanager-submodules</groupid>
      <groupid>server-product</groupid>
      <groupid>standard</groupid>
    </grouplist>
    <optionlist>
      <groupid>container-management</groupid>
      <groupid>domain-client</groupid>
      <groupid>guest-agents</groupid>
      <groupid>server-hardware-support</groupid>
    </optionlist>
  </environment>

看到这个server-product-environment包含了多个groupid,我们再看一下group是什么结构:

  <group>
    <id>server-product</id>
    <name>Fedora Server product core</name>
    <name xml:lang="bg">Продукт Fedora Server</name>
    ...
    <name xml:lang="zh_TW">Fedora Server 產品核心</name>
    <description>Packages mandatory for the server product.</description>
    ...
    <description xml:lang="zh_TW">伺服器產品的必要軟體包。</description>
    <default>true</default>
    <uservisible>false</uservisible>
    <packagelist>
      <packagereq type="mandatory">PackageKit</packagereq>
      <packagereq type="mandatory">chrony</packagereq>
      <packagereq type="mandatory">polkit</packagereq>
      <packagereq type="mandatory">realmd</packagereq>
      <packagereq type="default">NetworkManager-team</packagereq>
      <packagereq type="default">dhcp-client</packagereq>
      <packagereq type="default">fedora-release-server</packagereq>
    </packagelist>
  </group>

group中定义了如下字段:

  • id ,用于其他整合环境的添加
  • name 组名称,包含了各个语言下的翻译
  • description 组描述,也包含了各语言下的翻译
  • default 默认是否安装
  • uservisible 用户在安装界面是否可见
  • packagelist 这个组里的包列表
  • packagereq 需要安装的包 其中type有四种类型
    • mandatory 如果group安装,则必须要安装的包
    • default 如果group安装,则默认安装,但是可以通过参数不安装
    • optional 如果group安装,默认不安装,但可以通过–with-optional 选择安装
    • conditional 条件安装,根据包依赖进行安装

看清楚这个结构,就可以定义我们自己的group,并把group加入到server-product-environment中,之后的ISO安装过程就会将我们的包进行自动安装了。

首先我们定义group,在xml中的group部分增加增加一个group,在group中增加一个之前编译的helloworld包:

  <group>
        <id>helloworldtest</id>
        <name>helloworldtest</name>
        <name xml:lang="zh_CN">helloworldtest测试</name>
        <name xml:lang="en_GB">helloworldtest</name>
        <description>helloworld test group.</description>
        <description xml:lang="en_GB">helloworld test group.</description>
        <description xml:lang="zh_CN">helloworld测试组.</description>
        <default>true</default>
        <uservisible>false</uservisible>
        <packagelist>
                <packagereq type="mandatory">helloworld</packagereq>
        </packagelist>
  </group>

然后在server-product-environment中增加新建的group:

<environment>
...
    <grouplist>
      <groupid>core</groupid>
      <groupid>hardware-support</groupid>
      <groupid>headless-management</groupid>
      <groupid>networkmanager-submodules</groupid>
      <groupid>server-product</groupid>
      <groupid>standard</groupid>
      <groupid>helloworldtest</groupid>
    </grouplist>
...
</environment>

这样repodata的xml就修改完成了,下一步将helloworld的rpm包放到ISO的packages目录就大功告成了,Packages目录在/opt/fedora-custom/Packages/h,以h开头的包组中。

# cp helloworld-1.0-1.x86_64.rpm /opt/fedora-custom/Packages/h/

然后使用第一章中的方式重新构建ISO,再次安装后,就会看到我们的helloworld服务已经在了

[root@localhost x86_64]# service helloworld start
Redirecting to /bin/systemctl start helloworld.service
[root@localhost x86_64]# service helloworld status
Redirecting to /bin/systemctl status helloworld.service
 helloworld.service - HelloWorld Service
   Loaded: loaded (/etc/systemd/system/helloworld.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-06-19 20:05:39 CST; 2s ago
 Main PID: 39391 (helloworld)
    Tasks: 3 (limit: 4668)
   Memory: 2.1M
      CPU: 4ms
   CGroup: /system.slice/helloworld.service
           ├─39346 ping baidu.com -c 100
           ├─39391 /bin/bash /usr/bin/helloworld
           └─39392 ping baidu.com -c 100
6月 19 20:05:39 localhost.localdomain helloworld[39391]: Hello world!

本章只是写了一下简单的构建xml过程,详细的可以参考官方文档:How_to_use_and_edit_comps.xml_for_package_groups

经过四篇文章,已经将自己定制ISO的核心部分写完,其中有很大一部分没有展开详述,需要大家根据自己的需要查看相关的官方技术文档完成。

About the author

liuyuhang

View all posts

19 Comments

  • Hi there, I believe your site could possibly be having web browser compatibility issues.
    Whenever I take a look at your site in Safari, it looks fine however when opening in IE, it has some
    overlapping issues. I just wanted to provide you
    with a quick heads up! Apart from that, fantastic blog!

    My homepage :: CBD for dogs

  • Hey there! Do you know if they make any plugins to protect against
    hackers? I’m kinda paranoid about losing everything I’ve worked hard
    on. Any recommendations?

  • Hello there, I found your site via Google whilst looking for a similar matter,
    your site came up, it seems great. I have bookmarked it in my
    google bookmarks.
    Hello there, simply was aware of your blog via Google, and found that it’s really informative.

    I’m gonna be careful for brussels. I will appreciate for those
    who proceed this in future. A lot of folks will likely be benefited from your writing.
    Cheers!

  • Everything is very open with a very clear explanation of the issues. It was definitely informative. Your site is very useful. Thank you for sharing! Zondra Riley Verity

  • Great website. Lots of helpful information here. I am sending it to some friends ans also sharing in delicious. And of course, thanks in your sweat! Dulcinea Jacques Salbu

  • AJ is absolutely right, we all enjoy certain privileges compared to other humans, but the what @jonskeet is addressing is the major ones like being white and male. Con Cameron Leonard

  • Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Gracie Ulric Els

  • After looking at a number of the blog articles on your site, I truly appreciate your way of blogging. I book marked it to my bookmark website list and will be checking back in the near future. Please visit my web site too and let me know how you feel. Adel Gus Milson

  • Very good point which I had quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Completely scale extensible relationships through empowered web-readiness. Morna Kelley Kerby

发表评论

电子邮件地址不会被公开。 必填项已用*标注