Copying existing packages to a new system

Is there any way of copying pkgs from one system to another without re-installing them?

I was thinking of copying /var/cache/pkg/ and /usr/local/. Would that get me close?
 
May I ask what your ultimate goal is (or rather, why you'd like to do that)?

The more reasonable way would be to use pkg info on the source machine to get a list of all installed packages and then doing a pkg install on the target machine using that list as an input.
In any case, I don't think that there is a reasonable way of "copying without re-installing".

/var/cache/pkg contains the package cache. This means that you'll still have to install (or add) the packages to the target machine. Also, note that the package cache potentially contains older packages that are not currently installed on that same host (anymore).
 
I was thinking of copying /var/cache/pkg/ and /usr/local/. Would that get me close?
It would get the files there, yes. They'll work too. But they won't be registered in the package database. So the system thinks nothing is installed.
 
when you use pkg commands it updates that database

You can use a pkg command to list the installed packages on one system, send to output to a file.
Use this file on the other system to install the same packages.
 
SirDice Is my statement about /var/cache/pkg incorrect? Doing a quick pkg clean --dry-run shows packages in that path that would be cleaned up.
 
It's not incorrect. In essence you don't need the cache at all. If a package is 'installed' there's no need for the cache any more. pkg-install(8) fetches a package {pkg-fetch(8)) and stores it in /var/cache/pkg/, then a pkg-add(8) actually 'installs' it, i.e. copies the files from package archive to their respective spot somewhere in /usr/local/, wherever they need to go.

Then the package gets registered in the package database; /var/db/pkg/local.sqlite. As the name suggests it's an SQLite database. This database keeps track of everything you have installed. You can query that database using pkg-info(8) and pkg-query(8) for example. If it's not registered in this database, it's not installed, simple as that.
 
Is there any way of copying pkgs from one system to another without re-installing them?
It should be possible, but I prefer to copy complete system if I need to have a clone of some installation.
It may be a good idea to copy all current system and run it as a jail somewhere.
You will receive a copy of the same system with all packages. You have a chance to remove some packages other than required.
It may take a little bit more time, but the result will work as expected.
 
You might have another sqlite database in there, that's a local copy of the remote package database. And a copy of vuln.xml for use with pkg-audit(8).
 
The majority of packages install under /usr/local, but not everything is installed there; some packages install contents only or even in other locations, e.g.:
The list is surely not exhaustive, so you should carefully check that nothing is missing.
 
The majority of packages install under /usr/local, but not everything is installed there; some packages install contents only or even in other locations, e.g.:
The list is surely not exhaustive, so you should carefully check that nothing is missing.

I was surprised by that. It doesn't seem to adhere to FreeBSD's policy of separating the base system form pkgs...
 
The list is surely not exhaustive, so you should carefully check that nothing is missing.
pkg shell 'select path from files'|grep -v ^/usr/local

In addition to the files that are installed, many directories are created in /var.
pkg shell 'select path from directories'|grep var

pkg-shell(8)
Code:
DESCRIPTION
     Do not rely on this command.
 
Seems like a bad idea. You're bound to miss some files somewhere. I would do
Code:
pkg prime-origins > pkglist.txt
On the source system, and then
Code:
cat pkglist.txt | xargs pkg install -y
On the target system. It may even be faster if you have a local package cache.
 
poudriere-image builds images you can use to make cloned machines. Another simple alternative is to make a "meta package" that lists the packages you want, then you just need to install that one package on each machine and it will pull the rest in.
 
Back
Top