I'm doing this to get the user dynamic dependencies (not those in /lib64, but in /usr/lib64).

[root@localhost bin]# ldd Xvfb | grep '/usr/lib64/' | cut -d '=' -f1

I would like to copy these files from /usr/lib64 to another machine (CentOS to CentOS, nearly identical builds), most likely by way of transferring a tarball. Most of these are probably symlinks to their latest version, so those files would have to be included too, and the symlinks need to be recreated on the other machine.

It has to be done this way because there are no package managers on the target machine and it is sandboxed (no internet).

I'm thinking this list can be turned into a single string that can be passed to tar, but I'm not familiar with how to go about it. I have to do this for a few binaries, so a one-liner would be great if it can be done. Any ideas?

  • Don't do this. Install the packages instead. rpm -qf will tell you which packages are needed. – Gilles 'SO- stop being evil' Oct 2 '16 at 23:38
  • @Gilles I don't want to do this either, believe me. The other machine has no package manager installed and is highly sandboxed. I have to do it this way. Both machines are identical builds. – Drakes Oct 2 '16 at 23:44
  • One thing you certainly need to do is to dereference symlinks. Most of those files will not be regular files but symlinks, and with more than one level of symlinking. e.g. libX11.so.6 -> libX11.so.6.3 -> libX11.so.6.3.0 – grochmal Oct 3 '16 at 0:20
  • @grochmal You're right. I made a comment in the answer below that will dereference the symlinks before making the tarball. However, it's ugly and I would appreciate any help cleaning it up. – Drakes Oct 3 '16 at 3:22

You're probably better off determining which packages those shared libraries correspond to, and using that list of packages to install via yum on the second machine. By doing that, you will get updates when yum finds them.

Offhand, you might not want to do this if:

  • the second machine has no network access, or
  • for testing purposes, you want to duplicate the configuration for a slightly-out-of-date machine (where yum no longer has those specific package versions available).

Collecting the package information is done using rpm -qf for each file, e.g.,

rpm -qf /usr/lib64/libfreebl3.so

which will give you the package and its version — enough information to install that same package using yum on another machine.

If you tar up shared libraries, you should also be aware that they may depend upon configuration files (including those which would be installed into /etc/ld.so.conf.d). You can find the files which are part of the same package using rpm -ql, e.g.,

rpm -ql $(rpm -qf /usr/lib64/libfreebl3.so)

Of course you will have some duplicates. Also, those libraries may depend upon other packages (with their own configuration files) which are not apparent. In this case rpm -qR helps, but some work is needed to see that you have the files you need).

Working from the list of libraries:

ldd Xvfb | grep '/usr/lib64/'

you can make a list of the packages by

ldd Xvfb | grep '/usr/lib64/' | xargs rpm -qf

and get a corresponding list of files

ldd Xvfb | grep '/usr/lib64/' | xargs -n 1 rpm -qf | xargs -n 1 rpm -ql

and tar that up:

tar czf /tmp/blob.tar.gz $(ldd Xvfb | grep '/usr/lib64/' | xargs -n 1 rpm -qf | xargs -n 1 rpm -ql)

though you might want to toss in a stage with sort -u to filter out duplicate packages. rpm will accept multiple packages on some lines but not others, so I used the -n 1 option just to be safe(r).

If as suggested you simply want the library files, that could be done like this:

mkdir  /tmp/xvfb
cd /usr/lib64
tar czf /tmp/xvfb/Xvfb.tar.gz $(ldd /usr/bin/Xvfb | grep '/usr/lib64/' | cut -d '=' -f1 | awk '{print $1}' | while read IN; do OUT=`readlink $IN`; cp -rf $OUT /tmp/xvfb/$IN; echo /tmp/xvfb/$IN; done)

while the approach I suggested using rpm -q will provide the symbolic links for the files. (In a quick check with CentOS6, there are no ldconfig files, but a lot of /usr/share files which you would filter out).

|improve this answer|||||
  • This is good advice for most situations. Here, the other machine has no package manager installed and is highly sandboxed (no internet either). I have to do it this way, but the good news is that both machines are nearly identical builds. – Drakes Oct 2 '16 at 23:47
  • Your amendments almost solved my problem. I used your tar script and came up with tar czf /tmp/xvfb/Xvfb.tar.gz $(ldd /usr/bin/Xvfb | grep '/usr/lib64/' | cut -d '=' -f1 | awk '{print $1}' | while read IN; do OUT=`readlink $IN`; cp -rf $OUT /tmp/xvfb/$IN; echo /tmp/xvfb/$IN; done). This does exactly what I want, plus it dereferences the symlinks at the same time. Would you mind adding (something like) this to your answer for completeness? FWIW, copying these libraries worked on the target machine and all is well. – Drakes Oct 3 '16 at 2:56

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.