mock - Man Page

build SRPMs in a chroot

Syntax

mock  [options] --rebuild SRPM [SRPM...]

mock  [options] --chain SRPM [SRPM...]

mock  [options] --buildsrpm {--spec spec --sources src --symlink-dereference | --scm-enable}

mock  [options] --chroot <cmd>

mock  [options] {--init|clean|shell}

mock  [options] --installdeps {SRPM|RPM|SPEC}

mock  [options] -i, --install PACKAGE [PACKAGE...]

mock  [options] --update [PACKAGE...]

mock  [options] --remove PACKAGE [PACKAGE...]

mock  [options] --orphanskill

mock  [options] -p, --print-root-path

mock  [options] --copyin path [path...] destination

mock  [options] --copyout path [path...] destination

mock  [options] --scm-enable [--scm-option key=value ...]

mock  [options] -l, --list-snapshots

mock  [options] --snapshot [snapshot-name]

mock  [options] --rollback-to [snapshot-name]

mock  [options] --remove-snapshot [snapshot-name]

mock  [options] --umount

mock  [options] --pm-cmd [arguments ...]

mock  [options] --yum-cmd [arguments ...]

mock  [options] --dnf-cmd [arguments ...]

mock  [options] --calculate-build-dependencies SRPM

mock  [options] --hermetic-build LOCKFILE REPO SRPM

mock  [options] {--scrub=TYPE,--scrub-all-chroots}

Description

Mock is a simple program that will build source RPMs inside a chroot. It doesn't do anything fancy other than populating a chroot with the contents specified by a configuration file, then build any input SRPM(s) in that chroot.

The content of a chroot is specified by the configuration specified with the -r option. The default configuration file is /etc/mock/default.cfg, which is usually a symlink to one of the installed configurations.

There is a site-wide configuration file, /etc/mock/site-defaults.cfg, which can be used to specify site-wide options. The shipped version of this file has no active options, but does have a list of all of the configuration options examples of how to set them, and their default values.

To change configuration only for the current user please use ~/.config/mock.cfg configuration file.

For backward compatibility, old-style commands, ("rebuild", "init", "clean", etc.) without leading '--' are still accepted, but are deprecated. See Commands section, below, for the detailed listing of all commands.

To use mock, a user should become a member of the mock group by adding their username to the mock line in /etc/group. This can be done with the following command:

       sudo /usr/sbin/usermod -a -G mock $USER

Note that mock is not intended to be run directly as root.

Warning: Mock is running some parts of code with root privileges. There are known ways to get root access once a user is in mock group (and once he is able to run mock). This is possible when a user abuses the mock configuration options. Please do not add anyone who is not trustworthy to the mock group!

Commands

--buildsrpm

Build the specified SRPM either from a spec file and source file/directory or SCM. The chroot (including the results directory) is cleaned first, unless --no-clean is specified.

--calculate-build-dependencies SRPM

Evaluate and install all the SRPM (= file name, path on your system) build dependencies, including dynamic dependencies in %generate_buildrequires. This is similar to the --installdeps option which only installs the static BuildRequires.

Build chroot-native *.src.rpm and *.nosrc.rpm files (the later only when %generate_buildrequires is in use!).  The *.src.rpm records the corresponding static list of build dependencies (= BuildRequires).  The *.nosrc.rpm records a full list of build dependencies (static + dynamic). Test with rpm -qpR [*.src.rpm|*.nosrc.rpm].

Additionally, provide a buildroot_lock.json file; this records the metadata needed for a hermetic build (see also --hermetic-build).

--chain

When passing more than one SRPM, it will try to build failed builds if at least one subsequent SRPM succeed. This mimic the behaviour of deprecated mockchain.

--clean

Purge the chroot tree.

--copyin

Copies the source paths (files or directory trees) into the chroot at the specified destination path.

--copyout

Copies the source paths (files or directory trees) from the chroot to the specified destination path.

--chroot [--] COMMAND [ARGS...]

Run the specified command non-interactively within the chroot (no --clean is performed).

This mode is similar to shell mode, except that the output is logged and the COMMAND and ARGS arguments are not shell expanded in chroot when the variant with CMD+ARGS is used, see the difference in mock output:
   mock --quiet --chroot -- echo '*'
   *
   mock --quiet --chroot -- 'echo *'
   bin boot builddir dev etc home lib lib64 media mnt opt ... See also --shell.

--debug-config

Print all options in config_opts.

--debug-config-expanded

Prints all options in config_opts with jinja template values already expanded.

--dnf-cmd

Execute following arguments with DNF with installroot set to the chroot path. DNF must be installed on the system. It will use the binary which is specified in 'dnf_command' option in site-defaults.cfg config, which by default is /usr/bin/dnf. This option will enforce --dnf.

--init

Initialize a chroot (clean, install chroot packages, etc.).

-i,  --install

Do a yum install PACKAGE inside the chroot. No 'clean' is performed.

--installdeps

Find out "static" deps for SRPM or RPM, and do a dnf install to put them into the buildroot.  No 'cleanup' is performed.

Dynamic build dependencies (%generate_buildrequires specfile section) are not installed, see --calculate-build-dependencies.

--hermetic-build LOCKFILE REPO SRPM

Perform a hermetic RPM build (i.e., an offline build without the need to access the Internet at all) from the given SRPM (= file name, path on your system).  After running Mock with the --calculate-build-dependencies option to generate the LOCKFILE file (typically named buildroot_lock.json in the result directory), and then running the mock-hermetic-repo(1) helper to generate REPO (a directory on the host that provides RPMs with metadata and a bootstrap image tarball), Mock has all the necessary information to build RPMs from the given SRPM fully offline.  More info in the feature page:

https://rpm-software-management.github.io/mock/feature-hermetic-builds

--list-chroots

List all available chroots names and their description - both system-wide and user ones.

-l,  --list-snapshots

List all existing snapshots of the chroot belonging to the current configuration. Current base snapshot is marked with an asterisk (*)

--mount

Mount all everything mounted in the chroot path including the root itself that might have been an LVM volume, TMPFS or overlayfs.

--orphanskill

No-op mode that simply checks that no stray processes are running in the chroot. Kills any processes that it finds using the specified root.

--pm-cmd

Execute following arguments with the current package manager with installroot set to the chroot path.

-p,  --print-root-path

Prints a path to the currently used chroot directory.

--rebuild

If no command is specified, rebuild is assumed. Rebuild the specified SRPM(s). The chroot (including the results directory) is cleaned first, unless --no-clean is specified.

--remove

Do a yum remove PACKAGE inside the chroot. No 'clean' is performed.

--remove-snapshot

Remove given snapshot freeing the space it occupied. This action cannot be undone. This feature is available only when lvm_root or overlayfs plugin is installed and enabled.

--rollback-to

Return chroot to the state in the specified snapshot and set it as the current base to which clean actions will return. It won't delete nor modify the snapshot that was set as base previously. This feature is available only when the lvm_root or overlayfs plugin is installed and enabled.

--scm-enable

Enable building from an SCM (CVS/Git/SVN/DistGit). The SCM repository must be configured in site-defaults.cfg before SCM checkouts are possible. SCM package and branch can be defined with --scm-option arguments, see site-defaults.cfg for more information.

--scrub=TYPE

Completely remove the specified chroot or cache dir or all of the chroot and cache.  TYPE is one of all, chroot, bootstrap, cache, root-cache, c-cache, yum-cache or dnf-cache. In fact, dnf-cache is just alias for yum-cache, and both remove Dnf and Yum cache.

--scrub-all-chroots

Run mock --scrub=all -r <chroot> for all chroots that appear to have been used previously (some leftovers in /var/lib/mock or /var/cache/mock were detected by the heuristic).  This option cannot clean leftovers for chroots with configurations in non-standard locations, or if the configuration is no longer available.  It also attempts to detect previous use of --uniqueext and adjusts the corresponding --scrub=all call accordingly.

--shell [--] [COMMAND [ARGS...]]

Shell mode.  Run the specified command interactively within the chroot (no --clean is performed).  If no command specified, /bin/sh is run and prompt is provided.

Be aware that mock first parses all the command-line arguments, so the ARGS could be mistakenly evaluated as mock's options.  Thats why you almost always want to use the -- separator.

This mode does not produce logs (nothing is appended to root.log in --resultdir).

