Why does rpm/rpmkeys --import not execute successfully in rpm %post scriptlet in Red Hat Enterprise Linux 8?

Solution Verified - Updated -

Issue

  • rpm --import or rpmkeys --import doesn't execute successfully while being a part of rpm package's %post scriplet?
# rpm -q import --scripts
preinstall program: /bin/sh
postinstall scriptlet (using /bin/sh):
rpmkeys -vvv --import /RPM-GPG-KEY-redhat-release
preuninstall program: /bin/sh
postuninstall program: /bin/sh
  • This works with Red Hat Enterprise Linux 6 and 7.
[root@rhel6 ~]# rpm -ivh /root/rpmbuild/RPMS/x86_64/import-1-0.x86_64.rpm
Preparing...                ########################################### [100%]
   1:import                 ########################################### [100%]
D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key
D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key
D: loading keyring from rpmdb
D: opening  db environment /var/lib/rpm cdb:mpool:joinenv
D: opening  db index       /var/lib/rpm/Packages rdonly mode=0x0
D: locked   db index       /var/lib/rpm/Packages
D: opening  db index       /var/lib/rpm/Name rdonly mode=0x0
D:  read h#     670 Header sanity check: OK
D: added key gpg-pubkey-fd431d51-4ae0493b to keyring
D:  read h#     671 Header sanity check: OK
D: added key gpg-pubkey-2fa658e0-45700c69 to keyring
D:  read h#     788 Header sanity check: OK
D: added key gpg-pubkey-ab97acbe-586223cc to keyring
D:  read h#     806 Header sanity check: OK
D: added key gpg-pubkey-0608b895-4bd22942 to keyring
D: Using legacy gpg-pubkey(s) from rpmdb
D: closed   db index       /var/lib/rpm/Name
D: closed   db index       /var/lib/rpm/Packages
D: closed   db environment /var/lib/rpm

[root@rhel7 ~]# rpm -ivh /root/rpmbuild/RPMS/x86_64/import-1-0.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:import-1-0                       ################################# [100%]
D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key
D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key
D: loading keyring from rpmdb
D: opening  db environment /var/lib/rpm cdb:0x401
D: opening  db index       /var/lib/rpm/Packages 0x400 mode=0x0
D: locked   db index       /var/lib/rpm/Packages
D: opening  db index       /var/lib/rpm/Name 0x400 mode=0x0
D:  read h#     186 Header SHA1 digest: OK (dd737a402556b7653c2bc971f343532046e26384)
D: added key gpg-pubkey-352c64e5-52ae6884 to keyring
D:  read h#     450 Header SHA1 digest: OK (22824a5fcbad49190bcc2dd45d06b4b53aad2447)
D: added key gpg-pubkey-fd431d51-4ae0493b to keyring
D:  read h#    1132 Header SHA1 digest: OK (2355c07f9978587c537d385c0bdd9353214f7032)
D: added key gpg-pubkey-2fa658e0-45700c69 to keyring
D: Using legacy gpg-pubkey(s) from rpmdb
D: closed   db index       /var/lib/rpm/Name
D: closed   db index       /var/lib/rpm/Packages
D: closed   db environment /var/lib/rpm
  • The error it throws is as follows. rpm --import couldn't get the Lock.
# rpm -ivh import-1-0.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:import-1-0                       ################################# [100%]
ufdio:       1 reads,    17154 total bytes in 0.000011 secs
ufdio:       1 reads,     3211 total bytes in 0.000005 secs
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
error: /RPM-GPG-KEY-redhat-release: key 1 import failed.
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
error: /RPM-GPG-KEY-redhat-release: key 2 import failed.
warning: %post(import-1-0.x86_64) scriptlet failed, exit status 2

Environment

  • Red Hat Enterprise Linux 8
  • rpm-4.14.2-9.el8.x86_64.rpm and later

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content