# Installing driver from offline repository



## Leveret (Dec 22, 2018)

I need to know how to save the xf86-video-ati, sddm and plasma5-sddm-kcm files to cd/dvd/usb in a kind of offline repository. That way when I install FreeBSD I install them from my offline repository instead of having to connect to the Internet and download them. Does anyone know how to do this?


----------



## twllnbrck (Dec 23, 2018)

You could use ports-mgmt/poudriere or ports-mgmt/synth to create your own package repository, maybe on another machine. But keep in mind that the packages have to be consistent with your system (build packages for 11.2 or 12.0 and so on).


----------



## Phishfry (Dec 23, 2018)

You have to add `pkg` itself to your list and then make a local repository and point to it.
https://amitabhkant.com/2014/10/03/creating-custom-pkgng-repository-for-freebsd/
You can download the packages from FreeBSD on another machine and copy over.


----------



## Leveret (Dec 23, 2018)

Do the ports need to be downloaded before using synth? I entered synth just-build myrepository.list at command line. The file contains these lines:

ports-mgmt/pkg

x11-drivers/xf86-video-ati

x11/sddm/sddm

deskutils/plasma5-sddm-kcm

The error message I get is: It seems that a blank PORTSDIR is defined in /etc/make.conf


----------



## Sevendogsbsd (Dec 23, 2018)

Yes, in order to build from ports, you need a copy of the ports tree. I   use `portsnap` to do this. I do have a separate machine for this purpose though.


----------



## Sevendogsbsd (Dec 23, 2018)

Didn't get a chance to elaborate last night: I have the configs necessary to have one machine build packages and serve them to a second machine. Here is my set up:

Ports builder machine:

1) FreeBSD 12.0-RELEASE with ports-mgt/synth and www/nginx installed, nothing else.

nginx config snippet. I probably don't need the part about "autoindex" but wanted to be able to run a browser and see the what the contents of the site were. Not visible outside my LAN so it's fine. www/nginx is used to serve the packages to the machine using them.


```
server {
    listen       80;
    server_name  bigzbox.sevendogs.net;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    root /var/synth/live_packages;
    location / {
        autoindex on;
    }
```

No configuration for ports-mgmt/synth is necessary except if you want to use tmpfs, then it picks that up automatically.

2) PC being served packages to:

Needs 2 config files and these will depend on your particular set up in terms of names you have for your build machine:

Under /usr/local/etc/pkg/repos/, the following 2 files are needed: FreeBSD.conf and myrepo.conf. The "myrepo.conf" can be named whatever - I just used the example from the howto on ports-mgmt/poudriere.

FreeBSD.conf:


```
FreeBSD: {
  enabled: no
}
```

myrepo.conf:


```
myrepo: {
  url: "http://bigzbox.sevendogs.net"
  enabled : yes,
  mirror_type : NONE
}
```

That's it for the set up. On the build machine, I feed ports-mgmt/synth with a text file list of ports I want to build: `synth just-build <insert your file name here>` and let it go. After the build is complete, if no errors, run `synth rebuild-repository` and after it completes, the repository is ready to go.

On the machine that is going to use your new repository, you can just do normal package installs. For the FIRST time when I switched to this process and had packages installed from the official FreeBSD repository, I ran `pkg delete -afy` which will delete ALL of your packages installed. Not sure if this is necessary but it worked for me. Then bootstrap `pkg` so it installs from your repo and you are good to go. Make sure you have ports-mgmt/pkg in your list of ports to be built.

About once a week (or 2), I run `portsnap` on the build machine to update the tree, then re-run the build process and rebuild the repository. The only ugly part about this is setting the port specific configurations using `make config-recursive` in each port directory that I am going to use. Might be a better way to do this but I only have 30 or so ports so I just did it manually. I have only had to do this once. I THINK the configs stay when you run `portsnap fetch` and `portsnap update` but someone with a whole lot more experience may correct me 

The only thing I don't like about this set up is that I don't think ports-mgmt/synth can provide cryptographic validation of a repository using keys. ports-mgmt/poudriere does. I asked the synth dev but have't gotten a response.


----------



## Leveret (Dec 23, 2018)

Phishfry linked to an article that showed how to create a repository.

pkg create -a

I copied the files created to a usb drive and mounted it on the target machine. I disabled the base FreeBSD repository as indicated in the article that Phishfry linked to. But is there a way I can make the system realize that this is what I want to use?

The article said that the new repo had to be made active and showed these commands:

echo 'REPONAME: { url: "http://REPO_URL"}' > /usr/local/etc/pkg/repos/REPONAME.conf
pkg upgrade

How would I modify the echo command above to have it use the files stored on my usb? Modify the url?


----------



## Sevendogsbsd (Dec 23, 2018)