The COMMAND and ARGS are shell expanded using the shell in chroot (unless they mistakenly expand in host's terminal shell).  E.g. the following two commands are equivalent:
   mock --shell -- ls -l '*'
   mock --shell 'ls -l *'
But the following is something entierly different:
   mock --shell -- ls -l *

--sources=SOURCES

Specifies sources (either a single file or a directory of files) to use to build an SRPM (used only with --buildsrpm).

--spec=SPEC

Specifies spec file to use to build an SRPM.

--update [PACKAGE...]

Do a package update inside the chroot. The package list is optional, if omitted, all packages will be updated. No 'clean' is performed.

--snapshot

Make a snapshot of the current state of the chroot. That snapshot will be set as the current base to which --clean and implicit clean happening during rebuild command will return. This feature is available only when the lvm_root or overlayfs plugin is installed and enabled.

--umount

Umount all everything mounted in the chroot path including the root itself that might have been an LVM volume, TMPFS or overalyfs.

--yum-cmd

Execute following arguments with YUM with installroot set to the chroot path. Yum must be installed on the system. It will use the binary which is specified in 'yum_command' option in site-defaults.cfg config, which by default is /usr/bin/yum. Note that in config files for Fedora 22+ this value is overwritten in chroot config to default to /usr/bin/yum-deprecated. This option will enforce --yum.

Note: While you can specify more commands on a command line, only one can be executed. The last command will win.

Options

-a,  --addrepo=REPO

Add a repo baseurl to the DNF/YUM configuration for both the build chroot and the bootstrap chroot.  This option can be specified multiple times, allowing you to reference multiple repositories in addition to the default repository set.

--arch=ARCH

Calls the Linux personality() syscall to tell the kernel to emulate a secondary architecture. For example, building i386 packages on an x86_64 buildhost.

--additional-package=PACKAGE

An additional package (on top of in-package specified BuildRequires) to be installed into the buildroot before the build is done.  Can be specified multiple times.  Works only with --rebuild.

--forcearch=ARCH

Pass --forcearch to DNF. This will enable to install packages for different architecture. Works only for DNF and you have to have package qemu-user-static installed.

--cache-alterations

Rebuild the root cache after making alterations to the chroot (i.e. --install). This option is useful only when using tmpfs plugin.

--cleanup-after

Clean chroot after building. Use with --resultdir. Only active for '--rebuild'.

--configdir=CONFIGDIR

Change directory where config files are found

--config-opts=KEY=VALUE

Override configuration option. Can be used multiple times.

When used multiple times for the same key, it will create an array (if you need to specify an array value with just a sigle item, e.g. config_opts["foo"] = ["baz"], specify it as array of two items with the empty string as the first item, e.g.  --config-opts=foo= --config-opts=foo=baz).

This is evaluated after parsing configs, so command line options override previously defined options.

--continue

If a pkg fails to build, continue to the next one, default is to stop.

Works only with --chain.

--cwd=DIR

Change to the specified directory (relative to the chroot) before running command when using --chroot or --shell.

-D "MACRO EXPR", --define="MACRO EXPR"

Specify macro definitions used for the build.  This option may be used multiple times, just as the rpmbuild --define option can be.  For example:

--define "with_extra_cheese 1" --define="packager Monkey"

--disable-plugin=PLUGIN

Disable the specified plugin.  This option may be used multiple times.

--disablerepo=REPO

Pass --disablerepo option to package manager to disable a repository. It can be specified multiple times.

--dnf

Use DNF as the current package manager. You should have DNF (and dnf-plugins-core) installed on your system. This is the default.

--enable-plugin=PLUGIN

Enable the specified plugin.  This option may be used multiple times.

--enablerepo=REPO

Pass --enablerepo option to package manager to enable a repository. It can be specified multiple times.

--enable-network

Enable networking. If you want to have reproducible builds then your builds should run without a network. This option overrides config_opts['rpmbuild_networking'] and config_opts['use_host_resolv'], setting both True.

--isolation={auto|nspawn|simple}

What should be used for isolation of chroot.  The simple method uses chroot() call.  The nspawn  method utilizes systemd-nspawn(1) and runs the commands inside container.  The auto tries to use nspawn, and falls back to simple if system-nspawn can not be used (e.g. if mock is run in container).  The default is auto.

--localrepo=REPO

Set the path to put the results/repo in (works only in --chain mode). Will make a tempdir if not set.

-c

If package fails, continue to the next one (works only in --chain mode).

-h,  --help

Show usage information and exit.

--macro-file=FILE

Use pre-defined rpm macro file. Macros passed to '--define' override macros of the same name from FILE.

--new-chroot

Deprecated. Use --isolation=nspawn.

-n,  --no-clean

Do not clean chroot before building a package.

--nocheck

Pass --nocheck to rpmbuild to skip 'make check' tests.

-N,  --no-cleanup-after

Don't clean chroot after building. If automatic cleanup is enabled, use this to disable.

--offline

Run in an 'offline' mode where we tell 'yum' to run completely from the local cache. Also, disables cache expiry for the mock yum cache.

--old-chroot

Deprecated. Use --isolation=simple.

--plugin-option PLUGIN:KEY=VALUE

Set plugin specific parameter. This option may be used multiple times. Examples:

--plugin-option=root_cache:age_check=False

--plugin-option=mount:dirs=("/dev/device", "/mount/path/in/chroot/", "vfstype", "mount_options")

--postinstall

Try to install built packages in the same buildroot right after the build.

-q,  --quiet

Be quiet.

--recurse

Build all pkgs, record the failures and try to rebuild them again and again until everything gets built (or until the set of pkgs failing to build are the same over) sets --continue.  Works only with --chain.

-r CONFIG, --root=CONFIG

Uses specified chroot configuration as defined in ~/.config/mock/<CONFIG>.cfg or /etc/mock/<CONFIG>.cfg. Optionally if CONFIG ends in '.cfg', it is interpreted as full path to config file. If none specified, uses the chroot config linked to by /etc/mock/default.cfg.

--resultdir=RESULTDIR

Change directory where resulting files (RPMs and build logs) are written. Resultdir can contain python-string substitutions for any variable in the chroot config. For example:

--resultdir=./my/"{{dist}}"/"{{target_arch}}"/

This option enables automatic cleanup, this can be changed in config file (by cleanup_on_success, cleanup_on_failure configuration options) or overridden by --no-cleanup-after/--cleanup-after arguments.

Note that this option does not have an effect for --chain command. You can use --localrepo instead.

--rootdir=ROOTDIR

The path for where the chroot should be built. By default it is created in /var/lib/mock/<CONFIG>/root/.

--rpmbuild-opts=OPTIONS

Pass additional options to rpmbuild. To pass more options, put them in quotes.

--rpmbuild_timeout=SECONDS

Fail build if rpmbuild takes longer than 'timeout' seconds

--scm-option=OPTIONS

define an SCM option (may be used more than once).

--short-circuit=STAGE

Use rpmbuild's short-circuit mechanism to skip already executed stages of the build. It doesn't produce RPMs, and it's useful only for debugging packaging. Implies --no-clean. STAGE specifies which stage will be executed as the first. Available values: prep, build, install, binary.

--symlink-dereference

Follow symlinks in sources (used only with --buildsrpm).

--target=ARCH

This argument is passed to rpmbuild to specify the target arch to build. It defaults to whatever is specified for --arch, or whatever is specified in the config file as config_opts['target_arch'].

--tmp_prefix=PREFIX

Tmp dir prefix - will default to username-pid if not specified.

--trace

Enables verbose tracing of function enter/exit with function arguments and return codes. Useful for debugging mock itself.

--uniqueext=text

Arbitrary, unique extension to append to chroot directory name

--unpriv

Drop privileges before running command when using --chroot

-v,  --verbose

Output verbose progress information.

--version

Show version number and exit.

--with=OPTION

Enable configure OPTION for the build.  This option may be used multiple times.  For example:

--with=extra_cheese

--without=OPTION

Disable configure OPTION for the build.  This option may be used multiple times.  For example:

--without=anchovies

--yum

Use yum as the current package manager.

--bootstrap-chroot

build in two stages, using chroot rpm for creating the build chroot

--no-bootstrap-chroot

build in a single stage, using system rpm for creating the build chroot

--use-bootstrap-image

Instead of creating a bootstrap chroot from scrath, use podman image specified in config_opts['bootstrap_image'], extract it, and use it as a cache for the bootstrap chroot. This is useful when host rpm version is not compatible with the target system, or when using mock on non-RPM distributions.  This option turns --bootstrap-chroot on.

--no-bootstrap-image

don't create bootstrap chroot from container image

Files

/etc/mock/ - default configuration directory

/var/lib/mock - directory where chroots and results are created. You should not put there your input files.

Examples

To rebuild test.src.rpm using the Fedora 14 configuration for x86_64

mock -r fedora-14-x86_64 --rebuild /path/to/test.src.rpm

Note that the available configurations are found in the /etc/mock directory with the extension .cfg. To specify a configuration use the filename without the trailing .cfg extension.

To place the output RPMs and logs in a specified location.

mock -r fedora-14-i386 --resultdir=./my-results /path/to/your.src.rpm

To build a package from the default SCM repository configured in site-defaults.cfg use the following arguments.

mock -r fedora-14-i386 --scm-enable --scm-option package=pkg

To execute a command inside of chroot.

mock -r fedora-21-x86_64 --chroot -- rpm --eval %dist

mock -r fedora-21-x86_64 --chroot 'rpm --eval %dist'

To build rawhide package using yum:

mock -r fedora-rawhide-x86_64 --yum --rebuild your.src.rpm

Query rpm database inside chroot using Yum:

mock -r fedora-rawhide-x86_64 --yum-cmd whatprovides foo

List package manager history using package manager which is configured in chroot config (can be either DNF or YUM):

mock -r fedora-rawhide-x86_64 --pm-cmd history list

Bugs

To report an issue with Mock, go to:

Search through the list of existing issues.  If there is a similar issue to the one you are seeing, add your information in new comments. If not, press New issue and fill in the form.

Authors

Michael Brown <mebrown@michaels-house.net>

Clark Williams <williams@redhat.com>

Seth Vidal

and a cast of...tens

See Also

rpmbuild(8), yum(8), dnf(8), https://rpm-software-management.github.io/mock/

Referenced By

ddiskit(1), rebase-helper(1).

5.9" Seth Vidal"