How do you build chroot jails with dnf?

As you found out, with dnf you need to specify the --releaserver argument.

In addition, if you want to use repositories specific to the chroot, then you'll need a bit more work.

I find the easiest solution is to create your own dnf.conf file inside the chroot, put the repository configurations inside, and then use it.

For example, let's say you want to create a Fedora 24 chroot in the $(pwd)/mychroot folder, using only packages from the fedora and rpmfusion-free repositories.

You would create the mychroot/etc/dnf/dnf.conf file, with the following content:

[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
reposdir=

[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

[rpmfusion-free]
name=RPM Fusion for Fedora $releasever - Free
metalink=https://mirrors.rpmfusion.org/metalink?repo=free-fedora-$releasever&arch=$basearch
enabled=1
metadata_expire=14d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-free-fedora-$releasever

(look at the /etc/yum.repos.d/*.repo files on your system and just copy-paste)

The important part is this line in the main section, which tells dnf not to search for repositories in any directory, but only in the main configuration file, which will make it ignore your system repositories:

reposdir=

Finally, you can run dnf:

# dnf -c $(pwd)/mychroot/etc/dnf/dnf.conf install --installroot=$(pwd)/mychroot --releasever=24 gstreamer1-libav

Since 2016-10 or so Dnf has changed its defaults. That means when executing a command like

# dnf --installroot=/mnt/new-root --releasever=26 \
    group install custom-environment

Dnf now looks first for etc/dnf/dnf.conf and etc/yum.repo.d under /mnt/new-root, by default.

This default can be changed via specifying:

 --setopt=reposdir=/other/path --config /other/location/dnf.conf

Tags:

Fedora

Dnf