Home > FreeBSD > PXE Booting Into A FreeBSD Installation

PXE Booting Into A FreeBSD Installation

NOTE: This post is old. For our new installation method, see the article on Installing FreeBSD via Cobbler.

In the modern day, technologies for provisioning OS installations has progressed to a point where network installs are the standard thus eliminating the need for physical media and even physical access to the asset (apart from it’s physical installation in a cabinet). Networked consoles enable system builds in place.

Installing via PXE requires three services…DHCP, TFTP, and FTP or HTTP.  For the purposes of this post, we use ISC DHCP and the system TFTP daemon.  It is assumed that your FTP and/or HTTP servers are already configured appropriately.

The environment I installed in included Cobbler, a linux build system that has been modified by some of my colleagues to support FreeBSD.  Cobbler utilizes pxelinux as the PXE loader, therefore, my scenario included chaining Grub2pxe to pxelinux.  I have not tested without pxelinux, but I assume that Grub2pxe will work find without pxelinux.  Since we do employ Cobbler, my post will include the pxelinux configuration, but I will keep the information generic.

DHCP Configuration

An example of the dhcpd.conf file:

subnet netmask {
   option routers   ;
   option ntp-servers;
   option domain-name-servers,;
   option subnet-mask;
   pool {
   filename                   "/pxelinux.0";
   default-lease-time         21600;
   max-lease-time             43200;
   next-server      ;

TFTP Configuration

An example of /tftpboot/pxelinux.cfg/default file:

LABEL bsdpxegrub
   kernel /tftpboot/pxegrub.0
   MENU LABEL bsdpxegrub
   append initrd=/tftpboot/pxegrub.0  locale=  text
   ipappend 2

Most of the above configuration is superfluous, but does not cause any issues with the FreeBSD install.

Grub2pxe Configuration

Grub2 is necessary because it includes support for the BSD UFS Filesystem of which the mfsroot.gz is. Therefore, download and install Grub2 as per the instructions in the Grub2 manual.

The files and directories of interest here are:

  • /tftpboot/pxegrub.0  (The PXE executable)
  • /tftpboot/boot/grub/   (The default Grub directory)
  • /tftpboot/boot/grub/grub.cfg   (The default Grub config file)
  • /tftpboot/boot/grub/i386-pc/*   (All of Grub’s modules)

Once Grub is installed, grub-mknetdir will put everything into place including running grub-mkimage which generates the pxegrub.0 file.  An example of the command is as follows:

grub-mknetdir –net-directory=/tftpboot –grub-mkimage=pxegrub.0

What you see below for the /tftpboot/boot/grub/grub.cfg, is a complete config for our environment. Other implementations may not need the config that we have generated. Many of the kernel environment variables below are used in our mfsroot.gz file. For a minimal working environment, all the lines up to and including the vfs.root.mountfrom kernel variable are necessary.

menuentry $arbitrary_profile_name {
   echo -e "Fetching the kernel and UFS root...\c"
   kfreebsd $kernel_path
   kfreebsd_loadenv /boot/device.hints
   kfreebsd_module $initrd_path type=mfs_root

   set kFreeBSD.vfs.root.mountfrom=ufs:/dev/md0c
   set kFreeBSD.boot.nfsroot.server=$pxe_default_server
   set kFreeBSD.boot.netif.hwaddr=$net_pxe_mac
   set kFreeBSD.boot.netif.ip=$net_pxe_ip
   set kFreeBSD.boot.netif.netmask=
   set kFreeBSD.boot.netif.gateway=$system_gateway
   set kFreeBSD.dhcp.host-name=$net_pxe_hostname
   set kFreeBSD.dhcp.routers=$system_gateway
   set kFreeBSD.boot.kspath=$ks_path
   echo "Done!"
   sleep 2

HTTP/FTP Configuration

The HTTP/FTP configuration is beyond the scope of this post.  The assumption is made that FreeBSD is either mirrored locally or being accessed at freebsd.org remotely and that the install.cfg inside the mfsroot.gz is properly set to account for the media type and location.  An example of the variables would be mediaSetFTP accompanied by _ftpPath being set to something like ftp://ftp.freebsd.org/pub/FreeBSD/.  Note that using mediaSetFTP has several non-optional variables that must also be set.  Check the sysinstall manpage for more information.

Pure HTTP installs are not supported by sysinstall.  A former colleague wrote an HTTP module for sysinstall that we compiled into the binary that is placed inside the mfsroot.gz.  This patch was contributed back to the community, but was not committed to the FreeBSD sources due to the migration away from sysinstall in FreeBSD 9.0.

FreeBSD mfsroot Configuration

The actual contents and configurations of the mfsroot.gz are beyond the scope of this post, but are covered in this post.  The most important file, however, is the install.cfg that sysinstall consults upon boot of the environment.  Check the sysinstall manpage for complete information on generating an install.cfg for your environment.
Categories: FreeBSD
  1. May 25, 2012 at 12:16 AM

    I would like to add that I recently discovered that the host will not know what it’s netmask is unless the host declaration exists within the subnet declaration. This caused us considerable pain, but we wrote code to get the netmask without having the host declaration inside the subnet declaration.

    Unfortunately, for our environments, it was easier to customize the code in such a manner that would allow us to pass this through GRUB vs. applying the code to the Cobbler application to generate the dhpcd.conf correctly.

  2. Richard Sitze
    April 10, 2013 at 4:18 PM

    In the command “grub-mknetdir –net-directory=/tftpboot –grub-mkimage=pxegrub.0”, the –grub-mkimage takes a command name, not the output file name. Not clear what you’re doing here.

    • April 10, 2013 at 6:34 PM

      We no longer use Grub for PXE booting/installation, but the end result was having a PXE boot program that allowed us to boot an installation image over the network. We have since replaced PXE Grub with iPXE and memdisk to boot an ISO. I’m working on a new post that describes the new process.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: