Compile FreeBSD on one computer.
Install on another computer

Neil Short

 

Summary/Disclaimer: This tutorial explains how to keep your source and compiled source on one computer and install it on another computer. The "other" computer must access this compiled code via Network File System (NFS).

This tutorial is open-source. No warranty, etc. Don't blame me if it doesn't work, breaks your system, etc.

I kind of took my own road from a couple tutorials already published at The FreeBSD Diary. In particular, the tutorials "Build world on your fast box, install on your slow box" and "compiling a kernel on another machine." Those tutorials are very useful but a bit complicated for the average user - and I think incorrect in a few areas. Plus, the writer uses some extra tools that make the tutorials somewhat confusing if you don't break down and use the same exact tools. On the other hand, I would have never succeeded myself if not for these tutorials. I will make a few assumptions in the interest of keeping the length of this tutorial under control. I assume you have two networked FreeBSD machines; and I won't go into a lot of detail about how to customize a kernel.

This technique can be real useful if one of your computers in fairly fast and can compile a load of coad in a reasonable amount of time... while the other computer is really slow. In my situation, the "other" computer is reasonably fast but it has a teeny hard drive and I have to scrimp on what is on it. That means I have to cut the entire /usr/src directory.

The way we will handle compiling (buildworld) FreeBSD on one computer is by having one computer in charge of updating its sources and compiling them. That computer's compiled code will be available to the other computer(s) in the network.

Sharing the necessary resources

In order to share resources, you need to set up NFS (network file system.) On FreeBSD, this is done (the easy way) by adding a couple lines to /etc/rc.conf. On the computer that is going to have all the source and do all the compiling, add these lines to /etc/rc.conf:

# NFS
portmap_enable="YES"
nfs_server_enable="YES"
mountd_flags="-r"
nfs_reserved_port_only="YES"
On the computer that will be installing the already compiled code, add these lines to rc.conf:
nfs_client_enable="YES"
nfs_reserved_port_only="YES"
On the computer with all the source, create an /etc/exports file with this line:
/usr/src /usr/obj /usr/ports -maproot=root mom church
"mom" and "church" are other computers (hosts) in the network. Instead of their respective host names, it is also correct to specify their IP addresses instead, for example:
/usr/src /usr/%bj /usr/ports -maproot=root 192.168.0.3 192.168.0.4
I added "/usr/ports" for a completely different reason than this tutorial. It makes it easy to install ports off the main machine. See, in my case, I'm trying to save space on the teeny hard drive that is on the "church" computer.

On the beneficiary computer ("church" in this case) add these directories if they don't already exist:

mkdir /usr/src
mkdir /usr/obj
mkdir /usr/ports
and add theses lines to /etc/fstab:
# Device
.....
daddy:/usr/src
daddy:/usr/obj
daddy:/usr/ports
....
Mountpoint
 
/usr/src
/usr/obj
/usr/ports
 
FStype
 
nfs
nfs
nfs
 
Options
 
rw
rw
rw
 
Dump
 
0
0
0
 
Pass#
 
0
0
0
 
Again, instead of the hostname of the computer that has these resources (daddy), you can correctly supply the IP instead:
....
192.168.0.1:/usr/src     /usr/src     nfs     rw     0     0
....
After rebooting everybody (all the affected hosts, or "computers"), you will be ready to get to work.

Compile and install

Okay. I'm going to assume you know how to update your source, how to compile a kernel and how to build world on one computer. If not, there are just too many other tutorials and "how-tos" on the 'Net to warrant me going through it here.

On the main computer that got the source, go ahead and buildworld, buildkernel, installkernel, installworld and mergemaster. Optionally, you may want to compile a tailor-made kernel for the other computer.

Installing the same stuff on the other computer

If the NFS mounts are properly set up and mounted, all you need to do on the other computer is:
cd /usr/src
make installkernel
reboot
shutdown now go to single user mode. Your NFS mounts should be ok cd /usr/src
make installworld
mergemaster
The line make installkernel can be more specific by specifying the tailor-made kernel if you precompiled one on the main machine.

make installkernel KERNCONF=CHURCH

Notice that the sequence of commands does no compiling. Believe me, that's a time (and space) saver.

Final thoughts

This little how-to is a no-frills explanation of compiling source on one computer for the purpose of installing it on another.