What is diskless booting?
Diskless booting is using a remote system or systems to store the kernel and the filesystem that will be used on other computer(s).
Why do it?
Imagine my case I admin about 25 public workstations for a local library, if they want something changed across the board I can either go sit at each PC and spend X minutes on it, adding up to who knows how many hours, or I can simply make the change at any one of the 25 systems and have it effect every system equally. The same goes for updates and many other operations. It really eases support issues.
Getting Started
• Install the required packages
apt-get install dhcp3-server tftpd-hpa syslinux nfs-kernel-server initramfs-tools
• Configure your DHCP server
allow booting;
allow bootp;
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.xxx 192.168.2.xxx;
option broadcast-address 192.168.2.255;
option routers 192.168.2.xxx;
option domain-name-servers 192.168.2.xxx;
filename "/pxelinux.0";
}
# force the client to this ip for pxe.
# This is only necessary assuming you want to send different images to different computers.
host pxe_client {
hardware ethernet xx:xx:xx:xx:xx:xx;
fixed-address 192.168.2.xxx;
}
• Configure the TFTP Server
#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /tftpboot"
• Configure your tftp root directory
mkdir -p /tftpboot/pxelinux.cfg
cp /usr/lib/syslinux/pxelinux.0 /tftpboot
LABEL linux
KERNEL vmlinuz-2.6.15-23-686
APPEND root=/dev/nfs initrd=initrd.img-2.6.15-23-686 nfsroot=192.168.2.2:/nfsroot ip=dhcp rw
chmod -R 777 /tftpboot
/etc/init.d/tftp-hpa start
• Configure OS root
mkdir /nfsroot
/nfsroot 192.168.2.xxx(rw,no_root_squash,async)
exportfs -rv
• Creating your NFS installation
ls -ltr /boot/vmlinuz-*
-rw-r--r-- 1 root root 1745100 2007-04-15 03:07 /boot/vmlinuz-2.6.20-15-generic
-rw-r--r-- 1 root root 1746636 2007-06-07 15:58 /boot/vmlinuz-2.6.20-16-generic
sudo cp /boot/vmlinuz-2.6.20-16-generic /home/<USERNAME>
• Create an initrd.img file
# BOOT: [ local | nfs ]
#
# local - Boot off of local media (harddrive, USB stick).
#
# nfs - Boot using an NFS drive as the root of the drive.
#
BOOT=nfs
mkinitramfs -o /home/<USERNAME>/initrd.img-2.6.20-16-generic
• Copy OS files to the server
mount -tnfs -onolock 192.168.1.2:/nfsroot /mnt
cp -ax /. /mnt/.
cp -ax /dev/. /mnt/dev/.
• Copy kernel and initrd to tftp root
cp /nfsroot/home/<USERNAME>/<vmlinuz-xxxx> /tftpboot/
cp /nfsroot/home/<USERNAME>/<initrd.img-xxxx> /tftpboot/
• Modify /nfsroot/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface, commented out for NFS root
#auto eth0
#iface eth0 inet dhcp
iface eth0 inet manual
• Configure fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
/dev/nfs / nfs defaults 1 1
none /tmp tmpfs defaults 0 0
none /var/run tmpfs defaults 0 0
none /var/lock tmpfs defaults 0 0
none /var/tmp tmpfs defaults 0 0
/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
* Setup your client Enter your BIOS settings and configure your system to boot from LAN
* If you have options for different LAN boot methods choose PXE
• Adding a swap file
apt-get install dphys-swapfile
losetup /dev/loop0 /var/swap
swapon /dev/loop0
• Static IP
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
<client-ip> IP address of the client. If empty, the address will
either be determined by RARP/BOOTP/DHCP. What protocol
is used de- pends on the <autoconf> parameter. If this parameter is not empty, autoconf will be used.
<server-ip> IP address of the NFS server. If RARP is used to
determine the client address and this parameter is NOT empty only replies from the specified server are accepted. To use different RARP and NFS server, specify your RARP server here (or leave it blank), and specify your NFS server in the `nfsroot' parameter (see above). If this entry is blank the address of the server is used which answered the RARP/BOOTP/DHCP request.
<gw-ip> IP address of a gateway if the server is on a different
subnet. If this entry is empty no gateway is used and the server is assumed to be on the local network, unless a value has been received by BOOTP/DHCP.
<netmask> Netmask for local network interface. If this is empty,
the netmask is derived from the client IP address assuming classful addressing, unless overridden in BOOTP/DHCP reply.
<hostname> Name of the client. If empty, the client IP address is
used in ASCII notation, or the value received by BOOTP/DHCP.
<device> Name of network device to use. If this is empty, all
devices are used for RARP/BOOTP/DHCP requests, and the first one we receive a reply on is configured. If you have only one device, you can safely leave this blank.
<autoconf> Method to use for autoconfiguration. If this is either
'rarp', 'bootp', or 'dhcp' the specified protocol is used. If the value is 'both', 'all' or empty, all protocols are used. 'off', 'static' or 'none' means no autoconfiguration.