Jun's Blog

Output, activities, memo and etc.

How to use host os directory from chroot (mock) environment.

On Fedora Project's work, a chroot environment is usually used to build and test. The environment is called "mock" environment.

As I often forget the way, I save it to this page.

There are 2 ways.

1. Using mount --bind

Use below command.

$ mount --bind <old_dir> <new_dir>

The /path/to/root/mnt directory is /mnt in the mock (chroot) environment.

Create a directory to mount a directory.

$ sudo mkdir /var/lib/mock/fedora-rawhide-x86_64/root/mnt/foo

Mounting the directory, it can be referred in the mock (chroot) environment.

$ cd /path/to/foo
$ sudo mount --bind . /var/lib/mock/fedora-rawhide-x86_64/mnt/foo

2. Using mock's mount plugin

2nd way is limited to the mock command. But it's easier way.

The document is here [1].

You can set it for example in $HOME/.config/mock.cfg. This directory is auto-mounted when doing login to the mock environment.

config_opts['plugin_conf']['bind_mount_enable'] = True
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('/host_os/path/to/foo', '/mnt/foo' ))

That's all.

References