1. 安装 Mock 工具
确保你的系统已安装 mock:
sudo yum install -y mock
sudo usermod -a -G mock $(whoami) # 将当前用户加入 mock 组
newgrp mock # 刷新用户组(或重新登录)
2. 配置 Mock 使用 yuhua仓库
创建 yuhua的 Mock 配置文件
1.新建文件 /etc/mock/yuhua-30-x86_64.cfg,内容如下:
[root@localhost ~]# cat /etc/mock/yuhua-30-x86_64.cfg
include('templates/yuhua-30.tpl')
config_opts['root'] = 'yuhua-30-x86_64'
config_opts['description'] = 'YuHuaXinKe Linux 30'
config_opts['target_arch'] = 'x86_64'
config_opts['legal_host_arches'] = ('x86_64',)
[root@localhost ~]#
2.新建文件 /etc/mock/templates/yuhua-30.tpl,内容如下:
[root@localhost ~]# cd /etc/mock/templates/
[root@localhost templates]# vi yuhua-30.tpl
[root@localhost templates]# cat yuhua-30.tpl
config_opts['chroot_setup_cmd'] = 'install tar gcc-c++ anolis-release which xz sed make bzip2 gzip gcc coreutils unzip diffutils cpio bash gawk rpm-build info patch util-linux findutils grep'
config_opts['dist'] = 'yh30' # only useful for --resultdir variable subst
config_opts['releasever'] = '30'
config_opts['package_manager'] = 'dnf'
config_opts['description'] = 'YuHuaXinKe 30'
config_opts['extra_chroot_dirs'] = [ '/run/lock', ]
config_opts['macros']['%dist'] = '.yh30' # 覆盖 %dist 宏
config_opts['macros']['%_vendor'] = 'yuhua' # 覆盖供应商标识
#config_opts['bootstrap_image'] = 'docker.io/openanolis/anolisos:8'
config_opts['dnf.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
syslog_ident=mock
syslog_device=
mdpolicy=group:primary
best=1
install_weak_deps=0
protected_packages=
module_platform_id=platform:yh30
user_agent={{ user_agent }}_=_=
[BaseOS]
name=AnolisOS-$releasever - BaseOS
baseurl=https://mirrors.openanolis.cn/anolis/23/os/x86_64/os/
enabled=1
#gpgkey=file:///usr/share/distribution-gpg-keys/anolis/RPM-GPG-KEY-ANOLIS
#gpgcheck=1
"""
3. 初始化 Mock 构建环境
mock -r yuhua-30-x86_64 --init
- 下载并构建 SRPM
1.下载 zip 的 SRPM
wget https://mirrors.openanolis.cn/anolis/23/os/source/Packages/zip-3.0-24.an23.src.rpm
2.二构建 RPM
mock -r yuhua-30-x86_64 --rebuild zip-3.0-24.an23.src.rpm
4.获取构建结果
构建成功后,RPM 包会保存在:
[root@localhost result]# ll
总用量 2108
-rw-rw-r-- 1 root mock 44275 3月 26 17:41 build.log
-rw-rw-r-- 1 root mock 1933 3月 26 17:41 hw_info.log
-rw-rw-r-- 1 root mock 20108 3月 26 17:41 installed_pkgs.log
-rw-rw-r-- 1 root mock 115722 3月 26 17:41 root.log
-rw-rw-r-- 1 root mock 1348 3月 26 17:41 state.log
-rw-r--r-- 1 root mock 1131399 3月 26 17:41 zip-3.0-24.yh30.src.rpm
-rw-r--r-- 1 root mock 186848 3月 26 17:41 zip-3.0-24.yh30.x86_64.rpm
-rw-r--r-- 1 root mock 334241 3月 26 17:41 zip-debuginfo-3.0-24.yh30.x86_64.rpm
-rw-r--r-- 1 root mock 220354 3月 26 17:41 zip-debugsource-3.0-24.yh30.x86_64.rpm
-rw-r--r-- 1 root mock 85808 3月 26 17:41 zip-doc-3.0-24.yh30.noarch.rpm
[root@localhost result]# pwd
/var/lib/mock/yuhua-30-x86_64/result
[root@localhost result]#
5.其他
mock -r yuhua-30-x86_64 --scrub=all # 彻底清理旧环境
# 进入 chroot 环境调试
mock -r anolis-23-x86_64 --shell