# bectl(8), chroot(8) and pkg-install(8)



## grahamperrin@ (Jun 26, 2021)

Below, no record of installation in /var/log/messages


```
root@mowa219-gjp4-8570p:~ # bectl create example && bectl mount example /tmp/up
Successfully mounted example at /tmp/up
root@mowa219-gjp4-8570p:~ # chroot /tmp/up
root@mowa219-gjp4-8570p:/ # pkg install -r FreeBSD networkmgr
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        networkmgr: 5.5 [FreeBSD]

Installed packages to be REINSTALLED:
        libntlm-1.6 [FreeBSD]

Number of packages to be installed: 1
Number of packages to be reinstalled: 1

The process will require 2 MiB more space.
1 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/2] Fetching networkmgr-5.5.txz: 100%    1 MiB   1.2MB/s    00:01   
[2/2] Fetching libntlm-1.6.txz: 100%   26 KiB  26.8kB/s    00:01   
Checking integrity... done (0 conflicting)
[1/2] Installing networkmgr-5.5...
[1/2] Extracting networkmgr-5.5: 100%
[2/2] Reinstalling libntlm-1.6...
[2/2] Extracting libntlm-1.6: 100%
root@mowa219-gjp4-8570p:/ # exit
exit
root@mowa219-gjp4-8570p:~ # grep networkmgr /var/log/messages
Jun 26 16:33:56 mowa219-gjp4-8570p pkg[7767]: networkmgr-5.5 deinstalled
root@mowa219-gjp4-8570p:~ # bectl umount example
root@mowa219-gjp4-8570p:~ # bectl destroy -o example
root@mowa219-gjp4-8570p:~ # pkg info -x networkmgr
pkg: No package(s) matching networkmgr
root@mowa219-gjp4-8570p:~ #
```

How can I use pkg-install(8) with bectl and chroot(8) *and* have a log of installations?

Alternatively:



grahamperrin said:


> Is logging achievable with the `--chroot` option of pkg?


----------



## mer (Jul 10, 2021)

grahamperrin 
pkg stores it's info in /var/db/pkg.   /var/db is part of a BE, /var/log is it's own dataset so "persists" across different BEs.
When you chrooted above you installed networkmgr-5.5 in the BE named example.
Exiting your chroot, networkmgr-5.5 did not exist in that BE;  I don't know where the log from /var/log/messages came from, unless you did pkg delete networkmgr-5.5 in your original BE prior to chroot into example.

I'm not sure exactly what you are looking for.  Is it:
"if I do pkg install blah when I am chrooted into a BE that is not the boot BE, I want that fact to be logged so I have a log that  says I installed it in the BE I'm chrooted into"

What may have happened is when you chroot the /var/log dataset is not actually mounted in the chroot which means in the chroot BE /var/log should exist during the chroot.

One can also do "diffs" between snapshots/clones to see what is different.  Since a BE is basically a clone of a snapshot, one should be able to diff them and find this stuff out.


----------



## grahamperrin@ (Jul 10, 2021)

mer said:


> "if I do pkg install blah when I am chrooted into a BE that is not the boot BE, I want that fact to be logged so I have a log that says I installed it in the BE I'm chrooted into"



Sort of. Essentially, I want installations and so on to be logged in /var/log/messages as they normally are.



mer said:


> … What may have happened is when you chroot the /var/log dataset is not actually mounted in the chroot …



I recall making some attempt (not shown in the opening post) to have /var/log/messages writeable in the chroot environment, but it didn't work.


----------



## mer (Jul 10, 2021)

grahamperrin said:


> Sort of. Essentially, I want installations and so on to be logged in /var/log/messages as they normally are.
> 
> 
> 
> I recall making some attempt (not shown in the opening post) to have /var/log/messages writeable in the chroot environment, but it didn't work.


That makes sense, because "chroot blah" means "your directory tree is rooted at blah" and I don't recall offhand the rules on stuff outside the chroot making it visible in the chroot.


----------



## Alain De Vos (Jul 10, 2021)

A nullfs mount ?


----------



## mer (Jul 10, 2021)

Alain De Vos said:


> A nullfs mount ?


Maybe, but once you chroot, things get locked down.  Think similar to being in a jail:  you can't see the host filesystem.  Your whole world exists only in the jail.  A chroot is very similar.

Let's say you're booted into BE A.  You have package xyz installed.  If you bectl create B, B starts out as a copy of A.  Booting into B would like exactly like being in A.
So you boot into B and do pkg delete xyz.  Now in BE B, package xyz does not exist. pkg info | grep -i xyz returns nothing.
Activate A and reboot into BE A, pkg info | grep -i xyz shows that pkg exists.

If you are booted into BE A, you bectl mount B, then chroot B from a term window, that specific console session is effectively "in BE B" but it does not see the datasets mounted in the original BE A;  solely because of the way chroot is designed and works.


----------



## grahamperrin@ (Jul 10, 2021)

Reminding myself of <https://alpha.pkgbase.live/howto/bootstrap.html#create-a-new-boot-environment> but not thinking specifically of PkgBase … maybe I need to use the `jail` command of bectl …


----------

