Linux NFS Root and PXE-Boot
November 6, 2006
Linux kernel hacking and test running on the same machine becomes a major pain. This tutorial explains how to separate the two easily for a quick code-and-test loop. This tutorial explains how to setup a Linux thin client that boots using PXE by pulling a remote Linux kernel image and mounting a remote root file system over NFS. This is only possible if your client machine has a network card that supports this (do you remember seeing some type of option like press N to boot from network just after posting?). I am using Fedora Core 5 as my server, so some of the details may be specific to FC.
Most of the details of setting up the PXE boot server were found at Setting up a PXE-Boot Server.
1) yum install tftp-server dhcp
Make sure you have an NFS server.
2) create /etc/dhcpd.conf
allow bootp; allow booting; ddns-update-style interim; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.10 192.168.0.254; default-lease-time 3600; max-lease-time 4800; option routers 192.168.0.1; option domain-name-servers 192.168.0.1; option subnet-mask 255.255.255.0; option domain-name "llama.net"; option time-offset -8; } host llama0 { hardware ethernet 04:4B:80:80:80:03; fixed-address 192.168.0.254; option host-name "llama0"; filename "pxelinux.0"; }
Change MAC address to match that of the client machine.
3) Create the directory and add the following line to /etc/exports for the nfs share.
/nfsroot *(rw,no_all_squash,no_root_squash)
4) cp -a /bin /dev /etc /home /lib /mnt /sbin /tmp /usr /var /nfsroot
from a good Fedora Core install. You'll have to cleanup and change some of these files for your client at some point.
5) Activate tftp within xinetd by changing disable=yes to disable=no in /etc/xinetd.d/tftp. Restart xinetd. The tftp root is at /tftpboot.
6) Compile your kernel with the following options and move bzImage to /tftpboot/:
- NFS filesystem support (CONFIG_NFS_FS).
- Root file system on NFS (CONFIG_ROOT_NFS).
- Ethernet (10 or 100Mbit) (CONFIG_NET_ETHERNET).
- The ethernet driver for the clent's network card.
- IP: kernel level autoconfiguration (CONFIG_IP_PNP)
- BOOTP support (CONFIG_IP_PNP_BOOTP)
7) Configure pxelinux. First create the directory /tftpboot/pxelinux.cfg (and make it world readable). Inside that directory you need to create a number of zero size files (use touch):
01-04-4B-80-80-80-03
C
C0
C0A
C0A8
C0A80
C0A800
C0A800F
C0A800FE
01-04-4B-80-80-80-03
The first 8 are the hex representation of the 192.168.0.254 IP address that your PXE boot client will be assigned. The permutations allow a broader IP subnet to be searched first for matches. The last entry is the MAC address of your PXE boot client's NIC (with dashes substituted for the colons), with '01' pre-pended. The "01" at the front represents a hardware type of Ethernet, so pxelinux.0 see's the configuration string as an IP address.
Copy /usr/lib/syslinux/pxelinux.0 from your Fedora install to /tftpboot/
8) Now create the default pxelinux configuration inside the new file
/tftpboot/pxelinux.cfg/default:
prompt 1 default linux timeout 100 label linux kernel bzImage append init=/sbin/init root=/dev/nfs rw nfsroot=192.168.0.1:/nfsroot ip=192.168.0.254:192.168.0.1:192.168.0.1:255.255.255.0:llama0::off noapic acpi=off
The last line is where you can stick any kernel parameters needed. You'll notice this menu is somewhat similar to a grub config file.
Check out the following articles for more information:
PXELINUX - SYSLINUX for network boot
NFS-Root-Client Mini-HOWTO
NFS-Root mini-HOWTO
NFS-Root
http://www.tldp.org/HOWTO/Diskless-root-NFS-other-HOWTO-4.html