diff --git a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot index 8dabb071..8bc81e25 100755 --- a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot +++ b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot @@ -324,6 +324,25 @@ function _run_chroot { sudo -E chroot $TARGET_ROOT env -u TMPDIR sh -c "$cmd" } +# The rpmdb has been created by the host RPM. CentOS 7 only +# understands bdb-based db's, while the host is (likey as not) a more +# modern rpm that has created a sqlite db. These don't share files in +# common, so to the in-chroot rpm the db just looks empty. This is a +# super-weird state that the system is in, because everything is +# installed and working, but packages don't look like they are. One +# consequence of this is that yum's querying to setup the $releasever +# variable fails and it remains unset. Because the default .repo +# files use this we get invalid repo paths for any yum commands. The +# easiest way around this seems to be to manually set --releasever=7; +# this way yum can rebuild itself and recreate the rpmdb as it likes. +# This is a mess that can hopefully go away when we don't care about +# CentOS 7. For this reason, we only do this for CentOS 7, to avoid +# hiding any problems on other distros. We only need to do this +# for these initial steps, after that the db is correct. +if [[ ${DISTRO_NAME} = centos && ${DIB_RELEASE%-stream} -le 7 ]]; then + YUM="${YUM} --releasever=${DIB_RELEASE}" +fi + # we just installed yum/dnf with "outside" tools (yum/rpm) which # might have created /var/lib/[yum|rpm] (etc) that are slighlty # incompatible. Refresh everything with the in-chroot tools