Installing pkgs in a remote location

Is it possible to install pkgs in a remote location?

ie suppose I have a disk with FreeBSD installed, but I can't boot from it for some reason, although am able to mount it say mount /dev/da0p2 /mnt, is there some way to pkg install or pkg add pkgx to /mnt or maybe I can chroot /mnt and then pkg install pkgx?
 
The answer is under your fingertips. :) man pkg(8)
Code:
-c <chroot path>, --chroot <chroot path>
             pkg will chroot in the <chroot path> environment.

mount /dev/da0p2 /mnt
pkg -c /mnt install pkgx
 
Here's what I got - no idea what it means...
root@FreeBSD:~/test # pkg -c /mnt/tftproot/nfsroot/FreeBSD/12.0-x64 install mc
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file or directory
Fetching meta.txz: 0%
Fetching meta.txz: 100% 940 B 0.9kB/s 00:01
Fetching packagesite.txz: 0% 8 KiB 8.2kB/s 13:29 ETA

pkg: sqlite error while executing CREATE TABLE packages (id INTEGER PRIMARY KEY,origin TEXT,name TEXT NOT NULL,version TEXT NOT NULL,comment TEXT NOT NULL,desc TEXT NOT NULL,osversion TEXT,arch TEXT NOT NULL,maintainer TEXT NOT NULL,www TEXT,prefix TEXT NOT NULL,pkgsize INTEGER NOT NULL,flatsize INTEGER NOT NULL,licenselogic INTEGER NOT NULL,cksum TEXT NOT NULL,path TEXT NOT NULL,pkg_format_version INTEGER,manifestdigest TEXT NULL,olddigest TEXT NULL,dep_formula TEXT NULL,vital INTEGER NOT NULL DEFAULT 0);CREATE TABLE deps (origin TEXT,name TEXT,version TEXT,package_id INTEGER REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,UNIQUE(package_id, name));CREATE TABLE categories (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE );CREATE TABLE pkg_categories (package_id INTEGER REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,category_id INTEGER REFERENCES categories(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, category_id));CREATE TABLE licenses (id INTEGER PRIMARY KEY,name TEXT NOT NULL UNIQUE);CREATE TABLE pkg_licenses (package_id INTEGER REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,license_id INTEGER REFERENCES licenses(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, license_id));CREATE TABLE option (option_id INTEGER PRIMARY KEY,option TEXT NOT NULL UNIQUE);CREATE TABLE option_desc (option_desc_id INTEGER PRIMARY KEY,option_desc TEXT NOT NULL UNIQUE);CREATE TABLE pkg_option (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,option_id INTEGER NOT NULL REFERENCES option(option_id) ON DELETE RESTRICT ON UPDATE CASCADE,value TEXT NOT NULL,PRIMARY KEY(package_id, option_id));CREATE TABLE pkg_option_desc (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,option_id INTEGER NOT NULL REFERENCES option(option_id) ON DELETE RESTRICT ON UPDATE CASCADE,option_desc_id INTEGER NOT NULL REFERENCES option_desc(option_desc_id) ON DELETE RESTRICT ON UPDATE CASCADE,PRIMARY KEY(package_id, option_id));CREATE TABLE pkg_option_default (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,option_id INTEGER NOT NULL REFERENCES option(option_id) ON DELETE RESTRICT ON UPDATE CASCADE,default_value TEXT NOT NULL,PRIMARY KEY(package_id, option_id));CREATE TABLE shlibs (id INTEGER PRIMARY KEY,name TEXT NOT NULL UNIQUE );CREATE TABLE pkg_shlibs_required (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,shlib_id INTEGER NOT NULL REFERENCES shlibs(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, shlib_id));CREATE TABLE pkg_shlibs_provided (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,shlib_id INTEGER NOT NULL REFERENCES shlibs(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, shlib_id));CREATE TABLE annotation (annotation_id INTEGER PRIMARY KEY,annotation TEXT NOT NULL UNIQUE);CREATE TABLE pkg_annotation (package_id INTERGER REFERENCES packages(id) ON DELETE CASCADE ON UPDATE RESTRICT,tag_id INTEGER NOT NULL REFERENCES annotation(annotation_id) ON DELETE CASCADE ON UPDATE RESTRICT,value_id INTEGER NOT NULL REFERENCES annotation(annotation_id) ON DELETE CASCADE ON UPDATE RESTRICT,UNIQUE (package_id, tag_id));CREATE TABLE pkg_conflicts (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,conflict_id INTEGER NOT NULL,UNIQUE(package_id, conflict_id));CREATE TABLE provides( id INTEGER PRIMARY KEY, provide TEXT NOT NULL);CREATE TABLE pkg_provides (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,provide_id INTEGER NOT NULL REFERENCES provides(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, provide_id));CREATE TABLE requires( id INTEGER PRIMARY KEY, require TEXT NOT NULL);CREATE TABLE pkg_requires (package_id INTEGER NOT NULL REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,require_id INTEGER NOT NULL REFERENCES requires(id) ON DELETE RESTRICT ON UPDATE RESTRICT,UNIQUE(package_id, require_id));PRAGMA user_version=2014; in file pkgdb.c:2406: disk I/O error
Unable to create repository FreeBSD
Error updating repositories!


Seems like some sort of SQL...
 
The remote pkg sqlite database probably needs some credentials you don't have.
I think your whole method is wrong.
What you need to do is copy over the packages as *.txz files to remote machine then disconnect and boot remote machine and pkg add your packages that you copied over.
 
If you had a whole bunch of packages that would make it a pain to pkg add them all then maybe write a script to install them.
pkgname=mc.txz , ytree.txz, gpsd.txz;
pkg add -A ${pkgname}

Copy over the txz packages to remote machine and make a script with the package names as variables and copy this script over too.
Execute it on the remote machine when booted up.

Some more stuff to consider for remote/blind package adding.
setenv DEFAULT_ALWAYS_YES
setenv ASSUME_ALWAYS_YES
 
OK now that I gave you the spiel about how to do it my way, lets look at what went wrong with your approach.
You issued this command:
pkg -c /mnt/tftproot/nfsroot/FreeBSD/12.0-x64 install mc
And the key error:
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file or directory

Why is this?? Well the first command to run on your chroot should be:
pkg -c /mnt/tftproot/nfsroot/FreeBSD/12.0-x64 install pkg
The reason?
Well your package database does not yet exist in the chroot UNTIL you install pkg.
This creates the sql pkg database inside the chroot.
So add pkg first on list. It is required.

Post Requiem: It appears you local pkg sql database errored out because a remote database was not found.

I still like my method better... Dunno if this will even work.
 
How about this:
pkg fetch -d -o /mnt/tftproot/nfsroot/FreeBSD/12.0-x64/tempdir pkg mc ytree xorg xfe

This will save the txz files to your mount and you will need to run pkg-add later.

On the remote machine:
cd to here: ./12.0-x64/tempdir/All <<fetched directory plus /All
pkg add pkg
pkg add mc ytree xorg xfe
 
Back
Top