Many years ago for the first time, I did a ftp install of FreeBSD 4.x. using the two floppies. I instructed 'sysinstall' to retrieve the installation files from a FreeBSD ftp mirror on the internet. Previously I had installed FreeBSD a few times from CD. At that time I was using a new ISDN modem, which was fast with 64Kb, at least compared with the 14k4 old modem.

Because the system did not boot, I must have made a mistake somewhere. Not looking forward to a couple of repeated ftp downloads with the ISDN modem, I decided to download the release files once and for all on a FreeBSD Pentium-Pro box. Some simple configuration steps turned the Pentium-Pro into a local ftp server.

This method has become my favorite way to install FreeBSD as well as OpenBSD. First download the files making up the FreeBSD release to a ftp server in my local network. Boot 'sysinstall' with the install floppies, and install FreeBSD by fetching the installation files from the local ftp server.

A nice side effect is speed. Transfer over the network turned out to be much faster than reading from a 10x speed CD on a Pentium I box.

1.2 File hierarchy of a FreeBSD release

In the standardized ftp structure, we find the release files in '/pub/FreeBSD/releases/<arch>/<release>/', where <arch> stands for the hardware architecture like 'i386' or 'amd64', and <release> is a release tag, e.g. '7.2-RELEASE' or '8.0-RELEASE'.

MD5 and SHA256 checksum files for each individual 'base.??'. All 'base.??' files, from 'base.aa' to 'base.bi' are chunks of a 'tar' archive. A peek into 'install.sh', reveals how these pieces are glued together to a single tar file. and how subsequently this tar archive is unpacked:

Code:

cat base.?? | tar --unlink -xpzf - -C ${DESTDIR:-/}

Downloading all these files with the command line 'ftp' would be rather tedious. For a long time I used 'wget' to fetch the files. A couple of years later I discovered how to use a '.netrc' file to script ftp commands.

1.3 A '.netrc' file to download a FreeBSD release

A full explanation of the '.netrc' tokens can be found in the ftp(1) man page.

Note that the parameters for the mget and $ getdir commands have been wrapped for display purposes. In reality both commands expect these on a single line.

In the following invocation of the ftp command, the '-4' instructs the ftp client to only use IPv4 and not try IPv6, the 'a' option prescribes an 'anonymous' login.

Code:

$ ftp -4a ftp://ftp2.dk.FreeBSD.org

The ftp(1) program will perform the following procedure:

A check whether the directory specified by the 'HOME' environment variable, contains a '.netrc' file.

Scan the found '.netrc' for a line starting with 'machine ftp2.dk.FreeBSD.org'. All information up to end of file or till another line starting with either the 'machine' or 'default' token will be processed.

The first encounter is a macro definition called "init", which is executed automatically after the ftp server has authorized us to use its services.

prompt off prevents ftp from asking us for confirmations. From the ftp man page

Code:

prompt
Toggle interactive prompting. Interactive prompting occurs
during multiple file transfers to allow the user to selec-
tively retrieve or store files. If prompting is turned off
(default is on), any mget or mput will transfer all files,
and any mdelete will delete all files.

cd /pub/FreeBSD/releases/amd64/8.0-RELEASE changes the directory on the server to the standard location for the 8.0 files for the amd64 processor.

mget ERRATA.HTM ERRATA.TXT HARDWARE.HTM HARDWARE.TXT .. docbook.css gets or retrieves the files into the current working directory of the ftp client.

! mkdir $i executes the shell command mkdir $ion the ftp client. The $i parameter will be expanded to the first parameter 'base', resulting in 'mkdir base" on the ftp client. mget $1 will be expanded to mget base/*.

Now getdir will move on to the next parameter 'catpages', creating a 'catpages' directory on the client and mgeting the 'catpages/*' directory.

This implicit loop will continue until getdirs runs out of parameters.

With ! mkdir iso a local shell command creates a 'iso' directory. The lcd iso, a local cd, changes the default directory on the ftp client. The ftp(1) man page explains the reason:

Code:

mget remote-files
Expand the remote-files on the remote machine and do a get
for each file name thus produced.
......
Files are transferred into the local working directory, which
can be changed with `lcd directory'; new local directories
can be created with `! mkdir directory'

The default directory on the server is switched to the iso images with cd /pub/FreeBSD/ISO-IMAGES-amd64/8.0.

After having set the correct directory for both local and remote, the mget downloads the iso, as well as the two checksum files.

Note that the amd64 release has a 'lib32' file set, while the i386 release does not. Distilling the directories from a listing is a simple method to automatically include all release file sets for a certain architecture.

Finally after having gathered all necessary information, the script can generate the '.netrc' file.

The variables used in the 'here' document will be expanded. By prefixing the macro parameter '$i' with a "\", the shell is prevented from interpreting this macro parameter as an non-existing shell variable $i.