Re: pkg installation into non-default location

From: Emmanuel Vadot <>
Date: Wed, 11 Aug 2021 12:20:24 +0200
On Wed, 11 Aug 2021 12:59:52 +0300
Andriy Gapon <> wrote:

> On 2021-08-10 16:57, Emmanuel Vadot wrote:
> > On Tue, 10 Aug 2021 15:47:03 +0300
> > Andriy Gapon <> wrote:
> > 
> >>
> >> I noticed at least three way of installing a package under "alternative
> >> root".  One of them is very straightforward, but for two other I am not
> >> sure about details.  I guess, I can get them all from the source code,
> >> but maybe someone would be kind to give me a summary.
> >>
> >> So, the obvious way is to use pkg with -c or -j option.  In this case
> >> pkg just chroot-s or jexec-s before doing anything.  So, conceptually
> >> everything is like the normal operation, but in the chroot or the jail.
> >>
> >> Then, there is -r option:
> >>      -r ?root directory?, --rootdir ?root directory?
> >>              pkg will install all packages within the specified ?root
> >>              directory?.
> >> It's not entirely clear what that means and when that can be useful.
> >> In other words, why this option exists if we already have -c and -j.
> > 
> >  Having -r is useful for different things :
> > 
> >  - We use that for the tests so every test installation/delete is done
> > under a specified dir.
> >  - It's also useful when creating image for a different arch than the
> > native one.
> >  - It's also useful for pkgbase to bootstrap a system/jail/whatever as
> > at first you will not have something to chroot/jail on.
> Thank you for the information!
> Still curious about some technical details.
> I assume that -r simply unpacks packages files under an alternative root
> (similar to DESTDIR).
> So, does it still use the package database under the main root?

 The db and cache dirs are under the destdir, pkg(8) doesn't uses the
main root dir when using -r

> Is a package installed with -r marked as such?
> Or is it registered as if there was no -r ?

 There is not such thing being done, it's simply registered in the db
under the rootdir.

> What about installation scripts that the package may have?

 Some scripts are rootdir compliant but not all.
for some example of making something -r compliant.

> Is that the script's job to ensure that it works correctly with -r or
> does pkg arrange an alternative root somehow?
> Thank you.

 Yes it is, note that we also have triggers now and defered triggers
which means that if a package needs to run some programs after the
installation (like registering a font or something like that) it can
use triggers based on the dirs and if the arch isn't the same the
triggers is defered by default iirc, so one have to use pkg-triggers to
run it after.
 Not much have been done in the ports tree for triggers yet though.

> -- 
> Andriy Gapon

Emmanuel Vadot <> <>
Received on Wed Aug 11 2021 - 10:20:24 UTC

Original text of this message