# What's the best way to install a lot of ports on a new system?



## ericr (Apr 23, 2009)

I've got to build some new servers, and some of them require about 150 ports/dependencies to be compiled and installed.  I've got all the port names and such, I'm just wondering if there's a better way of installing all these.  Right now, I've just got a shell script that loops through the list and installs each port.  

Is there some port that I haven't found yet that would run through the list of ports to be installed, order them in the right way for doing common dependencies first, and then build them?

I looked at portmaster, but it doesn't seem to handle a big list of ports for initial install.

Thanks!

- ericr


----------



## ale (Apr 24, 2009)

You should just care about the ports you want to install.
The ports infrastructure will take care about dependencies for you.
So a script that cd to the ports dir and build them should be enough to start.
Two suggestions could be:

Run make _config-recursive_ on the ports you want to install before start building
If the servers uses the same make and ports options, consider using _make package_ on just one box after creating /usr/ports/packages. The ports will be build and installed and a packages will be created. So you can install the other servers using the packages you built skipping the build part.

EDIT:
configure->config


----------



## fronclynne (Apr 24, 2009)

Iff the other machines in question are running exactly the same version & arch of FreeBSD, you can use the pkg-recursive target to make and then use pkg_add(1) on all the other machines.


----------



## keramida@ (Apr 24, 2009)

*Use a ports builder machine/chroot*



			
				ericr said:
			
		

> I've got to build some new servers, and some of them require about 150 ports/dependencies to be compiled and installed.  I've got all the port names and such, I'm just wondering if there's a better way of installing all these.  Right now, I've just got a shell script that loops through the list and installs each port.



If you are using the same FreeBSD release/version on all systems, it should be possible to build the ports *once* and then install them from prebuilt packages.

You can build the ports in a clean chroot, and then use the port list that you already have and the pkg_create(1) utility to save the pre-built packages, i.e.:


```
chroot# mkdir /usr/ports/packages/All
chroot# cd /usr/ports/packages/All
chroot# pkg_info | awk '{print $1}' | xargs -n1 pkg_create -Rvnb
```

This will save all the packages *and* their dependencies in _*.tbz_ files.  You can then transfer the _/usr/ports/packages/All_ tree to the other hosts and just install everything with pkg_add(1):


```
otherhost# cd /usr/ports/packages/All
otherhost# pkg_add *
```

This will probably save a lot of compile-time


----------



## phoenix (Apr 24, 2009)

If the servers are all identical (same ports installed, same hardware, same OS options, same initial config), then doing an rsync backup of one system, and using rsync to "image" the other servers may be easier.  Do a minimal install off the CD, then boot off a Frenzy LiveCD, configure the network, mount the filesystems under /mnt, and rsync back from the image server.

We do this, and can image firewalls in <20 mins, diskless servers in ~1 hour.

Otherwise, using a central repository of packages is the next logical choice.  Use *pkg_create -b* to create packages from already installed ports, or *make package-recursive* when installing ports.


----------



## rbelk (Apr 24, 2009)

keramida, pkg_create -Rvnb gives an error on 7.1-RELEASE-p4. After looking at the source of pkg_create, I found that the option 'n' is not coded as an option in the source. The noclobber mode '-n' is mentioned in the manual page source and it is also displayed as an option in the pkg_create usage help. I guess I should file a bug report for this error, but it's past midnight here and I'll try to it at work today. 

Also, it would be easier to NFS export /usr/ports/packages/All and NFS mount it on other servers. That is how I am doing it. I do have a dedicated Ports building machine for my servers.


----------



## SirDice (Apr 24, 2009)

rbelk said:
			
		

> Also, it would be easier to NFS export /usr/ports/packages/All and NFS mount it on other servers. That is how I am doing it. I do have a dedicated Ports building machine for my servers.


Yep, same here. I build all my packages myself then export them. Same goes for /usr/src and /usr/obj, both can be exported read-only.


----------



## rbelk (Apr 25, 2009)

keramida, I did enter a PR for the pkg_create no-clobber bug on 7.1-RELEASE-p4. The PR is bin/133979. FYI, pkg-create's no-clobber option works correctly on 7.2-RC2 and 8.0-current though.


----------

