Installing FreeBSD 6.2 using PXEBoot/TFTP/NFS
Introduction
So what do you do when you do not have an optical drive for a computer or server and you would like to install FreeBSD? You have two options, use a USB device (CD-ROM, Hard Drive, or Thumbdrive) or PXE booting and doing a full network install. This article will discuss the latter. Doing a PXE boot install is a bit convoluded with FreeBSD, so I will go through all the steps involved from setting up the TFTP, NFS, and DHCP to the three times you need to run sysinstall.
Requirements
- A network adapter that supports PXE booting.
- A spare computer or server to install a TFTP, NFS, and DHCP server on.
- CD1 of the latest version of FreeBSD for your system's architechture.
Note: The following setup for the DHCP, NFS, and TFTP server is done on FreeBSD. Using a different OS may have a slightly different configuration, but generally should be similar.
PXEBoot Setup
Mount the FreeBSD install CD.
mount /cdromCopy all the contents of the FreeBSD install CD to /usr/tftpboot
cp -R /cdrom /usr/tftpboot
Setup TFTP Server
Add or edit a line in /etc/inetd.conf to the following
tftp dgram udp wait root /usr/libexec/tftpd tftpd -s /usr/tftpboot
Install DHCP server
Install the isc-dhcp3-server port.
cd /usr/ports/net/isc-dhcp3-server/ make && make install
Create a dhcpd.conf in /usr/local/etc, adjust the following example to fit your network
ddns-update-style none;
option broadcast-address 192.168.10.255;
option domain-name-servers 192.168.10.254;
option domain-name "simerson.net";
option routers 192.168.10.254;
option subnet-mask 255.255.255.0;
server-name "pxe-gw";
server-identifier 192.168.10.105;
next-server 192.168.10.105;
default-lease-time -1;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.32 192.168.10.99;
option root-path "192.168.10.105:/usr/tftpboot";
filename "/boot/pxeboot";
}
The most important lines in the above example are
This line identifies the TFTP server to the client.
next-server 192.168.10.105;This line identifies the NFS server, and the NFS export the FreeBSD kernel should mount as "/". You typically do not need to specifiy the server's IP address if it is the same server listed as next-server.
option root-path "192.168.10.105:/usr/tftpboot";This is the pxeboot kernel location relative to the TFTP server root (in this case /usr/tftpboot)
filename "/boot/pxeboot";
Create a NFS Share
Edit /etc/exports
/usr/tftpboot -alldirs -network 192.168.10.0 -mask 255.255.255.0
Restart the NFS daemons
/etc/rc.d/nfs restart
Start inetd
/etc/rc.d/inetd start
Start dhcpd
/usr/local/etc/rc.d/isc-dhcpd start
Your system should now be able to PXE boot from this server. Ensure that your system's BIOS is set to boot from its network card.
Once Booted
Login using the username root with no password.
Sysinstall Part 1
Run
sysinstall- Select Custom
- Select partition
- Use the D key to delete all existing partitions.
- Use the A key to create one partition that uses the entire disk.
- Use the S key to set the partition bootable.
- Use the W key to write changes. Acknowledge the message.
- Use the Q key to quit the FDISK Editor.
- On the next screen select BootMgr.
- Select OK to continue.
- Select Cancel
- Select partition
- Select Exit Install
- Select Custom
Warning: Do not use sysinstall's BSDLabel editor, it will attempt to mount the labels to the root of the install enviroment, effectively unmounting the NFS root and freezing the system.
BSDLabel
Run
bsdlabel -w /dev/ad4s1This writes a standard label to the partition.
Next run
bsdlabel -e /dev/ad4s1Note: If you need to use a different editor set the EDITOR enviroment variable to whatever editor you like.
When you start you will only see an "a" and "c" label created. Here you are creating labels. "a:" typically is the root label of your system, and "b:" is the swap label. Do not edit "c:". For the size of a label you can use G for gigabytes, M for megabytes, and K for kilobytes after the number. You can just enter a number for size in which case it will be interperted as number of blocks. On the last label you can specifiy "*" for size and it will occupy the rest of the availale space. For offset keep whatever the standard label created for "a:". For the rest of the labels you can use a "*" to have bsdlabel calculate the value. For fstype enter 4.2BSD for all the data labels, and swap for the swap label. Use the standard labels setting for fsize, bsize, and bps/cpg for the "a:" label. For the rest of the labels you can just enter a "*" for these three settings and BSDLabel again will calculate the values for you.
# size offset fstype [fsize bsize bps/cpg]
a: 4G 16 4.2BSD 2048 16384 28528
b: 512M * swap * * *
c: 72292437 0 unused 0 0 # "raw" part, don't edit
d: 1G * 4.2BSD * * *
e: 2G * 4.2BSD * * *
f: * * 4.2BSD * * *
Newfs
Format the new labels, use the -o flag to optimize the format for space instead of time ( change the device name to what your system is uses for its hard drive )
newfs -o space /dev/ad4s1a
Add the -U flag for soft updates for the rest of the labels
newfs -o space -U /dev/ad4s1d
newfs -o space -U /dev/ad4s1e
newfs -o space -U /dev/ad4s1f
Mount
Turn on swap on the swap label.
swapon /dev/ad4s1b
Label a is the root of the system so mount it first to /mnt
mount /dev/ad4s1a /mnt
Make the folders for the following mount points.
mkdir /mnt/tmp
mkdir /mnt/var
mkdir /mnt/usr
Mount the rest of the labels.
mount /dev/ad4s1d /mnt/tmp
mount /dev/ad4s1e /mnt/var
mount /dev/ad4s1f /mnt/usr
Sysinstall Part 2
Run
sysinstall
The following is very important, if you forget this step sysinstall will try to install to / and will unmount the NFS mount, and the install enviroment will freeze.
Select Options
- Edit Install Root. Set it to "/mnt" (where we mounted the root label)
- Exit the options menu
Next select Distributions. You can select any distributions you wish. I reccommend doing a minimal install, then going into custom and adding man pages and catman pages. As well if you want to recompile your kernel later on go to src and select base and sys.
Select Media
- Select Filesystem and enter "/" when asked. This works because we have the installation CD mounted as the root partition of the install environment over NFS.
- Select Commit, sysinstall will then start installing FreeBSD to /mnt
- Once completed select Exit. Sysinstall cannot do any of the post install configuration quite yet.
Once back to the command line run
chroot /mnt
This brings you into your installed environment, so sysinstall can do its normal post-install configuration.
Sysinstall Part 3
Run
sysinstall
- Goto configure
- Select root password, set your system's root password here.
- Select user management to add one or more users.
- Select Time Zone to set your system's timezone.
- Select Mouse, if you want to enable the mouse daemon.
- Select Networking
- Select Interfaces to configure your network interfaces.
Warning: When asked if you want to bring the interface up, say no. If you do and this is the interface that is currently communicating to the NFS server your install enviroment will freeze. - Select Gateway to set your network gateway
- Select Ntpdate if you want to enable the use of ntpdate at boot.
- Select sshd to enable the ssh daemon.
- Select Exit to continue
- Select Interfaces to configure your network interfaces.
- Select Exit
- Select Exit Install
Edit fstab.
ee /etc/fstab
Creating something similar to the following. Specifiy the device and its corrisponding mount point.
#Device Mountpoint FSType Options Dump Pass
/dev/ad4s1a / ufs rw 1 1
/dev/ad4s1b none swap sw 0 0
/dev/ad4s1d /tmp ufs rw 2 2
/dev/ad4s1e /var ufs rw 2 2
/dev/ad4s1f /usr ufs rw 2 2
Even though the kernel was copied to /mnt/boot it wasn't installed into the default location /boot/kernel. Run:
rm -rf /boot/kernel
Depending on if you have SMP system or not sysinstall will have install the SMP kernel or the GENERIC kernel. Move the corrisponding kernel folder to /boot/kernel.
mv /boot/SMP /boot/kernel
or
mv /boot/GENERIC /boot/kernel
Reboot
That should be everything. Run the reboot command, and ensure you do not PXEBoot again otherwise you will boot back into the install enviroment. Boot off the correct hard drive.