Using nfsroot to boot diskless clients on RHEL

Here is a brief outline on the steps needed to set up a Red Hat Enterprise Linux 6 server to boot diskless clients using nfs.

To do this, you need to set up dhcp, tftp (to pxe boot) and a nfs server to serve the rootfs.

To keep it simple, I did everything on the same server, but you can easily have multiple servers for each service. The same steps should also work on Fedora (14+) with minor changes.

Requirements :

Server : Fresh RHEL 6 installation (registered to RHN)

IP = 192.168.50.254/24 (static) on eth0

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=52:54:00:73:1C:CB
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.50.254
NETMASK=255.255.255.0

Client : A box on the same network (with support for PXE)

MAC = 52:54:00:ca:c6:71

On the Server :

Step 1 – Create the nfs rootfs first :

# mkdir /netboot/
# rsync -av --progress --exclude=/proc --exclude=/sys --exclude=/netboot / /netboot/

(i.e. copy everything from root to the /netboot folder)

# mkdir /netboot/{proc,sys}
# vi /netboot/etc/fstab

192.168.50.254:/netboot/  /                      nfs     defaults       1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

# vi /netboot/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
HWADDR="52:54:00:ca:c6:71"
ONBOOT="no"
BOOTPROTO="dhcp"

Step 2 – Install and enable services :

# yum install dhcp syslinux tftp-server -y
# yum groupinstall "NFS file server" -y

# chkconfig dhcpd on
# chkconfig tftp on
# chkconfig nfs on
# service xinetd start

For simplicity, disable the firewall :

# iptables -F
# service iptables save

Step 3 – configure dhcp server :

# vi /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.50.0 netmask 255.255.255.0 {
option routers      192.168.50.254;
option subnet-mask   255.255.255.0;
option nis-domain   "domain.org";
option domain-name  "domain.org";
option domain-name-servers  192.168.50.254;
option time-offset    -18000; # Eastern Standard Time
default-lease-time 21600;
max-lease-time 43200;

host netboot6 {
next-server 192.168.50.254;
hardware ethernet 52:54:00:ca:c6:71;
fixed-address 192.168.50.100;
filename "pxelinux.0";
}
}

# service dhcpd start

Tip : To restrict dhcpd to a particular interface edit the following file :

# cat /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS="eth1"

Step 4 – enable nfs and export the rootfs :

# vi /etc/exports
 /netboot/            *(rw,async,no_root_squash)

# service rpcbind start
# service nfs start

Step 5 – generate the initramfs file (here is where the magic happens):

# yum install dracut-network -y
# dracut -f /boot/netboot6.img `uname -r` root=dhcp root-path=nfs:192.168.50.254:/netboot/

Step 6 – configure pxe :

# mkdir /var/lib/tftpboot/pxelinux.cfg/
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
# cp /boot/netboot6.img /var/lib/tftpboot/
# cp /boot/vmlinuz-2.6.32-71.el6.x86_64 /var/lib/tftpboot

# vi /var/lib/tftpboot/pxelinux.cfg/default

 default netboot6
 timeout 30
 prompt 1

 label netboot6
 kernel /vmlinuz-2.6.32-71.el6.x86_64
 append initrd=/netboot6.img rw root=nfs:192.168.50.254:/netboot/ selinux=0 enforcing=0

On the Client :

Configure the client to boot over the network (i.e. enable pxe boot) and start the system.

The following screen shots show a successful boot :

Advertisements