From 3f3850aa0f6fc0e3e10a7c1e35ec67dbeb76d532 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 23 Oct 2015 15:42:00 +1100 Subject: [PATCH] Fixup RPM db path when building Fedora on Ubuntu On Debian/Ubuntu installs of RPM, /usr/lib/rpm/macros sets %_dbpath %(echo $HOME/.rpmdb) which makes quite a bit of sense, because RPM is not the system packager and thus RPM is setup to install things into a hierarchy in the users homedir. However, this messes things up when building a Fedora chroot on an Ubuntu platform. We use RPM & yum from the base-system to bootstrap the Fedora chroot. While both obey --root flags, they still pick up the %_dbpath macro and so end up creating the RPM database in /home/user/.rpmdb After we have bootstrapped yum/dnf, we execute further installation commands from inside the chroot -- where we now have the Fedora version of /usr/lib/rpm/macros and hence have _dbpath set to /var/lib/rpm -- except there is no rpm database there. Should anyone be finding this in the future, the actual issue that appears is $ sudo chroot /opt/dib_tmp/image.b6B5S3f6/mnt dnf makecache Error: Failed to synchronize cache for repo 'fedora' from \ 'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=x86_64': \ Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink Note the issue there is that $releasever is not expanded, because the rpmdb where this info is kept is not populated. The trick is to make sure we override this value when using the host rpm/yum to setup the chroot. The bare rpm calls, which we use to install the repos, have a --dbpath argument where we can override this. yum does not however, so we override this in the global ~/.rpmmacros while we are installing the packaging tools and dependencies into the chroot. Copious comments are included, because this is super-confusing. Change-Id: I20801150ea02d1c64f118eb969fb2aec473476f7 --- elements/yum-minimal/root.d/08-yum-chroot | 32 +++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/elements/yum-minimal/root.d/08-yum-chroot b/elements/yum-minimal/root.d/08-yum-chroot index ee760baf..fd5f43df 100755 --- a/elements/yum-minimal/root.d/08-yum-chroot +++ b/elements/yum-minimal/root.d/08-yum-chroot @@ -41,6 +41,11 @@ trap "$EACTION" EXIT YUM_CACHE=$DIB_IMAGE_CACHE/yum mkdir -p $YUM_CACHE +# Note, on Debian/Ubuntu, %_dbpath is set in the RPM macros as +# ${HOME}/.rpmdb/ -- this makes sense as RPM isn't the system +# packager. This path is relative to the "--root" argument +_RPM="rpm --dbpath=/var/lib/rpm" + # install the [fedora|centos]-[release|repo] packages inside the # chroot, which are needed to bootstrap yum/dnf # @@ -67,7 +72,7 @@ function _install_repos { # --nodeps works around these wanting /bin/sh in some fedora # releases, see rhbz#1265873 - sudo rpm --root $TARGET_ROOT --nodeps -ivh $WORKING/*rpm + sudo $_RPM --root $TARGET_ROOT --nodeps -ivh $WORKING/*rpm } # _install_pkg_manager packages... @@ -82,12 +87,29 @@ function _install_pkg_manager { sudo sed -i "s,/etc/pki/rpm-gpg,$TARGET_ROOT/etc/pki/rpm-gpg,g" \ $TARGET_ROOT/etc/yum.repos.d/*repo - sudo -E yum -y \ + # See notes on $_RPM variable -- we need to override the + # $HOME-based dbpath set on debian/ubuntu here. Unfortunately, + # yum does not have a way to override rpm macros from the command + # line. So we modify the user's ~/.rpmmacros to set %_dbpath back + # to "/var/lib/rpm" (note, this is taken relative to the + # --installroot). + # + # Also note, we only want this done around this call -- this is + # the only place we are using yum outside the chroot, and hence + # picking up the base-system's default rpm macros. For example, + # the yumdownloader calls above in _install_repos want to use + # ~/.rpmdb/ ... there is nothing in the build-system /var/lib/rpm! + ( + flock -w 1200 9 || die "Can not lock .rpmmacros" + echo "%_dbpath /var/lib/rpm" >> $HOME/.rpmmacros + sudo -E yum -y \ --setopt=cachedir=$YUM_CACHE/$ARCH/$DIB_RELEASE \ --setopt=reposdir=$TARGET_ROOT/etc/yum.repos.d \ --installroot $TARGET_ROOT \ - install $@ - + install $@ + sed -i '$ d' $HOME/.rpmmacros + ) 9>$HOME/.rpmmacros.dib.lock + rm $HOME/.rpmmacros.dib.lock # Set gpg path back because subsequent actions will take place in # the chroot sudo sed -i "s,$TARGET_ROOT/etc/pki/rpm-gpg,/etc/pki/rpm-gpg,g" \ @@ -110,7 +132,7 @@ else # initalize rpmdb sudo mkdir -p $TARGET_ROOT/var/lib/rpm - sudo rpm --root $TARGET_ROOT --initdb + sudo $_RPM --root $TARGET_ROOT --initdb # this makes sure that running yum/dnf in the chroot it can get # out to download stuff