RPM Community Forums

Mailing List Message of <rpm-users>

Re: error: cannot open Packages database in /opt/sys/var/lib/rpm

From: Jeff Johnson <n3npq@mac.com>
Date: Mon 05 Oct 2009 - 16:00:26 CEST
Message-id: <D7F9085A-90CE-4842-BD01-961616FCC79D@mac.com>

On Oct 5, 2009, at 7:53 AM, Manoj Palhade wrote:

> Dear Jens,
>
>
> Thanks for your reply. I have following requirement to port RPM on  
> QNX.
>
>
> I have to build RPM on one machine and then copy-past it to other  
> QNX machines(it is more that 10+) as I said previously (to install  
> rpm on QNX RTOS; I copied bin and lib folder from root folder to / 
> opt/sys/ folder of QNX.). It is not possible as per requirement that  
> I have to compile and build each time for each QNX running machine.  
> Copy-Past should work with out any problem.
>

Presumably there is no similarity whatsoever amongst the 10+ clients ...

Well RPM (like many significantly complex applications) needs to find  
its configuration
in order to "work".

RPM configuration is through macros loaded from files.

The paths to macro files are a colon separated list. Macro files are
loaded as found in the path(s) specified. The 1st file must exist,
the remaining macro files will be read iff they exist.

The search paths can be set from the CLI using the --macros option. If
not specified, the path(s) to macro files compiled into rpm will be  
used.

The macro file paths is also macro expanded, so one can achieve very  
flexible
configuration if used with discipline and methodology.

But note that macros that are not yet defined cannot be expanded while  
loading macro files.
So you can't just arbitrarily use macros and expect them to be present  
always and everywhere
while loading definitions of macros. This constraint is no different  
than any other computer
language.

I suggest you study /usr/lib/rpm/macros to see what RPM needs for  
configuration. Macros
defined early in that file tend (but aren't always) needed earlier  
during configuration.

E.g. RPM needs to know the path to where an rpmdb resides. From the  
CLI, that is a
--dbpath popt alias that defines a macro %{_dbpath} whose default  
value is usually
	...
	# The location of the rpm database file(s).
         %_dbpath %{_var}/lib/rpm
  Macros are lazily expanded where/when needed so the final resultant  
path also needs
the %{_var} macro defined at the time the %_dbpath is expanded
	...
	%_var                   /var
so the final path that will be used is "/var/lib/rpm".

There is a convention wired up within RPM to use argv[0]
in order to discover configuration. So if argv[0] is set to
"/usr/bin/rpm", then configuration will be attempted relative
to the executable path. In this case the path
	/usr/bin/../lib/macros
will be used instead of (what is usually used) "/usr/lib/rpm/macros"

But note that there are multiple directories and files that RPM
needs to function, that may or may not exist, including
	/var/lib/rpm			the path to the database
	/etc/rpm/platform		to set CPU-VENDOR-OS-GNU variables
	/usr/lib/rpm/macros	where most of the "default" configuration resides
	/usr/lib/rpm/rpmpopt*	where many RPM "options" are set

Note also that other applications, like smart/yum, which use RPM
also need to be configured, and have no argv[0] (or equivalent)
convention from which paths like "/usr/bin/../lib/macros" might be
inferred.

> As per your communication there are 2 ways to do this
>
> Compile and Build with some option (I am not sure which option to  
> use to compile and build RPM). This is OK as compilation and build  
> is one time task.
>
> Change paths in macro configuration. Is it in QNX OS file or in RPM  
> File? If it is in RPM File then it is possible as change paths in  
> macro configuration is one time task (Please let me know the  
> filename) but if it in QNX OS file then it is not possible because  
> of as per requirement.
> So please let me know which option I need to use to compile and  
> build RPM for first time so that I can do above task.
>

I cannot tell you what options are needed because you have not supplied
any details other than RPM needs to "work" from any path where it  
might be
copied to.

I can describe a process to capture what set of macros you will need to
copy with the rpm executable.

0) Copy /usr/bin/rpm to some random directory.
	mkdir /var/tmp/xxx
	cd /var/tmp/xxx
	cp /usr/bin/rpm
	touch macros

1) Invoke whatever functionality you want with --macros macros
	rpm --macros macros --showrc		# this will display the minimum defined  
set

2) populate the macros file item by item (mostly by pasting from /usr/ 
lib/rpm/macros)
until you have achieved whatever functionality you desire. At a  
minimum you will need
	%_dbpath	/var/lib/rpm
in order to do "rpm -qa". Note that /usr/lib/rpm/rpmpopt-X.Y contains  
many CLI "options"
(they're actually popt exec's and aliases, see man 3 popt), which also  
can contain
paths to executables like awk and grep and sort that will need to  
become path
independent for RPM to Just Work.

3) design a means to also copy the macros file when rpm is copied. You  
can try the argv[0]
discovery, or (even simpler) write a shell wrapper to hide "--macros / 
path/to/your/macros".

hth

73 de Jeff
> Thanks and Regards,
> Manoj Palhade
>
>
> On Thu, Oct 1, 2009 at 6:52 PM, Jeff Johnson <n3npq@mac.com> wrote:
>
> On Oct 1, 2009, at 7:18 AM, Manoj Palhade wrote:
>
>> Hi,
>>
>>  I want to install rpm on QNX RTOS. For this purpose I copied bin  
>> and lib folder from root folder to /opt/sys/ folder of QNX.
>>
>>
>
> You likely need to change paths in macro configuration, almost all  
> paths
> used by RPM are in configuration, not compiled into RPM. So you
> also need to change the configuration when moving executables.
>
>> And I tried to execute basic command like #rpm –qa & #rpm –Uvh  
>> rpmtest-1.1-1.x86pc.rpm
>>
>>  But I am getting following error for each and every command.
>>
>> error: cannot open Packages database in /opt/sys/var/lib/rpm
>>
>>
>
> The first step is to add -vv (or use strace) to see what paths RPM  
> is trying to use.
>
>>  I also tried to execute command # rpm –-initdb. It is working fine.
>>
>>
>
> The --initdb option doesn't really initialize anything and isn't  
> really needed or
> useful.
>
>>  Please help me to resolve this error. Also do I need to copy var  
>> folder also.
>>
>>
>
> Perhaps easiest would be to rebuild rpm and with the paths you want  
> to use.
>
> By copying, you are almost certainly going to have to override  
> compiled in
> paths with additional CLI arguments using a shell wrapper.
>
> 73 de Jeff
>
Received on Mon Oct 5 16:00:48 2009
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.