I've never installed packages that way but I think you can use "file" as a protocol. Here is a reference from the ports-mgmt/poudriere HOWTO:



> A better way to use the packages is to use the pkg remote repository feature (see pkg-repository(5)) by creating a repository configuration file /usr/local/etc/pkg/repos/myrepo.conf and specifying the repository address as a file:// URL (to use the local file system) in this configuration file.




```
myrepo: {
    url             : "file:///usr/local/poudriere/data/packages/releng112amd64-default",
    enabled         : yes,
    mirror_type     : NONE
}
```

I suppose you could reference the usb drive this way but I have never done that.


----------



## Leveret (Dec 23, 2018)

Thanks.  sounds like what I was thinking. I'll give it a try.


----------



## Sevendogsbsd (Dec 23, 2018)

You would just have to remember to have the usb drive mounted, and the mount designation be consistent if you are going to use it in a configuration, before you ran `pkg update` or another command, or it would error out.


----------



## Leveret (Dec 23, 2018)

What I found that seems to work is to change to the directory on usb containing my repository and simply type: pkg add *.*

I read in the online manual pages that add is used when installing from a local package instead of fetching from remote. This solved the problem except that the pkg program itself has to be installed already. This requires connecting to the Internet if FreeBSD was installed from the img dowload file. I suspect that pkg is on the dvd but I don't have a dvd drive attached to the target machine and can only install using usb.

Do you know a way to determine which FreeBSD iso's might contain pkg already? It's not a big deal but it would mean I could install my repository without connecting to the Internet at all.


----------



## Phishfry (Dec 23, 2018)

Like I said earlier pkg.txz has to be included in your repo. Then you can bootstrap pkg.
Something like this `pkg-static add pkg.txz`.
pkg-static(1) is used to bootstrap pkg
Note: pkg.txz is a shortened name I am using for the latest pkg*.txz

https://forums.freebsd.org/threads/solved-offline-packages-installation.44589/


----------



## Leveret (Dec 24, 2018)

Phishfry, if I understand you correctly, I could have simply used *pkg add pkg.txz* from my usb repository and then *pkg add *.**? I didn't need to download pkg from the online repository?


----------



## Sevendogsbsd (Dec 24, 2018)

I am laughing at myself right now: I wrote this long tutorial because I misunderstood your original intention. No worries, hope it helps someone!


----------



## Leveret (Dec 24, 2018)

No problem, Sevendogsbsd. Every bit of information I get is of interest to me since I'm still very new to learning about FreeBSD.


----------



## Phishfry (Dec 24, 2018)

I modified my answer and added a forum post with supporting details. You need to use `pkg-static` to install `pkg`.
Once `pkg` is installed then you can install the rest using `pkg add`

This post will help you find all the dependencies you might need.
https://forums.freebsd.org/threads/pkg-dependencies.65695/#post-386206


----------



## Leveret (Dec 24, 2018)

Thanks Phishfry. I'll try pkg-static add pkg.txz and then pkg add *.* on a fresh install tomorrow. This last detail should complete the entire process of creating and using offline repositories.


----------



## Phishfry (Dec 24, 2018)

`pkg-static add pkg-1.10.5_5.txz` if using latest packages.
This after cd 'ing into your usb stick mountpoint with package txz files.

Any repo settings are not needed with this method.
Checkout `pkg fetch -d` to grab the packages on your connected machine.


----------



## Leveret (Dec 24, 2018)

I tried the pkg-static add pkg-1.10.5_5.txz but it doesn't install. I changed to the usb directory containing the repository.


----------



## Phishfry (Dec 24, 2018)

This post had everything you need. You need to update the version number.


dpejesh said:


> tar -Jxvf pkg-1.2.5.txz /usr/local/sbin/pkg-static


----------



## SirDice (Dec 24, 2018)

Leveret said:


> and then *pkg add *.**?


You're not on MS-DOS any more. There's no need to account for the 'extension'. Extensions don't exist, they're just part of the filename. So `pkg add *` will do exactly the same thing.


----------



## ShelLuser (Dec 24, 2018)

I know many people already answered but I'm sort of ignoring all that because I cannot help but think that programs such as Synth are serious overhead for what the OP is asking.



Leveret said:


> I need to know how to save the xf86-video-ati, sddm and plasma5-sddm-kcm files to cd/dvd/usb in a kind of offline repository.


It's actually really easy, and you don't need much else besides the base tools. You can simply download the individual package files and then use `# pkg add` to add those to your other system. _However..._ keep well in mind that some packages have specific dependencies which you're also going to have to satisfy, otherwise things don't work:

