Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5122900
  • 博文数量: 1614
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 14980
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
文章分类

全部博文(1614)

文章存档

2020年(30)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(229)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2011-08-26 15:28:06

Mock – Chroot Build Tools
Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.
http://fedoraproject.org/wiki/Projects/Mock 更多信息请查看Wiki
一.安装
最简单的安装方法(yum ) 因为是Fedora发行的包,yum中不一定有.如果没有请安装epel或rpmforge源.安装方法不介绍
yum -y install mock

mock 为了安全,不能使用root用户,所以添加一个新的用户,并指定组为mock
useradd bulid -G mock
查看用户组
cat /etc/group|grep mock
mock:x:489:bulid
切换到bulid 用户.开始我们的打包操作
su bulid

2.应用
先介绍一个配置文件

初始化chroot配置环境
mock –init -r fedora-10-i386
提示如下:——->原因是没有指定路径


[bulid@builder mock]$ /usr/bin/mock –init -r fedora-15-i386
INFO: mock.py version 1.1.9 starting…
State Changed: init plugins
INFO: selinux disabled
State Changed: start
State Changed: lock buildroot
State Changed: clean
INFO: chroot (/var/lib/mock/fedora-15-i386) unlocked and deleted
State Changed: unlock buildroot
State Changed: init
State Changed: lock buildroot
Mock Version: 1.1.9
INFO: Mock Version: 1.1.9
INFO: enabled root cache
INFO: enabled yum cache
State Changed: cleaning yum metadata
INFO: enabled ccache
State Changed: running yum
State Changed: creating cache
State Changed: unlock buildroot

完成初始化.

/usr/bin/mock –shell -r fedora-15-i386
mock-chroot> chmod u+s bin/bash
/var/lib/mock/fedora-15-i386/root/bin/bash -p
cat /etc/shadow

命名如下:
Usage:
usage:
mock [options] {–init|–clean|–scrub=[all,chroot,cache,root-cache,c-cache,yum-cache]}
mock [options] [--rebuild] /path/to/srpm(s)
mock [options] –buildsrpm {–spec /path/to/spec –sources /path/to/src|–scm-enable [--scm-option key=value]}
mock [options] {–shell|–chroot}
mock [options] –installdeps {SRPM|RPM}
mock [options] –install PACKAGE
mock [options] –copyin path [..path] destination
mock [options] –copyout path [..path] destination
mock [options] –scm-enable [--scm-option key=value]

Options:
–version show program’s version number and exit
-h, –help show this help message and exit
–rebuild rebuild the specified SRPM(s)
–buildsrpm Build a SRPM from spec (–spec …) and sources
(–sources …) or from SCM
–shell run the specified command interactively within the
chroot. Default command: /bin/sh
–chroot run the specified command noninteractively within the
chroot.
–clean completely remove the specified chroot
–scrub=[all|chroot|cache|root-cache|c-cache|yum-cache]
completely remove the specified chroot or cache dir or
all of the chroot and cache
–init initialize the chroot, do not build anything
–installdeps install build dependencies for a specified SRPM
–install install packages using yum
–update update installed packages using yum
–orphanskill Kill all processes using specified buildroot.
–copyin Copy file(s) into the specified chroot
–copyout Copy file(s) from the specified chroot
-r CHROOT, –root=CHROOT
chroot name/config file name default: default
–offline activate ‘offline’ mode.
–no-clean do not clean chroot before building
–cleanup-after Clean chroot after building. Use with –resultdir.
Only active for ‘rebuild’.
–no-cleanup-after Dont clean chroot after building. If automatic cleanup
is enabled, use this to disable.
–arch=ARCH Sets kernel personality().
–target=RPMBUILD_ARCH
passed to rpmbuild as –target
-D ‘MACRO EXPR’, –define=’MACRO EXPR’
define an rpm macro (may be used more than once)
–with=option enable configure option for build (may be used more
than once)
–without=option disable configure option for build (may be used more
than once)
–resultdir=RESULTDIR
path for resulting files to be put
–uniqueext=UNIQUEEXT
Arbitrary, unique extension to append to buildroot
directory name
–configdir=CONFIGDIR
Change where config files are found
–rpmbuild_timeout=RPMBUILD_TIMEOUT
Fail build if rpmbuild takes longer than ‘timeout’
seconds
–unpriv Drop privileges before running command when using
–chroot
–cwd=DIR Change to the specified directory (relative to the
chroot) before running command when using –chroot
–spec=SPEC Specifies spec file to use to build an SRPM (used only
with –buildsrpm)
–sources=SOURCES Specifies sources (either a single file or a directory
of files)to use to build an SRPM (used only with
–buildsrpm)
-v, –verbose verbose build
-q, –quiet quiet build
–trace Enable internal mock tracing output.
–enable-plugin=ENABLED_PLUGINS
Enable plugin. Currently-available plugins: ['tmpfs',
'root_cache', 'yum_cache', 'bind_mount', 'ccache',
'selinux', 'scm']
–disable-plugin=DISABLED_PLUGINS
Disable plugin. Currently-available plugins: ['tmpfs',
'root_cache', 'yum_cache', 'bind_mount', 'ccache',
'selinux', 'scm']
–print-root-path print path to chroot root
–scm-enable build from SCM repository
–scm-option=SCM_OPTS
define an SCM option (may be used more than once)

把src.rpm 编译为指定平台
/usr/bin/mock -v -r epel-5-x86_64 –no-clean mtr-0.71-3.1.src.rpm
安装指定的包到chroot环境中
/usr/bin/mock –install -r epel-5-x86_64 /var/lib/mock/epel-5-x86_64/result/wget-1.11.4-2.el5.1.x8
6_64.rpm

 

转:http://www.selfcai.com.cn/?p=1429

阅读(793) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~