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 192.168.1.0 netmask 255.255.255.0 { option routers 192.168.1.1; option ntp-servers 192.168.1.1; option domain-name-servers 192.168.1.2, 192.168.1.3; option subnet-mask 255.255.255.0; pool { range 192.168.1.100 192.168.1.200; } filename "/pxelinux.0"; default-lease-time 21600; max-lease-time 43200; next-server 192.168.1.5; }
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
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=255.255.255.0 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
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.
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.
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.
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.