0

My system is centos7.

[root@centos7 caiyiheng]# uname -a
Linux centos7 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 
x86_64 x86_64 x86_64 GNU/Linux

My system run in a virtualbox.

When I run the cmd yum -y update, and press ctrl+c while yum is updateing something. after that I found I can't use yum or rpm anymore. when I input yum or rpm it show as:

[root@centos7 caiyiheng]# yum
error: Failed to initialize NSS library
error: no dbpath has been set
error: cannot open Packages database in /%{_dbpath}
CRITICAL:yum.main:

Error: rpmdb open failed
[root@centos7 caiyiheng]# rpm
error: Failed to initialize NSS library

most yum or rpm command can't work, such as yum install,yum clean all even yum --help.

I check /var/log/yum.log, it show as:

[root@centos7 caiyiheng]# tail -f /var/log/yum.log
Sep 21 05:53:21 Installed: wget-1.14-15.el7_4.1.x86_64
Sep 21 05:53:21 Installed: lsof-4.87-5.el7.x86_64
Sep 21 05:53:22 Installed: net-tools-2.0-0.22.20131004git.el7.x86_64
Sep 26 17:28:11 Updated: libgcc-4.8.5-28.el7_5.1.x86_64
Sep 26 17:28:12 Installed: 1:grub2-common-2.02-0.65.el7.centos.2.noarch
Sep 26 17:28:13 Installed: 1:grub2-pc-modules-2.02-0.65.el7.centos.2.noarch
Sep 26 17:28:13 Installed: firewalld-filesystem-0.4.4.4-14.el7.noarch
Sep 26 17:28:14 Updated: tzdata-2018e-3.el7.noarch
Sep 26 17:28:14 Updated: ncurses-base-5.9-14.20130511.el7_4.noarch
Sep 26 17:28:15 Updated: nss-softokn-freebl-3.36.0-5.el7_5.x86_64

and I search in google for a whole day, found lots of solutions may like my problem, I tried them but nothing happen.

such as

I even download the rpm https://centos.pkgs.org/7/centos-updates-x86_64/nss-softokn-freebl-3.36.0-5.el7_5.x86_64.rpm.html

and rpm2cpio nss-softokn-freebl-3.36.0-5.el7_5.x86_64.rpm | cpio -idmv and copy ./usr/lib or lib64 or ./etc to /usr/lib /usr/lib64 /etc, but all of that can't solve my problem.

Someone mentioned that yum has a problem with chroot (https://bugs.centos.org/view.php?id=14767) but it doesn't match my situation, I even tried that, but nothing happen.

3
  • Can you check rpm -qa |grep nss and edit your question to post the results please (if it will let you run that) Commented Sep 27, 2018 at 17:50
  • no, can't run rpm -qa,show the same error,maybe I need to reinstall my system.
    – rangercyh
    Commented Sep 28, 2018 at 6:11
  • Have you tried running that rpm2cpio command at the root of the machine? That would automatically dump the required files. Maybe try it with the previous version noted in yum.log Commented Sep 29, 2018 at 20:19

1 Answer 1

0

I just experience the same issue. it took me hours to find the issue and solve it. my case is interrupt the yum update and the last yum.log record is just like you

Oct 22 19:04:36 Updated: 1:grub2-pc-modules-2.02-0.65.el7.centos.2.noarch
Oct 22 19:04:36 Updated: tzdata-2018e-3.el7.noarch
Oct 22 19:04:37 Updated: bash-4.2.46-30.el7.x86_64
Oct 22 19:04:37 Updated: nss-softokn-freebl-3.36.0-5.el7_5.x86_64

I searched and tried the all the solutions but no luck just like you. then I read the rpm source and found in the rpm/rpmio/digest_nss.c

#if HAVE_NSS_INITCONTEXT
    PRUint32 flags = (NSS_INIT_READONLY|NSS_INIT_NOCERTDB|
              NSS_INIT_NOMODDB|NSS_INIT_FORCEOPEN|
              NSS_INIT_NOROOTINIT|NSS_INIT_OPTIMIZESPACE);
    _nss_ctx = NSS_InitContext(NULL, NULL, NULL, NULL, NULL, flags);
    if (_nss_ctx == NULL) {
#else
    if (NSS_NoDB_Init(NULL) != SECSuccess) {
#endif
        rpmlog(RPMLOG_ERR, _("Failed to initialize NSS library\n"));
        rc = -1;
    } else {
        _crypto_initialized = 1;
    }
    sigaction(SIGPIPE, &oact, NULL);
    }

    /* Register one post-fork handler per process */
    if (_new_process) {
    if (pthread_atfork(NULL, NULL, at_forkchild) != 0) {
        rpmlog(RPMLOG_WARNING, _("Failed to register fork handler: %m\n"));
    }
    _new_process = 0;
    }
    return rc;
}

then I tried with code like this to verify

#include <stdio.h>
#include <nss.h>

int main() {
    NSSInitContext * _nss_ctx = NULL;
    printf("hello world!\n");
    PRUint32 flags = (NSS_INIT_READONLY|NSS_INIT_NOCERTDB|
                      NSS_INIT_NOMODDB|NSS_INIT_FORCEOPEN|
                      NSS_INIT_NOROOTINIT|NSS_INIT_OPTIMIZESPACE);
    _nss_ctx = NSS_InitContext(NULL, NULL, NULL, NULL, NULL, flags);
    if(_nss_ctx == NULL){
      printf("Error");
    }else{
      printf("OK");
    }
    return 0;
}

and got the NSS_InitContext is not referenced. ~~ so it is clear the lib version is not match

wget both nss-3.36.0-7.el7_5.x86_64.rpm and nspr-4.13.1-1.0.el7_3.x86_64.rpm (my system is centos7)

using rpm2cpio *rpm | cpio -idmv to extract the file and copy to /usr

run rpm still got the error

version `NSSUTIL_3.31' not found (required by /lib64/libnss3.so)

wget the nss-util-3.36.0-1.el7_5.x86_64.rpm and do a more rpm2cpio and copy

then everything get ok ~ hope this can help you

1
  • thx all the same though I have already reinstall my centos7,maybe next time I will try your solution.
    – rangercyh
    Commented Oct 30, 2018 at 2:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .