# Installing pkgs in a remote location



## balanga (Jul 6, 2019)

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`?


----------



## T-Daemon (Jul 6, 2019)

The answer is under your fingertips.  man pkg(8)

```
-c <chroot path>, --chroot <chroot path>
             pkg will chroot in the <chroot path> environment.
```

`mount /dev/da0p2 /mnt`
`pkg -c /mnt install pkgx`


----------



## balanga (Jul 8, 2019)

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%
> ...




Seems like some sort of SQL...


----------



## Phishfry (Jul 8, 2019)

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.


----------



## Phishfry (Jul 8, 2019)

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




__





						pkg-add
					






					www.freebsd.org
				







__





						PkgPrimer - FreeBSD Wiki
					





					wiki.freebsd.org


----------



## Phishfry (Jul 8, 2019)

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.


----------



## balanga (Jul 8, 2019)

Phishfry said:


> 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`



Exactly the same thing happened.


----------



## Phishfry (Jul 8, 2019)

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


----------



## balanga (Jul 8, 2019)

I was trying to follow some instructions for installing pkgs on a diskless system - couldn't get it to work though...


----------

