7

Back in the day I used to build chroot jails using yum. It was simple, easy, and let me do things that weren't really available at the time (build packages for multiple distros on platforms like ia64 and ppc using the same infrastructure).

Fast forward 5 years, I'd like to build a simple chroot jail on Fedora 23. However, dnf doesn't make this easy. I used to be able to just create an /etc/yum.repo.d/ file in the jail dir and call yum --installroot. Unfortunately dnf is still reading the local repo and not the one created in the chroot jail.

Is it possible to have dnf use conf files that aren't /etc/dnf/dnf.conf or in /etc/yum.repos.d/?

  • So it turns out that adding --releasever=23 made the install work with my local repos, but it still doesn't let me reference a different repo that is not part of my install. This gets me what I want right now, but doesn't solve the root problem – Joe Mar 2 '16 at 19:55
3

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
  • You can show it now! – Demi Oct 10 '16 at 21:21
  • And I finally did. Sorry it took me so long. :-/ – Mathieu Bridon Jun 17 '17 at 7:30
  • I tried that, but all I get is AttributeError: 'NoneType' object has no attribute 'lstrip' – panzi Sep 11 '17 at 16:27
3

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
0

dnf allows setting any config option on the command line, and this includes reposdir. It should be possible to use a command like this:

ROOT=/path/to/my/chroot
dnf --installroot="$ROOT" \
    -c "$ROOT"/etc/dnf/dnf.conf \
    --setopt=reposdir="$ROOT"/etc/yum.repos.d \
    install ...
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Thomas Jun 17 '17 at 11:22
  • @Thomas do you prefer this phrasing? – sourcejedi Jun 17 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.