Diskless FreeBSD (PXE/NFS)

Build the system to boot from

by ross at 04:12:11 on October 31, 2012

Directory structure

I use /share/lanboot directory as root. There I have subdirectories for the particular system, like “FreeBSD-9.0”.

This way, for instance, when 9.1 is out I can create “FreeBSD-9.1” dir, boot and test it with one client (the rest of the clients will still use “FreeBSD-9.0”).

And only after that I will switch all the clients to 9.1 and delete the 9.0 dir.

Build and install the base system

Fetch sources and build the system without using /etc/make.conf and /etc/src.conf:

If your shell is sh-compatible (bash):
# export __MAKE_CONF=/dev/null
# export SRCCONF=/dev/null

If your shell is csh-compatible (tcsh):
# setenv __MAKE_CONF /dev/null
# setenv SRCCONF /dev/null

# cd /usr/src
# make buildworld
# make buildkernel

# mkdir /share/lanboot/FreeBSD-9.0
# make installworld DESTDIR=/share/lanboot/FreeBSD-9.0
# make installkernel DESTDIR=/share/lanboot/FreeBSD-9.0
# make distribution DESTDIR=/share/lanboot/FreeBSD-9.0

Not setting the KERNCONF variable of buildkernel/installkernel targets means using the GENERIC kernel. But you can add KERNCONF of course, when you need Kerberized NFS support, for instance.

This will build and install FreeBSD of the same architecture as host. You better use amd64 on the host if you want to see all the memory installed.

Anyway amd64 is very stable nowdays, all the ports work without a problem, so there is no need for 32bit i386 arch.

When you decide to update the client's base system later use the same environment variables as listed above and pass -D /share/lanboot/FreeBSD-9.0 parameter to mergemaster.

Mount important directories

In order to save disk space you could mount /usr/src and /usr/ports under the root dir you used.

Add to /etc/fstab:

/usr/src      /share/lanboot/FreeBSD-9.0/usr/src nullfs rw,late 0 0
/usr/ports    /share/lanboot/FreeBSD-9.0/usr/ports nullfs rw,late 0 0
dev           /share/lanboot/FreeBSD-9.0/dev devfs rw,late 0 0

Run:

# mount /share/lanboot/FreeBSD-9.0/usr/src
# mkdir /share/lanboot/FreeBSD-9.0/usr/ports
# mount /share/lanboot/FreeBSD-9.0/usr/ports
# mount /share/lanboot/FreeBSD-9.0/dev

Now when you update the base system sources or the ports tree on the host system it will instantly become available to LAN clients.

Install ports

To install a port in the client's system you need to chroot to the new system directory. Some ports require full /dev directory so you must mount it first:

# chroot /share/lanboot/FreeBSD-9.0
# cd /usr/ports/sysutils/dvd+rw-tools
# make install clean

Do not install ports in the client system at the same time when installing ports in host system — they use the same ports tree!

 

Comments