RE: pkg(8): difference between "-c /path" and "-r /path"

From: Mark Millard <marklmi_at_yahoo.com>
Date: Sun, 26 Feb 2023 17:49:32 UTC
Michael Schuster <michaelsprivate_at_gmail.com> wrote on
Date: Sun, 26 Feb 2023 09:07:14 UTC :

> This question is (as of yet) more of the "fill in background info" type:
> From the "pkg(8)" man-page:
> 
> -c <chroot path>, --chroot <chroot path>
> pkg will chroot in the <chroot path> environment.
> 
> -r <root directory>, --rootdir <root directory>
> pkg will install all packages within the specified <root
> directory>.
> 
> up to now, I've leaned towards "pkg -c /path <cmd>" when
> installing/updating a BE mounted at /path, but, given some results in the
> past that weren't quite clear to me (yes, that's a bit vague, sorry), I've
> been wondering whether "-r /path" would have been better.

For example, I have (aarch64 context):

# bectl list
BE            Active Mountpoint Space Created
13S-CA72      -      -          9.55G 2023-02-06 14:54
13_0R-CA72    -      -          5.72G 2021-09-29 00:45
13_1R-CA72    -      -          9.21G 2022-03-10 14:24
main-CA72     NR     /          14.1G 2023-02-19 17:31
old-main-CA72 -      -          1.80G 2023-02-09 21:20

So, other than 2 vintages of main [so: 14], there are
different versions of FreeBSD: 2 releases of releng/13.* ,
a stable/13 , as well as the 2 main 's.

I also build my own ports into local packages. Presume
for the purposes here that in main-CA72 the ports were
built for main, not for 13.0-RELEASE.

If executed from, say, main-CA72 as the booted environment,
pkg -r into a bectl mount of say 13_0R-CA72 (13.0-RELEASE),
that would be inappropriate: puting things for main in a
13.0-RELEASE context would be a unsupported mismatch.

But, if I had ports built for 13.0-RELEASE in 13_0R-CA72 ,
pkg -c into a bectl mount of 13_0R-CA72 would be appropriate.
It could avoid needing a reboot to do the same command.

Note that if I'd instead have booted 13_0R-CA72 and tried
to pkg -c into a mount of main-CA72, that would not be
appropriate because the 13.0-RELEASE kernel does not
support running main's world in a chroot. For this,
booting into a main context would be required. (I presume
not wanting 13.0-RELEASE port builds installed in main
so that -r would not be an option either.)

Overall, without sufficient description of your bectl
environment's type of content and the from/to combinations
you would be attempting, there is no direct answer to your
question and the answer may vary from from/to combination
to from/to combination.

(I've also ignored that pkg may do some validation of
context that would block more than I've indicated. The
description is already complicated enough. Other
keep-it-simple presumptions are present as well.)

===
Mark Millard
marklmi at yahoo.com