```
root@psi:/usr/local/etc # pkg search -d xf86-video-ati
xf86-video-ati-18.1.0,1
Comment        : X.Org ati display driver
Depends on     :
        libXi-1.7.9_2,1
        xorg-server-1.18.4_10,1
        mesa-libs-18.1.9_4
        libdrm-2.4.96,1
        libpciaccess-0.13.5
```
So if you don't make sure that you also include these packages as well then you'll eventually run into problems. Fortunately there's an easy solution: let the package manager sort it all out for you. We do that by "installing" the package (which would also pull in its dependencies) but without actually installing.

To avoid problems we're also going to download those packages into another, separate, directory. We can learn about these options by studying /usr/local/etc/pkg.conf:

```
root@psi:/usr/local/etc # grep -i cache pkg.conf
#PKG_CACHEDIR = "/var/cache/pkg";
```
That option specifies where the downloaded packages get stored. And if you take a look at pkg-install(8) you'll notice a few interesting options: -F ('fetch only') and the fact that we can use environment variables to override some options in pkg.conf, including the cache directory.

_*SO...*_


```
root@psi:~ # mkdir pkg
root@psi:~ # set PKG_CACHEDIR=/root/pkg
root@psi:~ # echo $PKG_CACHEDIR
/root/pkg
root@psi:~ # pkg install -qyF xf86-video-ati
```
Note that I used set because I'm using the default csh shell, on Bourne based shells (sh or bash) you'd probably want to use export. I also used -qy for demonstration purposes only, you can easily stick with -F if you're using this interactively.

Problem: I seem to be experiencing a bug or I'm overlooking something obvious because even though pkg.conf(5) tells me that the environment variable should override any (default) settings in pkg.conf my experiences are different. In the above situation everything got downloaded to the default directory of /var/cache/pkg and I have no idea why that is so right now.

So worst case scenario: edit /usr/local/etc/pkg.conf, set the variable PKG_CACHEDIR to point at your directory and use the command above.

Now, the install command doesn't only pull in dependencies from xf86-video-ati, it recurses this operation; so it also pulls in dependencies from the packages that the 'ATI package' depends on. This could be a good thing of course, but if you only want to concentrate on the direct dependencies of these packages then use this:

```
root@psi:/var/cache/pkg # ls xf86*
xf86-video-ati-18.1.0,1-9deda9fb07.txz  xf86-video-ati-18.1.0,1.txz@
root@psi:/var/cache/pkg # pkg info -dF ./xf86-video-ati-*txz
xf86-video-ati-18.1.0,1:
        libXi-1.7.9_2,1
        libdrm-2.4.96,1
        libpciaccess-0.13.5
        mesa-libs-18.1.9_4
        xorg-server-1.18.4_10,1
root@psi:/var/cache/pkg # mv xf86-video-ati*txz libXi-1* libdrm* libpciacc* mesa* xorg-serv* /root/pkg
root@psi:/var/cache/pkg # ls /root/pkg
libXi-1.7.9_2,1-2d0ca2f640.txz          mesa-dri-18.1.9_3.txz@
libXi-1.7.9_2,1.txz@                    mesa-libs-18.1.9_4-629a58ec07.txz
libdrm-2.4.96,1-9af5283799.txz          mesa-libs-18.1.9_4.txz@
libdrm-2.4.96,1.txz@                    xf86-video-ati-18.1.0,1-9deda9fb07.txz
libpciaccess-0.13.5-ed1d77b50e.txz      xf86-video-ati-18.1.0,1.txz@
libpciaccess-0.13.5.txz@                xorg-server-1.18.4_10,1-ac7f448db9.txz
mesa-dri-18.1.9_3-47dab7e4fd.txz        xorg-server-1.18.4_10,1.txz@
```
Ok, so this also copied the symlinks but you can easily get rid of those: `find /root/pkg -type l -delete`.

And now you only have the 'ATI package' plus its direct dependencies. On the new system you can use `# pkg add /root/pkg/*` to actually install all those packages. Of course you don't have to include the dependencies if you don't want to, but I suggest that you do because otherwise you'll run into problems.

Hope this can help.


----------



## Sevendogsbsd (Dec 24, 2018)

ShelLuser said:


> I know many people already answered but I'm sort of ignoring all that because I cannot help but think that programs such as Synth are serious overhead for what the OP is asking.



Agree - I misunderstood the OPs request and kind of went off the path...


----------



## Leveret (Dec 25, 2018)

I found an old post from 2013 in which Beastie gave this link: [URL]https://wiki.freebsd.org/PkgPrimer[/URL]
The code is below:

`tar xf ./pkg-1.2.1.txz -s ",/.*/,,g" "*/pkg-static"`

`./pkg-static add ./pkg-1.2.1.txz`

I switched to the usb containing my repository and executed the above as root. Then, remembering SirDice's advice that extensions were not necessary, I typed `pkg add *`. So far everything seems to work fine. Thought I'd put this out there again in case no one saw Beastie's post but has this same problem.


----------

